blob: 1e41e2e4b19826ac9bd19d0701b70270f163ba49 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#!/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=(',', ':'))
|