forked from hgoldfish/quickpanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_files.py
72 lines (61 loc) · 2.39 KB
/
compile_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
class NotFound(Exception):
pass
def findPyQtTools_win32():
pythondir = os.path.dirname(sys.executable)
systempaths = os.environ["PATH"].split(";")
systempaths = [path.strip() for path in systempaths]
def findTool(toolname):
tool = os.path.join(pythondir, toolname)
if not os.path.exists(tool):
tool = os.path.join(pythondir, "Scripts", toolname)
if not os.path.exists(tool):
tool = os.path.join(pythondir, "Lib\\site-packages\\PyQt5", toolname)
if not os.path.exists(tool):
for systempath in systempaths:
tool = os.path.join(systempath, toolname)
if os.path.exists(tool):
break
if not os.path.exists(tool):
raise NotFound()
return tool
pyrcc = findTool("pyrcc5.bat")
pyuic = findTool("pyuic5.bat")
return pyrcc, pyuic
def findPyQtTools_linux():
pyrcc = "/usr/bin/pyrcc5"
if not os.path.exists(pyrcc):
pyrcc = "/usr/local/bin/pyrcc5"
if not os.path.exists(pyrcc):
raise NotFound()
pyuic = "/usr/bin/pyuic5"
if not os.path.exists(pyuic):
pyuic = "/usr/local/bin/pyuic5"
if not os.path.exists(pyuic):
raise NotFound()
return pyrcc, pyuic
curdir = os.path.abspath(os.path.dirname(__file__))
J = os.path.join
try:
pyrcc, pyuic = findPyQtTools_win32() if os.name == "nt" else findPyQtTools_linux()
except NotFound:
print("pyqt tools are not found in your machine.")
sys.exit(1)
if not os.path.exists(J(curdir, "quickpanel_rc.py")) or \
os.path.getmtime(J(curdir, "quickpanel_rc.py")) < os.path.getmtime(J(curdir, "quickpanel.qrc")):
print("compile quickpanel.qrc to quickpanel_rc.py")
os.system("{2} -o {0} {1}".format(J(curdir, "quickpanel_rc.py"), J(curdir, "quickpanel.qrc"), pyrcc))
for root, dirs, files in os.walk(os.path.join(curdir, "besteam")):
for filename in files:
if not filename.endswith(".ui"):
continue
basename = "Ui_" + os.path.splitext(filename)[0] + ".py"
pyfile = J(root, basename)
uifile = J(root, filename)
if os.path.exists(pyfile) and os.path.getmtime(pyfile) > os.path.getmtime(uifile):
continue
print("compiling", uifile, "to", pyfile)
os.system("{2} -x -o {0} {1}".format(pyfile, uifile, pyuic))