-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_pyinstaller.py
185 lines (158 loc) · 4.1 KB
/
setup_pyinstaller.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
17 Aug 2019
@autor: Daniel Carrasco
'''
import PyInstaller.__main__
from os import path, makedirs, remove
import glob
import shutil
# Package Options
package_name = "Components Manager"
package_file = "manager.py"
onefile = True
console = False
icon = "images/icon.ico"
# Encryption Key must have 16 characters.
encryption_key = None
# Compression options
upx = False
upx_excluded = [
"vcruntime140.dll",
]
# Included/Excluded modules and files
included_data = [
(
"images/*.*",
"images/"
),
(
"images/filetypes/*.*",
"images/filetypes/"
),
(
"plugins/database/sqlite/sqlite_components.sql",
"plugins/database/sqlite/"
),
(
"plugins/database/sqlite/sqlite_templates.sql",
"plugins/database/sqlite/"
)
]
included_binary = []
included_external = []
included_modules = [
"screeninfo.enumerators.cygwin",
"screeninfo.enumerators.drm",
"screeninfo.enumerators.osx",
"screeninfo.enumerators.windows",
"screeninfo.enumerators.xinerama",
"screeninfo.enumerators.xrandr"
]
excluded_modules = [
"OpenGL",
"email",
"html",
"pydoc_data",
"unittest",
"http",
"xml",
"pkg_resources",
"numpy"
]
# Compile Options
noconfirm = True
clean = True
log_level = "DEBUG"
version = (1, 3, 2, 0)
# Build the command
pyInstaller_cmd = [
'--name=%s' % package_name
]
if onefile:
pyInstaller_cmd.append("--onefile")
if console:
pyInstaller_cmd.append("--console")
else:
pyInstaller_cmd.append("--windowed")
if icon:
pyInstaller_cmd.append("--icon={}".format(icon))
if encryption_key:
pyInstaller_cmd.append("--key={}".format(encryption_key))
if not upx:
pyInstaller_cmd.append("--noupx")
else:
for item in upx_excluded:
pyInstaller_cmd.append("--upx-exclude={}".format(item))
for item in included_data:
pyInstaller_cmd.append("--add-data={};{}".format(item[0], item[1]))
for item in included_binary:
pyInstaller_cmd.append("--add-binary={};{}".format(item[0], item[1]))
for item in included_modules:
pyInstaller_cmd.append("--hidden-import={}".format(item))
for item in excluded_modules:
pyInstaller_cmd.append("--exclude-module={}".format(item))
if noconfirm:
pyInstaller_cmd.append("--noconfirm")
if clean:
pyInstaller_cmd.append("--clean")
if log_level:
pyInstaller_cmd.append("--log-level={}".format(log_level))
pyInstaller_cmd.append(package_file)
# Creating Version file
version_data = """
VSVersionInfo(
ffi=FixedFileInfo(
filevers=({0}, {1}, {2}, {3}),
prodvers=({0}, {1}, {2}, {3}),
mask=0x3f,
flags=0x0,
OS=0x40004,
fileType=0x1,
subtype=0x0,
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
u'040904B0',
[StringStruct(u'CompanyName', u'Danixu'),
StringStruct(u'FileDescription', u'{4}'),
StringStruct(u'FileVersion', u'{0}.{1}.{2}.{3}'),
StringStruct(u'InternalName', u'{4}'),
StringStruct(u'LegalCopyright', u'\xa9 Danixu'),
StringStruct(u'OriginalFilename', u'{4}'),
StringStruct(u'ProductName', u'{4}'),
StringStruct(u'ProductVersion', u'{0}.{1}.{2}.{3}')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
)""".format(
version[0],
version[1],
version[2],
version[3],
package_name
)
with open("version", "w", encoding='utf8') as version_file:
version_file.write(version_data)
pyInstaller_cmd.append("--version-file=version")
print(pyInstaller_cmd)
PyInstaller.__main__.run(pyInstaller_cmd)
remove("version")
# copying external files to output folder
output = "dist/"
if not onefile:
output = path.join(output, package_name)
for toCopy in included_external:
dest_dir = path.join(output, toCopy[1])
if not path.isdir(dest_dir):
makedirs(dest_dir)
for file in glob.glob(toCopy[0]):
print("Copying file {} to folder {}".format(file, dest_dir))
try:
shutil.copy(file, dest_dir)
except Exception as e:
print("There was an error copying the file: {}".format(e))