#!/usr/bin/env python3 import ast import json import sys def settings2json(the_ast): ret = {'images': {}} if the_ast[0]['_type'] != the_ast[3]['_type']: raise TypeError('validation failed, wrong file?') for node in the_ast[1]['block']: if node['_type'] == 'Image': r = node['code'] if r: # not atl try: r['eval'] = ast.literal_eval(r['source']) except ValueError: pass ret['images'][' '.join(node['imgname'])] = r return ret with open(sys.argv[1], 'r') as f: output = settings2json(json.load(f)) json.dump(output, open(sys.argv[2], 'w'), separators=(',', ':'))