24 | 24 |
"""
|
25 | 25 |
|
26 | 26 |
import os
|
|
27 |
import sys
|
|
28 |
import site
|
27 | 29 |
|
28 | |
from gi.repository import Gdk
|
|
30 |
from gi.repository import Gio, Gdk
|
|
31 |
|
|
32 |
|
|
33 |
MIRAGE_RESOURCE_FILE_NAME = "io.thomasross.mirage.gresource"
|
29 | 34 |
|
30 | 35 |
|
31 | 36 |
def get_mirage_source_dir():
|
|
38 | 43 |
return None
|
39 | 44 |
|
40 | 45 |
|
|
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 |
|
41 | 57 |
if __name__ == "__main__":
|
42 | 58 |
mirage_source_dir = get_mirage_source_dir()
|
43 | 59 |
uninstalled = mirage_source_dir is not None
|
44 | 60 |
|
45 | 61 |
if uninstalled:
|
46 | |
import sys
|
|
62 |
import subprocess
|
47 | 63 |
|
48 | 64 |
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)
|
49 | 85 |
|
50 | 86 |
import mirage
|
51 | 87 |
|