-
Notifications
You must be signed in to change notification settings - Fork 1
/
compile.py
executable file
·131 lines (105 loc) · 3.14 KB
/
compile.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python
"""
Trying to keep compile_linux.sh, compile_windows.bat, and compile_osx.sh
in sync is a pain. Also, because the windows command line is terrible,
trying to do anything at all in compile_windows.bat is also a pain.
This is an ugly bloated mess, but it seems better than the alternatives...
"""
import subprocess
import os
import platform
import tarfile
import zipfile
import textwrap
os_type = platform.system()
def get_spec():
gui_data = [
("icon.ico", "icon.ico", "DATA"),
("help.html", "help.html", "DATA"),
("LICENSE.txt", "LICENSE.txt", "DATA"),
]
bin_ext = ""
if os_type == "Windows":
bin_ext = ".exe"
return textwrap.dedent("""
# GUI spec
a = Analysis(['main_gui.py'])
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas + %(gui_data)r,
name=os.path.join('dist', 'eve-gmlp%(bin_ext)s'),
debug=False,
strip=None,
upx=True,
console=False,
icon='icon.ico'
)
app = BUNDLE(
exe,
name=os.path.join('dist', 'eve-gmlp.app')
)
# CLI spec
a = Analysis(['main_cli.py'])
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name=os.path.join('dist', 'eve-mlp%(bin_ext)s'),
debug=False,
strip=None,
upx=True,
console=True,
icon='icon.ico'
)
""".rstrip()) % {
"gui_data": gui_data,
"bin_ext": bin_ext,
}
def init_environ():
if os_type == "Linux":
os.environ["LD_LIBRARY_PATH"] = "/usr/lib/x86_64-linux-gnu/"
if os_type == "Windows":
os.environ["PATH"] = os.environ.get("PATH", "") + ";C:\Python27"
def get_version():
try:
version = subprocess.check_output("git describe", shell=True)
version = version.strip()[1:]
except:
version = "UNKNOWN"
return version
def build(version):
print "*** Building EVE-MLP %s Binaries" % version
file("_compile.spec", "w").write(get_spec())
pyinstaller = os.path.join("..", "pyinstaller-2.0", "pyinstaller.py")
comp = subprocess.Popen("python %s _compile.spec" % pyinstaller, shell=True)
comp.wait()
os.unlink("_compile.spec")
def package(version):
print "*** Building %s Packages" % os_type
os.chdir("dist")
if os_type == "Linux":
tar = tarfile.open("eve-mlp-%s.tar.gz" % version, "w:gz")
tar.add("eve-mlp")
tar.close()
tar = tarfile.open("eve-gmlp-%s.tar.gz" % version, "w:gz")
tar.add("eve-gmlp")
tar.close()
if os_type == "Windows":
zip = zipfile.ZipFile("eve-mlp-%s.zip" % version, "w")
zip.write("eve-mlp.exe")
zip.close()
zip = zipfile.ZipFile("eve-gmlp-%s.zip" % version, "w")
zip.write("eve-gmlp.exe")
zip.close()
if __name__ == "__main__":
init_environ()
version = get_version()
build(version)
package(version)