-
Notifications
You must be signed in to change notification settings - Fork 4
/
beqdesigner.spec
241 lines (202 loc) · 7.27 KB
/
beqdesigner.spec
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# -*- mode: python -*-
import os
import platform
import distro
# work-around for https://github.com/pyinstaller/pyinstaller/issues/4064
import distutils
distutils_dir = getattr(distutils, 'distutils_path', None)
if distutils_dir is not None and distutils_dir.endswith('__init__.py'):
distutils.distutils_path = os.path.dirname(distutils.distutils_path)
generic_linux_excludes = [
'libstdc++.so.',
'libtinfo.so.',
'libreadline.so.',
'libdrm.so.'
]
fedora_excludes = [
'libgio-2.0.so.',
'libglib-2.0.so.',
'libfreetype.so.',
'libssl.so.',
'libfontconfig.so.'
]
debian_excludes = [
'libfontconfig.so.'
]
ubuntu_excludes = [
'libgpg-error.so.',
'libgtk-3.so.*',
'libgio-2.0.so.*'
]
linux_excludes = {
'ubuntu': generic_linux_excludes + ubuntu_excludes,
'linuxmint': generic_linux_excludes + ubuntu_excludes,
'fedora': generic_linux_excludes + fedora_excludes,
'centos': generic_linux_excludes + fedora_excludes,
'debian': generic_linux_excludes + debian_excludes
}
# helper functions
def get_resampy_path():
'''
:return: gets the current path to the resampy module in order to find where the kaiser data files are.
'''
import resampy as _
return _.__path__[0]
def get_icon_file():
'''
:return: the full path to the icon file for the current platform.
'''
return f"src/main/icons/{'icon.icns' if platform.system() == 'Darwin' else 'Icon.ico'}"
def use_nsis():
'''
:return: true if pyinstaller is being run in order to create an installer.
'''
return platform.system() == 'Windows' and 'USE_NSIS' in os.environ
def get_exe_args():
'''
:return: the *args to pass to EXE, varies according to whether we are in "create an installer" mode or not.
'''
return (a.scripts,) if use_nsis() is True else (a.scripts, a.binaries, a.zipfiles, a.datas)
def get_data_args():
'''
:return: the data array for the analysis.
'''
vals = [
('src/main/icons/Icon.ico', '.'),
(os.path.abspath(f"{get_resampy_path()}/data/kaiser_fast.npz"), '_resampy_filters'),
('src/main/python/style', 'style'),
('src/main/python/VERSION', '.'),
('src/main/xml/flat24hd.xml', '.'),
]
import glob
for p in glob.glob("src/main/xml/default_jriver_config_*.xml"):
vals.append((p, '.'))
return vals
def should_keep_binary(x):
'''
:param x: the binary (from Analysis.binaries)
:return: True if we should keep the given binary in the resulting output.
'''
if platform.system().lower().startswith('linux'):
dist = distro.linux_distribution(full_distribution_name=False)[0]
return not __is_exclude(x, linux_excludes.get(dist, generic_linux_excludes))
return True
def __is_exclude(x, excludes):
for exclude in excludes:
if x[0].startswith(exclude):
import sys
print(f"EXCLUDING {x}", file=sys.stderr)
return True
return False
def remove_platform_specific_binaries(a):
'''
Removes elements from the analysis based on the current platform.
Provides equivalent behaviour to https://github.com/mherrmann/fbs/tree/master/fbs/freeze
:param a: the pyinstaller analysis.
'''
a.binaries = [x for x in a.binaries if should_keep_binary(x) is True]
def get_exe_name():
'''
Gets the executable name which is beqdesigner for osx & windows and has some dist specific suffix for linux.
'''
if platform.system().lower().startswith('linux'):
linux_dist = distro.linux_distribution(full_distribution_name=False)
return f"beqdesigner_{'_'.join((x for x in linux_dist if x is not None and len(x) > 0))}"
elif platform.system().lower().startswith('windows'):
return f"beqdesigner_{platform.win32_ver()[0].replace('.', '_')}"
return 'beqdesigner'
def get_binaries():
'''
:return: the ssl binaries if we're on windows and they exist + graphviz (if available).
'''
ssl_dlls = get_ssl_dlls()
gz_binaries = get_graphviz_binaries()
return ssl_dlls + gz_binaries
def get_graphviz_binaries():
'''
:return: the graphviz binaries.
'''
if platform.system() == 'Windows':
return get_graphviz_windows()
return []
def get_graphviz_windows():
path_to_gz = os.environ.get('GZ_PATH', 'c:/Program Files/Graphviz/bin')
dot_exe = 'dot.exe'
if os.path.isfile(os.path.join(path_to_gz, dot_exe)):
gz = [
(os.path.join(path_to_gz, 'cdt.dll'), '.'),
(os.path.join(path_to_gz, 'cgraph.dll'), '.'),
(os.path.join(path_to_gz, 'dot.exe'), '.'),
(os.path.join(path_to_gz, 'gvc.dll'), '.'),
(os.path.join(path_to_gz, 'libexpat.dll'), '.'),
(os.path.join(path_to_gz, 'gvplugin_core.dll'), '.'),
(os.path.join(path_to_gz, 'gvplugin_dot_layout.dll'), '.'),
(os.path.join(path_to_gz, 'pathplan.dll'), '.'),
(os.path.join(path_to_gz, 'xdot.dll'), '.'),
(os.path.join(path_to_gz, 'zlib1.dll'), '.')
]
return gz
else:
print(f"MISSING {os.path.join(path_to_gz, dot_exe)}")
return []
def get_ssl_dlls():
if platform.system() == 'Windows':
import os
ssl_dll = 'c:/Windows/System32/libssl-1_1-x64.dll'
crypto_dll = 'c:/Windows/System32/libcrypto-1_1-x64.dll'
if os.path.isfile(ssl_dll):
if os.path.isfile(crypto_dll):
return [
(ssl_dll, '.'),
(crypto_dll, '.'),
]
else:
print(f"MISSING libcrypto-1_1-x64.dll")
else:
print(f"MISSING libssl-1_1-x64.dll")
return []
block_cipher = None
spec_root = os.path.abspath(SPECPATH)
a = Analysis(['src/main/python/app.py'],
pathex=[spec_root],
binaries=get_binaries(),
datas=get_data_args(),
hiddenimports=['numpy.random', 'pkg_resources.py2_warn', 'scipy.spatial.transform._rotation_groups'],
hookspath=['hooks/'],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
remove_platform_specific_binaries(a)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(pyz,
*get_exe_args(),
name=get_exe_name(),
debug=False,
strip=False,
upx=False,
console=True,
exclude_binaries=use_nsis(),
icon=get_icon_file())
if platform.system() == 'Darwin':
app = BUNDLE(exe,
name='beqdesigner.app',
bundle_identifier='com.3ll3d00d.beqdesigner',
icon='src/main/icons/icon.icns',
info_plist={
'NSHighResolutionCapable': 'True',
'LSBackgroundOnly': 'False',
'NSRequiresAquaSystemAppearance': 'False',
'LSEnvironment': {
'PATH': '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:'
}
})
if use_nsis() is True:
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
name='beqdesigner')