summaryrefslogtreecommitdiff
path: root/ast2json/settings2json.py
diff options
context:
space:
mode:
authorAlex Xu <alex_y_xu@yahoo.ca>2014-05-02 10:32:16 -0400
committerAlex Xu <alex_y_xu@yahoo.ca>2014-05-02 10:32:16 -0400
commit2e9bfa707b33f7e371088b66e75f4e76f90ebcee (patch)
tree08261187323f5ae2e72ce178acd5df5af1701f5e /ast2json/settings2json.py
parente417662dce5cae2e95ef98ee38baa8f53a02b9d5 (diff)
downloadhtml5ks-2e9bfa707b33f7e371088b66e75f4e76f90ebcee.tar.xz
html5ks-2e9bfa707b33f7e371088b66e75f4e76f90ebcee.zip
new image system
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: