-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·187 lines (170 loc) · 5.25 KB
/
setup.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# @author Lukas Schreiner
#
import sys
import os.path
import subprocess
import shlex
import glob
import zipfile
import shutil
from cx_Freeze import setup, Executable
from flsvplan import __version__ as flsvplan_version
scriptDir = os.path.dirname(os.path.realpath(__file__))
buildDir = os.path.join(scriptDir, 'build')
distDir = os.path.join(scriptDir, 'dist')
def addToZip(zipFile, p):
if os.path.isdir(p):
for fls in glob.glob(os.path.join(p, '*'), recursive=True):
addToZip(zipFile, fls)
else:
zipFile.write(p, os.path.relpath(p, buildDir))
files = [
os.path.join(scriptDir, 'config.ini.sample'),
]
# really dirty hack for Windows Server
if sys.platform == 'win32':
# Platforms plugins
pluginPath = os.path.join(
os.path.dirname(sys.executable),
'..\\Lib\\site-packages\\PyQt5\\Qt\\plugins\\platforms'
)
for f in glob.glob(pluginPath + '\\*.dll'):
files.append((f, 'platforms\\' + os.path.basename(f)))
# Image formats plugins
pluginPath = os.path.join(
os.path.dirname(sys.executable),
'..\\Lib\\site-packages\\PyQt5\\Qt\\plugins\\imageformats'
)
for f in glob.glob(pluginPath + '\\*.dll'):
files.append((f, 'imageformats\\' + os.path.basename(f)))
# DEFAULT VALUES
setupVersion = flsvplan_version
setupDescription = "Vertretungsplaner Client"
setupPublisher = 'Friedrich-List-Schule Wiesbaden'
setupPublisherMail = '[email protected]'
if sys.argv[-1] in ['gks', 'fls', 'sds']:
variant = sys.argv.pop()
else:
variant = 'fls'
setupSrcIco = '%s.ico' % (variant,)
if variant == 'fls':
setupName = 'FLS Vertretungsplaner'
setupUrl = 'https://www.fls-wiesbaden.de'
setupGuid = 'ED537E23-D959-4C1A-AEBD-580CDF68E450'
elif variant == 'gks':
setupUrl = 'https://vplan.gks-obertshausen.de'
setupName = 'GKS Vertretungsplaner'
setupGuid = '22A5D5F7-0677-4691-9D08-5CE05E11AAFD'
elif variant == 'sds':
setupUrl = 'https://sds.fls-wiesbaden.de'
setupName = 'SDS Vertretungsplaner'
setupGuid = '7CE997E4-8D0A-4406-A3EA-F48CAB29F4A9'
setupIco = os.path.join(scriptDir, 'pixmaps', setupSrcIco)
files.append((setupIco, 'logo.ico'))
# check and add destination configuration (preconfigured version)
ciConfigFile = None
if os.path.exists(os.path.join(scriptDir, 'config.ini')):
ciConfigFile = os.path.join(scriptDir, 'config.ini')
# Automatic jenkins build: any secret config based on variant?
ciConfigFileName = 'vplanconfig_{}'.format(variant)
try:
ciConfigFileTmp = os.environ[ciConfigFileName]
if os.path.exists(ciConfigFileTmp):
ciConfigFile = ciConfigFileTmp
except KeyError:
print('Could not find: {}'.format(ciConfigFileName))
finally:
if ciConfigFile:
files.append((ciConfigFile, 'config.ini'))
base = None
exeName = 'flsvplan'
exeDebug = 'flsvplan_debug'
if sys.platform == "win32":
base = "Win32GUI"
exeName = exeName + '.exe'
exeDebug = exeDebug + '.exe'
flsvplan = Executable(
"flsvplan.py",
base = base,
icon = setupIco,
targetName = exeName,
copyright = setupPublisher
)
flsvplan_debug = Executable(
"flsvplan.py",
base = None,
icon = setupIco,
targetName = exeDebug,
copyright = setupPublisher
)
buildOpts = {
'include_files': files,
'zip_include_packages': [
'PyQt5.QtNetwork', 'PyQt5.sip', 'PyQt5.QtCore', 'PyQt5.QtGui', 'PyQt5.QtWidgets', 'PyQt5',
'sip'
],
'packages': ['planparser'],
'include_msvcr': True,
'includes': [
'queue', 'sentry_sdk.integrations.logging', 'sentry_sdk.integrations.stdlib',
'sentry_sdk.integrations.excepthook', 'sentry_sdk.integrations.dedupe',
'sentry_sdk.integrations.atexit', 'sentry_sdk.integrations.modules',
'sentry_sdk.integrations.argv', 'sentry_sdk.integrations.threading'
],
'build_exe': os.path.join(buildDir, 'vplan-{:s}'.format(setupVersion))
}
setup(
name = setupName,
version = setupVersion,
description = setupDescription,
author = setupPublisher,
author_email = setupPublisherMail,
url = setupUrl,
options = {'build_exe': buildOpts},
executables = [flsvplan, flsvplan_debug]
)
# inno setup?
if sys.platform == "win32":
cmd = 'iscc \
/DMyAppVersion="{version}" \
/DMyAppName="{name}" \
/DMyAppPublisher="{publisher}" \
/DMyAppURL="{url}" \
/DMyAppExeName="{exeName}" \
/DbuildDirectory="{buildDirectory}" \
/DMyAppGuid="{appGuid}" \
inno_setup.iss'.format(
version=setupVersion,
name=setupName,
publisher=setupPublisher,
url=setupUrl,
exeName=exeName,
buildDirectory=os.path.join(buildDir, 'vplan-{:s}'.format(setupVersion)),
appGuid=setupGuid
)
exeCmd = shlex.split(cmd)
try:
p = subprocess.Popen(exeCmd)
except FileNotFoundError:
sys.stderr.write('ISCC setup builder not supported here.' + os.linesep)
else:
p.communicate()
# copy setup file to build directory.
srcSetupFile = os.path.join(scriptDir, 'Output', setupName + '_' + setupVersion + '_setup.exe')
dstSetupFile = os.path.join(buildDir, setupName + '_' + setupVersion + '_setup.exe')
if os.path.exists(srcSetupFile):
shutil.copyfile(srcSetupFile, dstSetupFile)
# create dist file.
if not os.path.exists(distDir):
try:
os.makedirs(distDir, exist_ok=True)
except:
pass
distZipName = os.path.join(distDir, 'vplan-{:s}.zip'.format(setupVersion))
zf = zipfile.ZipFile(distZipName, 'w', compression=zipfile.ZIP_DEFLATED)
for fls in glob.glob(os.path.join(buildDir, 'vplan-{:s}'.format(setupVersion), '*'), recursive=True):
addToZip(zf, fls)
zf.close()