-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
205 lines (173 loc) · 5.77 KB
/
build.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env python2.7
#coding=UTF-8
import sys, os, shutil, subprocess
import app_info
project_root = os.path.dirname(os.path.realpath(__file__))
project_syspath = [
project_root,
os.path.join(project_root, "fsmonitor")
] + sys.path
target_name = "devo"
main_script = "main.py"
dist_dir = "dist"
platform_dir = os.path.join(dist_dir, sys.platform)
target_dir = os.path.join(platform_dir, "%s-%s" % (target_name, app_info.version_string))
includes = []
excludes = ["pywin", "pywin.debugger"]
encodings = ["ascii", "latin_1", "utf_8", "utf_16", "utf_32", "hex_codec", "mbcs"]
win32com_includes = ["win32com.shell"]
dll_excludes = [
"w9xpopen.exe",
"MSVCR71.DLL",
"MFC71.DLL",
"MSVCP71.DLL",
"gdiplus.dll",
"MSVCP90.dll",
"OLEACC.dll",
"mswsock.dll",
"powrprof.dll",
"UxTheme.dll",
"CRYPT32.dll",
]
def run(*args, **kwargs):
subprocess.Popen(args, **kwargs).communicate()
class Attributes(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def get_encodings_modules(encodings):
return ["encodings"] + ["encodings." + encoding for encoding in encodings]
def add_win32com_modules(win32com_modules):
# see http://www.py2exe.org/index.cgi/WinShell
try:
import py2exe.mf as modulefinder
import win32com
for p in win32com.__path__[1:]:
modulefinder.AddPackagePath("win32com", p)
for module_name in win32com_modules:
__import__(module_name)
m = sys.modules[module_name]
for p in m.__path__[1:]:
modulefinder.AddPackagePath(module_name, p)
except ImportError:
pass
def find_program_files(rel_path):
for envvar in ["PROGRAMW6432", "PROGRAMFILES", "PROGRAMFILES(X86)"]:
if envvar in os.environ:
path = os.path.join(os.environ[envvar], rel_path)
if os.path.exists(path):
return path
return ""
def build_py2exe():
from distutils.core import setup
import py2exe
class target(object):
script = main_script
dest_base = target_name
name = app_info.name
description = app_info.name
version = app_info.version_string
company_name = app_info.company_name
copyright = app_info.copyright.encode("latin-1")
icon_resources = [(1, "icons/devo.ico")]
sys.argv.append("py2exe")
sys.path = project_syspath
add_win32com_modules(win32com_includes)
setup(
options = {
"py2exe" : dict(
dist_dir = target_dir,
ascii = True,
includes = includes + get_encodings_modules(encodings),
excludes = excludes,
optimize = 1,
bundle_files = 3,
dll_excludes = dll_excludes,
compressed = True,
)
},
zipfile = None,
windows = [target],
)
sevenzip = find_program_files(r"7-Zip\7z.exe")
if sevenzip:
run(sevenzip, "a", "-tzip", "-y",
"%s-%s.zip" % (target_name, app_info.version_string),
"%s-%s" % (target_name, app_info.version_string),
cwd = platform_dir)
else:
print "Error: 7-zip not found"
def build_py2app():
from distutils.core import setup
import py2app
sys.argv.append("py2app")
sys.path = project_syspath
setup(
name = target_name,
setup_requires = "py2app",
app = [main_script],
data_files = [],
options = dict(
py2app = dict(
dist_dir = target_dir,
includes = includes + get_encodings_modules(encodings),
excludes = excludes,
optimize = 1,
compressed = True,
site_packages = True,
iconfile = "icons/devo.icns",
plist = dict(
CFBundleName = app_info.name,
CFBundleShortVersionString = app_info.version_string,
CFBundleGetInfoString = "%s %s" % (app_info.name, app_info.version_string),
CFBundleExecutable = target_name,
CFBundleIdentifier = app_info.identifier,
LSArchitecturePriority = ["x86_64", "i386"],
),
),
),
)
run("hdiutil", "create", "-srcfolder", target_dir, "-volname", app_info.name,
"-format", "UDBZ", "-ov", os.path.join(dist_dir, "%s-%s.dmg" % (target_name, app_info.version_string)))
def build_cxfreeze():
import cx_Freeze
cx_Freeze.Freezer(
[cx_Freeze.Executable(main_script, targetName=target_name)],
targetDir = target_dir,
includes = includes + get_encodings_modules(encodings),
excludes = excludes,
optimizeFlag = 1,
appendScriptToExe = True,
createLibraryZip = False,
copyDependentFiles = True,
binPathExcludes = ["/usr"],
path = project_syspath,
compress = True,
silent = False
).Freeze()
def make_tar_archive():
run("tar", "cvjf",
"%s-%s.tar.bz2" % (target_name, app_info.version_string),
"%s-%s" % (target_name, app_info.version_string),
cwd = platform_dir)
def build():
os.chdir(project_root)
shutil.rmtree(target_dir, True)
from get_components import get_components
try:
get_components()
except OSError:
pass
from compile_resources import compile_resources
compile_resources()
syspath = sys.path[:]
try:
if sys.platform == "win32":
build_py2exe()
elif sys.platform == "darwin":
build_py2app()
else:
build_cxfreeze()
finally:
sys.path = syspath
if __name__ == "__main__":
build()