2016-05-27 07:48:23 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
2017-06-07 05:23:18 -07:00
|
|
|
import io
|
2016-05-27 07:48:23 -07:00
|
|
|
|
|
|
|
resources = {}
|
2016-10-03 02:56:24 -07:00
|
|
|
resources_size = 0
|
2016-05-27 07:48:23 -07:00
|
|
|
|
2016-09-29 04:35:00 -07:00
|
|
|
os.chdir(os.path.dirname(__file__))
|
2016-09-26 06:13:33 -07:00
|
|
|
os.chdir('../src/')
|
2016-05-31 05:31:28 -07:00
|
|
|
|
2016-10-12 04:12:27 -07:00
|
|
|
|
2016-05-27 07:48:23 -07:00
|
|
|
def process_file(name):
|
2016-05-31 05:31:28 -07:00
|
|
|
if name.endswith('.gitignore'):
|
|
|
|
return
|
2016-05-27 07:48:23 -07:00
|
|
|
if name.endswith('.py'):
|
|
|
|
return
|
2016-10-06 08:54:57 -07:00
|
|
|
if os.path.basename(name).startswith('.'):
|
|
|
|
return
|
2016-05-27 07:48:23 -07:00
|
|
|
with open(name, 'rb') as f:
|
2016-10-03 02:56:24 -07:00
|
|
|
data = f.read()
|
|
|
|
resources[name] = data
|
|
|
|
print('processing file %s (%d bytes)' % (name, len(data)))
|
|
|
|
global resources_size
|
|
|
|
resources_size += len(data)
|
2016-05-27 07:48:23 -07:00
|
|
|
|
2016-10-12 04:12:27 -07:00
|
|
|
|
|
|
|
def process_dir_rec(dir):
|
|
|
|
for name in os.listdir(dir):
|
|
|
|
path = os.path.join(dir, name)
|
|
|
|
if os.path.isfile(path):
|
|
|
|
process_file(path)
|
|
|
|
elif os.path.isdir(path):
|
|
|
|
process_dir_rec(path)
|
|
|
|
|
|
|
|
|
|
|
|
process_dir_rec('trezor/res/')
|
|
|
|
for name in os.listdir('apps/'):
|
|
|
|
path = os.path.join('apps/', name, 'res/')
|
|
|
|
if os.path.isdir(path):
|
|
|
|
process_dir_rec(path)
|
2016-05-27 07:48:23 -07:00
|
|
|
|
2016-09-26 06:13:33 -07:00
|
|
|
resfile = 'trezor/res/resources.py'
|
2017-06-07 05:23:18 -07:00
|
|
|
|
|
|
|
bio = io.StringIO()
|
|
|
|
bio.write('resdata = {\n')
|
|
|
|
for k in sorted(resources.keys()):
|
|
|
|
bio.write(" '%s': %s,\n" % (k, resources[k]))
|
|
|
|
bio.write('}\n')
|
|
|
|
|
2017-06-13 11:15:47 -07:00
|
|
|
try:
|
|
|
|
with open(resfile, 'r') as f:
|
|
|
|
stale = f.read()
|
|
|
|
except:
|
|
|
|
stale = None
|
|
|
|
|
|
|
|
fresh = bio.getvalue()
|
2017-06-07 05:23:18 -07:00
|
|
|
|
|
|
|
if stale != fresh:
|
|
|
|
with open(resfile, 'wt') as f:
|
|
|
|
f.write(fresh)
|
|
|
|
print('written %s with %d entries (total %d bytes)' %
|
|
|
|
(resfile, len(resources), resources_size))
|
|
|
|
else:
|
|
|
|
print('continuing with %s, no changes detected' % (resfile))
|