Codebase list mirage / ad3412d
Have bin/mirage automatically compile & set up GLib resources Thomas Ross 3 years ago
3 changed file(s) with 41 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
1111
1212 # Emacs lock files
1313 .#*
14
15 # Resource files
16 *.gresource
2424 """
2525
2626 import os
27 import sys
28 import site
2729
28 from gi.repository import Gdk
30 from gi.repository import Gio, Gdk
31
32
33 MIRAGE_RESOURCE_FILE_NAME = "io.thomasross.mirage.gresource"
2934
3035
3136 def get_mirage_source_dir():
3843 return None
3944
4045
46 def get_data_file_path(filename):
47 for prefix in (
48 x for x in [sys.prefix, site.USER_BASE, getattr(sys, "base_prefix", None)] if x
49 ):
50 path = os.path.join(prefix, filename)
51 if os.path.exists(path):
52 return path
53
54 return None
55
56
4157 if __name__ == "__main__":
4258 mirage_source_dir = get_mirage_source_dir()
4359 uninstalled = mirage_source_dir is not None
4460
4561 if uninstalled:
46 import sys
62 import subprocess
4763
4864 sys.path.insert(0, mirage_source_dir)
65
66 resource_file_path = os.path.join(mirage_source_dir, MIRAGE_RESOURCE_FILE_NAME)
67 subprocess.call(
68 [
69 "glib-compile-resources",
70 "--sourcedir={}".format(os.path.join(mirage_source_dir, "resources")),
71 "--target={}".format(resource_file_path),
72 os.path.join(mirage_source_dir, "resources", "mirage.gresource.xml"),
73 ]
74 )
75 else:
76 resource_file_path = get_data_file_path(
77 os.path.join("share", "mirage", MIRAGE_RESOURCE_FILE_NAME)
78 )
79 if not resource_file_path:
80 print("Could not find", MIRAGE_RESOURCE_FILE_NAME, file=sys.stderr)
81 sys.exit(1)
82
83 resources = Gio.resource_load(resource_file_path)
84 Gio.resources_register(resources)
4985
5086 import mirage
5187
2828 import random, urllib.request, gettext, locale
2929 import stat, time, subprocess, shutil, filecmp
3030 import tempfile, socket, threading
31
32 resources = Gio.resource_load("mirage.gresource")
33 Gio.resources_register(resources)
3431
3532 from .fullscreen_controls import FullscreenControls
3633