diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2020-07-14 20:46:34 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2020-07-14 20:46:34 (GMT) |
commit | 611aa243b42aa854a8a5302a634cef14a7dced90 (patch) | |
tree | 243a34b5f95531f51aa2c2db6d41fd407b70764d | |
parent | 1a73afdd420c8648fb58d7e3fb9d80b06f975acd (diff) |
Created a small tool to unpack theme modules.
-rw-r--r-- | python/extract.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/python/extract.py b/python/extract.py new file mode 100644 index 0000000..e04ba7e --- /dev/null +++ b/python/extract.py @@ -0,0 +1,71 @@ + +import gi +import os +import sys +from gi.repository import Gio + + +if len(sys.argv) != 2: + print('Usage: %s <theme file>' % sys.argv[0]) + sys.exit(1) + +res = Gio.Resource.load(sys.argv[1]) + + +# Get the name of the theme + +children = res.enumerate_children('/org/chrysalide/gui/themes', Gio.ResourceLookupFlags.NONE) + +name = children[0][:-1] + + +# Prepare the output directory + +if not(os.path.isdir(name)): + os.mkdir(name) + + +# Dump resource files + +files = '' + +children = res.enumerate_children('/org/chrysalide/gui/themes/' + name, Gio.ResourceLookupFlags.NONE) + +for child in children: + + raw = res.lookup_data('/org/chrysalide/gui/themes/' + name + '/' + child, Gio.ResourceLookupFlags.NONE) + + with open(name + os.sep + child, 'wb') as out: + out.write(raw.get_data()) + + files += '\n <file compressed="true">%s</file>' % child + + +# Create the gresource.xml file + +xml = '''<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/chrysalide/gui/themes/%s">%s + </gresource> +</gresources> +''' % (name, files) + +with open(name + os.sep + 'gresource.xml', 'w') as out: + out.write(xml) + + +# Create a Makefile + +rules = ''' +GTK3_CSS = %s + +%s.ctm: gresource.xml $(GTK3_CSS) + glib-compile-resources --target=$@ --sourcedir=. gresource.xml + +clean: + rm -f %s + +''' % (' '.join(children), name.lower(), name.lower()) + +with open(name + os.sep + 'Makefile', 'w') as out: + out.write(rules) |