summaryrefslogtreecommitdiff
path: root/ast2json/settings2json.py
diff options
context:
space:
mode:
Diffstat (limited to 'ast2json/settings2json.py')
-rwxr-xr-xast2json/settings2json.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/ast2json/settings2json.py b/ast2json/settings2json.py
index a72239d..1e41e2e 100755
--- a/ast2json/settings2json.py
+++ b/ast2json/settings2json.py
@@ -1,16 +1,22 @@
#!/usr/bin/env python3
+import ast
import json
import sys
-def settings2json(ast):
- ret = {}
- if ast[0]['_type'] != 'Label':
- raise TypeError('obj does not start with Label, wrong file?')
- for label in ast:
- if label['parameters'] is not None:
- raise NotImplementedError()
- ret[label['name']] = label['block']
+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: