Created
June 17, 2016 11:09
-
-
Save zindel/b73cee596d5ddcb62afc46338ceb07b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.makedirs(os.path.join(os.getcwd(), 'resource')) | |
for path, _, files in os.walk('./urlmap'): | |
for file in files: | |
if not file.endswith('.yaml'): | |
continue | |
fname = os.path.join(path, file) | |
content = open(fname).read() | |
if 'widget:' in content: | |
continue | |
lines = content.split('\n') | |
i = 0 | |
while lines[i].strip() != 'action:': | |
i += 1 | |
lines = lines[i + 1:] | |
for i, s in enumerate(lines): | |
assert s[0:6] == (' ' * 6) or not s.strip(), s + ' : ' + fname | |
parts = s.split(': ') | |
if len(parts) == 2 \ | |
and (parts[1].strip().startswith('/wizard') \ | |
or parts[1].strip().startswith('/action')): | |
url = parts[1].strip()[7:].replace('-', '_') | |
lines[i] = '%s: rex.study:/resource/common%s.yaml' % (parts[0], url) | |
content = '\n'.join([('' if not s.strip() else s[6:]) for s in lines]) | |
newname = fname.replace('/urlmap/', '/resource/') | |
dirname = os.path.dirname(newname) | |
if not os.path.isdir(dirname): | |
os.makedirs(dirname) | |
with open(newname, 'w') as f: | |
f.write(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment