2017-03-11 21:54:20 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# Generate gtk.gresources.xml
|
|
|
|
#
|
|
|
|
# Usage: gen-gtk-gresources-xml SRCDIR_GTK [OUTPUT-FILE]
|
|
|
|
|
|
|
|
import os, sys
|
2020-04-03 11:58:18 +00:00
|
|
|
import filecmp
|
|
|
|
|
|
|
|
def replace_if_changed(new, old):
|
|
|
|
'''
|
|
|
|
Compare contents and only replace if changed to avoid triggering a rebuild.
|
|
|
|
'''
|
|
|
|
try:
|
|
|
|
changed = not filecmp.cmp(new, old, shallow=False)
|
|
|
|
except FileNotFoundError:
|
|
|
|
changed = True
|
|
|
|
if changed:
|
|
|
|
os.replace(new, old)
|
|
|
|
else:
|
|
|
|
os.remove(new)
|
2017-03-11 21:54:20 +00:00
|
|
|
|
|
|
|
srcdir = sys.argv[1]
|
|
|
|
|
|
|
|
xml = '''<?xml version='1.0' encoding='UTF-8'?>
|
|
|
|
<gresources>
|
|
|
|
<gresource prefix='/org/gtk/libgtk'>
|
|
|
|
'''
|
|
|
|
|
|
|
|
def get_files(subdir,extension):
|
|
|
|
return sorted(filter(lambda x: x.endswith((extension)), os.listdir(os.path.join(srcdir,subdir))))
|
|
|
|
|
|
|
|
xml += '''
|
2020-01-17 22:42:06 +00:00
|
|
|
<file>theme/Empty/gtk.css</file>
|
2021-01-15 06:07:08 +00:00
|
|
|
|
2021-01-15 05:25:30 +00:00
|
|
|
<file>theme/Default/gtk.css</file>
|
2021-01-15 06:07:08 +00:00
|
|
|
<file alias='theme/Default-dark/gtk.css'>theme/Default/gtk-dark.css</file>
|
|
|
|
<file alias='theme/Default-hc/gtk.css'>theme/Default/gtk-hc.css</file>
|
|
|
|
<file alias='theme/Default-hc-dark/gtk.css'>theme/Default/gtk-hc-dark.css</file>
|
|
|
|
|
2021-01-15 05:25:30 +00:00
|
|
|
<file>theme/Default/gtk-light.css</file>
|
|
|
|
<file>theme/Default/gtk-dark.css</file>
|
|
|
|
<file>theme/Default/gtk-hc.css</file>
|
|
|
|
<file>theme/Default/gtk-hc-dark.css</file>
|
|
|
|
<file>theme/Default/Default-light.css</file>
|
|
|
|
<file>theme/Default/Default-dark.css</file>
|
|
|
|
<file>theme/Default/Default-hc.css</file>
|
|
|
|
<file>theme/Default/Default-hc-dark.css</file>
|
2017-03-11 21:54:20 +00:00
|
|
|
'''
|
|
|
|
|
2021-01-15 05:25:30 +00:00
|
|
|
for f in get_files('theme/Default/assets', '.png'):
|
|
|
|
xml += ' <file>theme/Default/assets/{0}</file>\n'.format(f)
|
2017-03-11 21:54:20 +00:00
|
|
|
|
|
|
|
xml += '\n'
|
|
|
|
|
2021-01-15 05:25:30 +00:00
|
|
|
for f in get_files('theme/Default/assets', '.svg'):
|
|
|
|
xml += ' <file>theme/Default/assets/{0}</file>\n'.format(f)
|
2017-03-11 21:54:20 +00:00
|
|
|
|
2021-01-15 05:25:30 +00:00
|
|
|
for f in get_files('theme/Default/assets-hc', '.png'):
|
|
|
|
xml += ' <file>theme/Default/assets-hc/{0}</file>\n'.format(f)
|
2017-03-11 21:54:20 +00:00
|
|
|
|
|
|
|
xml += '\n'
|
|
|
|
|
2021-01-15 05:25:30 +00:00
|
|
|
for f in get_files('theme/Default/assets-hc', '.svg'):
|
|
|
|
xml += ' <file>theme/Default/assets-hc/{0}</file>\n'.format(f)
|
2017-03-11 21:54:20 +00:00
|
|
|
|
|
|
|
for f in get_files('ui', '.ui'):
|
|
|
|
xml += ' <file preprocess=\'xml-stripblanks\'>ui/{0}</file>\n'.format(f)
|
|
|
|
|
|
|
|
xml += '\n'
|
|
|
|
|
2021-01-28 04:34:06 +00:00
|
|
|
for s in ['16x16', '32x32', '64x64', 'scalable']:
|
2019-02-12 17:40:17 +00:00
|
|
|
for c in ['actions', 'categories', 'emblems', 'emotes', 'devices', 'mimetypes', 'places', 'status']:
|
2018-07-27 11:16:44 +00:00
|
|
|
icons_dir = 'icons/{0}/{1}'.format(s,c)
|
|
|
|
if os.path.exists(os.path.join(srcdir,icons_dir)):
|
|
|
|
for f in get_files(icons_dir, '.png'):
|
|
|
|
xml += ' <file>icons/{0}/{1}/{2}</file>\n'.format(s,c,f)
|
2019-01-24 21:12:27 +00:00
|
|
|
for f in get_files(icons_dir, '.svg'):
|
|
|
|
xml += ' <file>icons/{0}/{1}/{2}</file>\n'.format(s,c,f)
|
2018-07-27 11:16:44 +00:00
|
|
|
|
2017-03-11 21:54:20 +00:00
|
|
|
for f in get_files('inspector', '.ui'):
|
|
|
|
xml += ' <file preprocess=\'xml-stripblanks\'>inspector/{0}</file>\n'.format(f)
|
|
|
|
|
|
|
|
xml += '''
|
2019-05-07 22:04:41 +00:00
|
|
|
<file>inspector/inspector.css</file>
|
2020-10-04 02:26:56 +00:00
|
|
|
<file>emoji/en.data</file>
|
2021-07-08 21:59:50 +00:00
|
|
|
<file>compose/sequences</file>
|
|
|
|
<file>compose/chars</file>
|
2017-03-11 21:54:20 +00:00
|
|
|
</gresource>
|
|
|
|
</gresources>'''
|
|
|
|
|
|
|
|
if len(sys.argv) > 2:
|
|
|
|
outfile = sys.argv[2]
|
2020-04-03 11:58:18 +00:00
|
|
|
tmpfile = outfile + '~'
|
|
|
|
with open(tmpfile, 'w') as f:
|
|
|
|
f.write(xml)
|
|
|
|
replace_if_changed(tmpfile, outfile)
|
2017-03-11 21:54:20 +00:00
|
|
|
else:
|
|
|
|
print(xml)
|