trezor-core/tools/res_collect.py

37 lines
974 B
Python
Raw Normal View History

#!/usr/bin/env python3
import os
resources = {}
2016-09-26 06:13:33 -07:00
os.chdir('../src/')
def process_file(name):
if name.endswith('.gitignore'):
return
if name.endswith('.py'):
return
print('processing file %s' % name)
with open(name, 'rb') as f:
2016-09-26 06:13:33 -07:00
resources[name] = f.read()
2016-05-27 18:24:58 -07:00
# scan common resources
2016-09-26 06:13:33 -07:00
for res in os.scandir('trezor/res/'):
if res.is_file():
2016-09-26 06:13:33 -07:00
process_file('trezor/res/%s' % res.name)
# scan apps
2016-09-26 06:13:33 -07:00
for app in os.scandir('apps/'):
if app.is_dir() and os.path.isdir('apps/%s/res/' % app.name):
for res in os.scandir('apps/%s/res/' % app.name):
if res.is_file():
2016-09-26 06:13:33 -07:00
process_file('apps/%s/res/%s' % (app.name, res.name))
2016-09-26 06:13:33 -07:00
resfile = 'trezor/res/resources.py'
with open(resfile, 'wt') as f:
f.write('resdata = {\n')
for k in sorted(resources.keys()):
f.write(" '%s': %s,\n" % (k, resources[k]))
f.write('}\n')
print('written %s with %d entries' % (resfile, len(resources)))