| 23 | rewrite_actual_path = base_path + '.actual-rewrite' |
| 24 | |
| 25 | def valueTreeToString(fout, value, path = '.'): |
| 26 | ty = type(value) |
| 27 | if ty is types.DictType: |
| 28 | fout.write('%s={}\n' % path) |
| 29 | suffix = path[-1] != '.' and '.' or '' |
| 30 | names = value.keys() |
| 31 | names.sort() |
| 32 | for name in names: |
| 33 | valueTreeToString(fout, value[name], path + suffix + name) |
| 34 | elif ty is types.ListType: |
| 35 | fout.write('%s=[]\n' % path) |
| 36 | for index, childValue in zip(xrange(0,len(value)), value): |
| 37 | valueTreeToString(fout, childValue, path + '[%d]' % index) |
| 38 | elif ty is types.StringType: |
| 39 | fout.write('%s="%s"\n' % (path,value)) |
| 40 | elif ty is types.IntType: |
| 41 | fout.write('%s=%d\n' % (path,value)) |
| 42 | elif ty is types.FloatType: |
| 43 | fout.write('%s=%.16g\n' % (path,value)) |
| 44 | elif value is True: |
| 45 | fout.write('%s=true\n' % path) |
| 46 | elif value is False: |
| 47 | fout.write('%s=false\n' % path) |
| 48 | elif value is None: |
| 49 | fout.write('%s=null\n' % path) |
| 50 | else: |
| 51 | assert False and "Unexpected value type" |
| 52 | |
| 53 | def parseAndSaveValueTree(input, actual_path): |
| 54 | root = json.loads(input) |