forked from EDCD/EDMarketConnector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·229 lines (206 loc) · 9.71 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
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
import codecs
import os
from os.path import exists, isdir, join
import platform
import re
import shutil
import sys
from tempfile import gettempdir
import requests
from config import appname as APPNAME, applongname as APPLONGNAME, appcmdname as APPCMDNAME, appversion as VERSION
from config import update_feed, update_interval
if sys.platform=='win32':
assert platform.architecture()[0]=='32bit', 'Assumes a Python built for 32bit'
import py2exe
dist_dir = 'dist.win32'
elif sys.platform=='darwin':
if sys.executable.startswith('/usr'):
# SIP doesn't allow symlinks to /usr/bin/...
import subprocess
subprocess.call(['/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python'] + sys.argv, stdout=sys.stdout, stderr=sys.stderr)
sys.exit(0)
dist_dir = 'dist.macosx'
else:
assert False, 'Unsupported platform %s' % sys.platform
if dist_dir and len(dist_dir)>1 and isdir(dist_dir):
shutil.rmtree(dist_dir)
# "Developer ID Application" name for signing
macdeveloperid = None
# Windows paths
WIXPATH = r'C:\Program Files (x86)\WiX Toolset v3.11\bin'
SDKPATH = r'C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x86'
# OSX paths
SPARKLE = '/Library/Frameworks/Sparkle.framework'
# Patch py2app recipe enumerator to skip the sip recipe since it's too enthusiastic - we'll list additional Qt modules explicitly
if sys.platform=='darwin':
from py2app import recipes
import py2app.build_app
def iterRecipes(module=recipes):
for name in dir(module):
if name.startswith('_') or name=='sip':
continue
check = getattr(getattr(module, name), 'check', None)
if check is not None:
yield (name, check)
py2app.build_app.iterRecipes = iterRecipes
APP = 'EDMarketConnector.py'
APPCMD = 'EDMC.py'
SHORTVERSION = ''.join(VERSION.split('.')[:3])
PLUGINS = [ 'plugins/coriolis.py', 'plugins/eddb.py', 'plugins/eddn.py', 'plugins/edsm.py', 'plugins/edsy.py', 'plugins/inara.py' ]
if sys.platform=='darwin':
OPTIONS = { 'py2app':
{'dist_dir': dist_dir,
'optimize': 2,
'packages': [ 'requests', 'keyring.backends' ],
'frameworks': [ 'Sparkle.framework' ],
'excludes': [ 'distutils', 'iniparse', '_markerlib', 'PIL', 'pkg_resources', 'simplejson', 'unittest' ],
'iconfile': '%s.icns' % APPNAME,
'include_plugins': [('plugins', x) for x in PLUGINS],
'resources': [ requests.certs.where(), 'commodity.csv', 'rare_commodity.csv', 'snd_good.wav', 'snd_bad.wav', 'modules.p', 'ships.p', 'stations.p', 'systems.p'],
'semi_standalone': True,
'site_packages': False,
'plist': {
'CFBundleName': APPLONGNAME,
'CFBundleIdentifier': 'uk.org.marginal.%s' % APPNAME.lower(),
'CFBundleLocalizations': sorted(set([x[:-len('.lproj')] for x in os.listdir(join(SPARKLE, 'Resources')) if x.endswith('.lproj')]) | set([x[:-len('.strings')] for x in os.listdir('L10n') if x.endswith('.strings')])), # https://github.com/sparkle-project/Sparkle/issues/238
'CFBundleShortVersionString': VERSION,
'CFBundleVersion': VERSION,
'CFBundleURLTypes': [
{
'CFBundleTypeRole': 'Viewer',
'CFBundleURLName': 'uk.org.marginal.%s.URLScheme' % APPNAME.lower(),
'CFBundleURLSchemes': ['edmc'],
}
],
'LSMinimumSystemVersion': '10.10',
'NSAppleScriptEnabled': True,
'NSHumanReadableCopyright': u'© 2015-2019 Jonathan Harris, 2020 EDCD',
'SUEnableAutomaticChecks': True,
'SUShowReleaseNotes': True,
'SUAllowsAutomaticUpdates': False,
'SUFeedURL': update_feed,
'SUScheduledCheckInterval': update_interval,
},
'graph': True, # output dependency graph in dist
}
}
DATA_FILES = []
elif sys.platform=='win32':
OPTIONS = { 'py2exe':
{'dist_dir': dist_dir,
'optimize': 2,
'packages': [
'requests', 'keyring.backends',
'shutil', 'sqlite3', 'zipfile', # Included for plugins
],
'excludes': [ 'distutils', 'iniparse', '_markerlib', 'optparse', 'PIL', 'pkg_resources', 'simplejson', 'unittest' ],
}
}
DATA_FILES = [
('', [
requests.certs.where(),
'WinSparkle.dll',
'WinSparkle.pdb', # For debugging - don't include in package
'EUROCAPS.TTF',
'commodity.csv',
'rare_commodity.csv',
'snd_good.wav',
'snd_bad.wav',
'modules.p',
'ships.p',
'stations.p',
'systems.p',
'%s.VisualElementsManifest.xml' % APPNAME,
'%s.ico' % APPNAME
]),
('L10n', [join('L10n',x) for x in os.listdir('L10n') if x.endswith('.strings')]),
('plugins', PLUGINS),
]
setup(
name = APPLONGNAME,
version = VERSION,
app = [APP],
windows = [ {'dest_base': APPNAME,
'script': APP,
'icon_resources': [(0, '%s.ico' % APPNAME)],
'copyright': u'© 2015-2019 Jonathan Harris, 2020 EDCD',
'name': APPNAME, # WinSparkle
'company_name': 'EDCD', # WinSparkle
'other_resources': [(24, 1, open(APPNAME+'.manifest').read())],
} ],
console = [ {'dest_base': APPCMDNAME,
'script': APPCMD,
'copyright': u'© 2015-2019 Jonathan Harris, 2020 EDCD',
'name': APPNAME,
'company_name': 'EDCD',
} ],
data_files = DATA_FILES,
options = OPTIONS,
setup_requires = [sys.platform=='darwin' and 'py2app' or 'py2exe'],
)
if sys.platform == 'darwin':
if isdir('%s/%s.app' % (dist_dir, APPLONGNAME)): # from CFBundleName
os.rename('%s/%s.app' % (dist_dir, APPLONGNAME), '%s/%s.app' % (dist_dir, APPNAME))
# Generate OSX-style localization files
for x in os.listdir('L10n'):
if x.endswith('.strings'):
lang = x[:-len('.strings')]
path = '%s/%s.app/Contents/Resources/%s.lproj' % (dist_dir, APPNAME, lang)
os.mkdir(path)
codecs.open('%s/Localizable.strings' % path, 'w', 'utf-16').write(codecs.open('L10n/%s' % x, 'r', 'utf-8').read())
if macdeveloperid:
os.system('codesign --deep -v -s "Developer ID Application: %s" %s/%s.app' % (macdeveloperid, dist_dir, APPNAME))
# Make zip for distribution, preserving signature
PKG = '%s_mac_%s.zip' % (APPNAME, SHORTVERSION)
os.system('cd %s; ditto -ck --keepParent --sequesterRsrc %s.app ../%s; cd ..' % (dist_dir, APPNAME, PKG))
else:
os.system(r'"%s\candle.exe" -out %s\ %s.wxs' % (WIXPATH, dist_dir, APPNAME))
if exists('%s/%s.wixobj' % (dist_dir, APPNAME)):
PKG = '%s_win_%s.msi' % (APPNAME, SHORTVERSION)
os.system(r'"%s\light.exe" -sacl -spdb -sw1076 %s\%s.wixobj -out %s' % (WIXPATH, dist_dir, APPNAME, PKG))
# Seriously, this is how you make Windows Installer use the user's display language for its dialogs. What a crock.
# http://www.geektieguy.com/2010/03/13/create-a-multi-lingual-multi-language-msi-using-wix-and-custom-build-scripts
lcids = [int(x) for x in re.search(r'Languages\s*=\s*"(.+?)"', open('%s.wxs' % APPNAME).read()).group(1).split(',')]
assert lcids[0]==1033, 'Default language is %d, should be 1033 (en_US)' % lcids[0]
shutil.copyfile(PKG, join(gettempdir(), '%s_1033.msi' % APPNAME))
for lcid in lcids[1:]:
shutil.copyfile(join(gettempdir(), '%s_1033.msi' % APPNAME), join(gettempdir(), '%s_%d.msi' % (APPNAME, lcid)))
os.system(r'cscript /nologo "%s\WiLangId.vbs" %s\%s_%d.msi Product %d' % (SDKPATH, gettempdir(), APPNAME, lcid, lcid)) # Don't care about codepage because the displayed strings come from msiexec not our msi
os.system(r'"%s\MsiTran.Exe" -g %s\%s_1033.msi %s\%s_%d.msi %s\%d.mst' % (SDKPATH, gettempdir(), APPNAME, gettempdir(), APPNAME, lcid, gettempdir(), lcid))
os.system(r'cscript /nologo "%s\WiSubStg.vbs" %s %s\%d.mst %d' % (SDKPATH, PKG, gettempdir(), lcid, lcid))
# Make appcast entry
appcast = open('appcast_%s_%s.xml' % (sys.platform=='darwin' and 'mac' or 'win', SHORTVERSION), 'w')
appcast.write('''
\t\t<item>
\t\t\t<title>Release {0:.2f}</title>
\t\t\t<description>
\t\t\t\t<![CDATA[
<style>{6}</style>
<h2>Release {0:.2f}</h2>
<ul>
</ul>
\t\t\t\t]]>
\t\t\t</description>
\t\t\t<enclosure
\t\t\t\turl="https://github.com/EDCD/EDMarketConnector/releases/download/rel-{1}/{2}"
\t\t\t\tsparkle:os="{3}"
\t\t\t\tsparkle:version="{4}"
\t\t\t\tlength="{5}"
\t\t\t\ttype="application/octet-stream"
\t\t\t/>
\t\t</item>
'''.format(float(SHORTVERSION)/100,
SHORTVERSION,
PKG,
sys.platform=='win32' and 'windows"\n\t\t\t\tsparkle:installerArguments="/passive LAUNCH=yes' or 'macos',
VERSION,
os.stat(PKG).st_size,
sys.platform=='win32' and 'body { font-family:"Segoe UI","Tahoma"; font-size: 75%; } h2 { font-family:"Segoe UI","Tahoma"; font-size: 105%; }' or 'h2 { font-size: 105%; }'))