mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-04 17:41:18 +03:00
setup.py: isorted imports & de-caps config variables
* Test build exhibited no issues.
This commit is contained in:
parent
41cb4c24ce
commit
bc5f805b5a
136
setup.py
136
setup.py
@ -1,28 +1,25 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
This is a setup.py script generated by py2applet
|
Script to build to .exe and .msi package.
|
||||||
|
|
||||||
Usage:
|
.exe build is via py2exe on win32.
|
||||||
python setup.py py2app
|
.msi packaging utilises Windows SDK.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from distutils.core import setup
|
|
||||||
import codecs
|
import codecs
|
||||||
import os
|
import os
|
||||||
from os.path import exists, isdir, join
|
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
from distutils.core import setup
|
||||||
|
from os.path import exists, isdir, join
|
||||||
from tempfile import gettempdir
|
from tempfile import gettempdir
|
||||||
|
|
||||||
import semantic_version
|
import semantic_version
|
||||||
|
|
||||||
from config import appname as APPNAME, applongname as APPLONGNAME, appcmdname as APPCMDNAME, appversion as VERSION, copyright as COPYRIGHT
|
from config import appcmdname, applongname, appname, appversion, copyright, update_feed, update_interval
|
||||||
from config import update_feed, update_interval
|
|
||||||
|
|
||||||
if sys.version_info[0:2] != (3, 7):
|
|
||||||
raise AssertionError(f'Unexpected python version {sys.version}')
|
|
||||||
|
|
||||||
if sys.platform=='win32':
|
if sys.platform=='win32':
|
||||||
assert platform.architecture()[0]=='32bit', 'Assumes a Python built for 32bit'
|
assert platform.architecture()[0]=='32bit', 'Assumes a Python built for 32bit'
|
||||||
@ -34,8 +31,8 @@ else:
|
|||||||
assert False, 'Unsupported platform %s' % sys.platform
|
assert False, 'Unsupported platform %s' % sys.platform
|
||||||
|
|
||||||
# Split version, as py2exe wants the 'base' for version
|
# Split version, as py2exe wants the 'base' for version
|
||||||
semver = semantic_version.Version.coerce(VERSION)
|
semver = semantic_version.Version.coerce(appversion)
|
||||||
BASEVERSION = str(semver.truncate('patch'))
|
BASEappversion = str(semver.truncate('patch'))
|
||||||
|
|
||||||
if dist_dir and len(dist_dir)>1 and isdir(dist_dir):
|
if dist_dir and len(dist_dir)>1 and isdir(dist_dir):
|
||||||
shutil.rmtree(dist_dir)
|
shutil.rmtree(dist_dir)
|
||||||
@ -66,7 +63,7 @@ if sys.platform=='darwin':
|
|||||||
|
|
||||||
APP = 'EDMarketConnector.py'
|
APP = 'EDMarketConnector.py'
|
||||||
APPCMD = 'EDMC.py'
|
APPCMD = 'EDMC.py'
|
||||||
SHORTVERSION = ''.join(VERSION.split('.')[:3])
|
SHORTappversion = ''.join(appversion.split('.')[:3])
|
||||||
PLUGINS = [ 'plugins/coriolis.py', 'plugins/eddb.py', 'plugins/eddn.py', 'plugins/edsm.py', 'plugins/edsy.py', 'plugins/inara.py' ]
|
PLUGINS = [ 'plugins/coriolis.py', 'plugins/eddb.py', 'plugins/eddn.py', 'plugins/edsm.py', 'plugins/edsy.py', 'plugins/inara.py' ]
|
||||||
|
|
||||||
if sys.platform=='darwin':
|
if sys.platform=='darwin':
|
||||||
@ -83,26 +80,26 @@ if sys.platform=='darwin':
|
|||||||
],
|
],
|
||||||
'frameworks': [ 'Sparkle.framework' ],
|
'frameworks': [ 'Sparkle.framework' ],
|
||||||
'excludes': [ 'distutils', '_markerlib', 'PIL', 'pkg_resources', 'simplejson', 'unittest' ],
|
'excludes': [ 'distutils', '_markerlib', 'PIL', 'pkg_resources', 'simplejson', 'unittest' ],
|
||||||
'iconfile': '%s.icns' % APPNAME,
|
'iconfile': '%s.icns' % appname,
|
||||||
'include_plugins': [('plugins', x) for x in PLUGINS],
|
'include_plugins': [('plugins', x) for x in PLUGINS],
|
||||||
'resources': [ 'commodity.csv', 'rare_commodity.csv', 'snd_good.wav', 'snd_bad.wav', 'modules.p', 'ships.p', 'stations.p', 'systems.p'],
|
'resources': [ 'commodity.csv', 'rare_commodity.csv', 'snd_good.wav', 'snd_bad.wav', 'modules.p', 'ships.p', 'stations.p', 'systems.p'],
|
||||||
'site_packages': False,
|
'site_packages': False,
|
||||||
'plist': {
|
'plist': {
|
||||||
'CFBundleName': APPLONGNAME,
|
'CFBundleName': applongname,
|
||||||
'CFBundleIdentifier': 'uk.org.marginal.%s' % APPNAME.lower(),
|
'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
|
'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,
|
'CFBundleShortVersionString': appversion,
|
||||||
'CFBundleVersion': VERSION,
|
'CFBundleVersion': appversion,
|
||||||
'CFBundleURLTypes': [
|
'CFBundleURLTypes': [
|
||||||
{
|
{
|
||||||
'CFBundleTypeRole': 'Viewer',
|
'CFBundleTypeRole': 'Viewer',
|
||||||
'CFBundleURLName': 'uk.org.marginal.%s.URLScheme' % APPNAME.lower(),
|
'CFBundleURLName': 'uk.org.marginal.%s.URLScheme' % appname.lower(),
|
||||||
'CFBundleURLSchemes': ['edmc'],
|
'CFBundleURLSchemes': ['edmc'],
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'LSMinimumSystemVersion': '10.10',
|
'LSMinimumSystemVersion': '10.10',
|
||||||
'NSAppleScriptEnabled': True,
|
'NSAppleScriptEnabled': True,
|
||||||
'NSHumanReadableCopyright': COPYRIGHT,
|
'NSHumanReadableCopyright': copyright,
|
||||||
'SUEnableAutomaticChecks': True,
|
'SUEnableAutomaticChecks': True,
|
||||||
'SUShowReleaseNotes': True,
|
'SUShowReleaseNotes': True,
|
||||||
'SUAllowsAutomaticUpdates': False,
|
'SUAllowsAutomaticUpdates': False,
|
||||||
@ -145,8 +142,8 @@ elif sys.platform=='win32':
|
|||||||
'ships.p',
|
'ships.p',
|
||||||
'stations.p',
|
'stations.p',
|
||||||
'systems.p',
|
'systems.p',
|
||||||
'%s.VisualElementsManifest.xml' % APPNAME,
|
'%s.VisualElementsManifest.xml' % appname,
|
||||||
'%s.ico' % APPNAME,
|
'%s.ico' % appname,
|
||||||
'EDMarketConnector - TRACE.bat',
|
'EDMarketConnector - TRACE.bat',
|
||||||
'EDMarketConnector - localserver-auth.bat',
|
'EDMarketConnector - localserver-auth.bat',
|
||||||
]),
|
]),
|
||||||
@ -155,26 +152,26 @@ elif sys.platform=='win32':
|
|||||||
]
|
]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = APPLONGNAME,
|
name = applongname,
|
||||||
version = VERSION,
|
version = appversion,
|
||||||
windows = [ {'dest_base': APPNAME,
|
windows = [ {'dest_base': appname,
|
||||||
'script': APP,
|
'script': APP,
|
||||||
'icon_resources': [(0, '%s.ico' % APPNAME)],
|
'icon_resources': [(0, '%s.ico' % appname)],
|
||||||
'company_name': 'EDCD', # WinSparkle
|
'company_name': 'EDCD', # WinSparkle
|
||||||
'product_name': APPNAME, # WinSparkle
|
'product_name': appname, # WinSparkle
|
||||||
'version': BASEVERSION,
|
'version': BASEappversion,
|
||||||
'product_version': VERSION,
|
'product_version': appversion,
|
||||||
'copyright': COPYRIGHT,
|
'copyright': copyright,
|
||||||
'other_resources': [(24, 1, open(APPNAME+'.manifest').read())],
|
'other_resources': [(24, 1, open(appname+'.manifest').read())],
|
||||||
} ],
|
} ],
|
||||||
console = [ {'dest_base': APPCMDNAME,
|
console = [ {'dest_base': appcmdname,
|
||||||
'script': APPCMD,
|
'script': APPCMD,
|
||||||
'company_name': 'EDCD',
|
'company_name': 'EDCD',
|
||||||
'product_name': APPNAME,
|
'product_name': appname,
|
||||||
'version': BASEVERSION,
|
'version': BASEappversion,
|
||||||
'product_version': VERSION,
|
'product_version': appversion,
|
||||||
'copyright': COPYRIGHT,
|
'copyright': copyright,
|
||||||
'other_resources': [(24, 1, open(APPCMDNAME+'.manifest').read())],
|
'other_resources': [(24, 1, open(appcmdname+'.manifest').read())],
|
||||||
} ],
|
} ],
|
||||||
data_files = DATA_FILES,
|
data_files = DATA_FILES,
|
||||||
options = OPTIONS,
|
options = OPTIONS,
|
||||||
@ -182,42 +179,75 @@ setup(
|
|||||||
|
|
||||||
PKG = None
|
PKG = None
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
if isdir('%s/%s.app' % (dist_dir, APPLONGNAME)): # from CFBundleName
|
if isdir('%s/%s.app' % (dist_dir, applongname)): # from CFBundleName
|
||||||
os.rename('%s/%s.app' % (dist_dir, APPLONGNAME), '%s/%s.app' % (dist_dir, APPNAME))
|
os.rename('%s/%s.app' % (dist_dir, applongname), '%s/%s.app' % (dist_dir, appname))
|
||||||
|
|
||||||
# Generate OSX-style localization files
|
# Generate OSX-style localization files
|
||||||
for x in os.listdir('L10n'):
|
for x in os.listdir('L10n'):
|
||||||
if x.endswith('.strings'):
|
if x.endswith('.strings'):
|
||||||
lang = x[:-len('.strings')]
|
lang = x[:-len('.strings')]
|
||||||
path = '%s/%s.app/Contents/Resources/%s.lproj' % (dist_dir, APPNAME, lang)
|
path = '%s/%s.app/Contents/Resources/%s.lproj' % (dist_dir, appname, lang)
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
codecs.open('%s/Localizable.strings' % path, 'w', 'utf-16').write(codecs.open('L10n/%s' % x, 'r', 'utf-8').read())
|
codecs.open('%s/Localizable.strings' % path, 'w', 'utf-16').write(codecs.open('L10n/%s' % x, 'r', 'utf-8').read())
|
||||||
|
|
||||||
if macdeveloperid:
|
if macdeveloperid:
|
||||||
os.system('codesign --deep -v -s "Developer ID Application: %s" %s/%s.app' % (macdeveloperid, dist_dir, APPNAME))
|
os.system('codesign --deep -v -s "Developer ID Application: %s" %s/%s.app' % (macdeveloperid, dist_dir, appname))
|
||||||
# Make zip for distribution, preserving signature
|
# Make zip for distribution, preserving signature
|
||||||
PKG = '%s_mac_%s.zip' % (APPNAME, VERSION)
|
PKG = '%s_mac_%s.zip' % (appname, appversion)
|
||||||
os.system('cd %s; ditto -ck --keepParent --sequesterRsrc %s.app ../%s; cd ..' % (dist_dir, APPNAME, PKG))
|
os.system('cd %s; ditto -ck --keepParent --sequesterRsrc %s.app ../%s; cd ..' % (dist_dir, appname, PKG))
|
||||||
elif sys.platform == 'win32':
|
elif sys.platform == 'win32':
|
||||||
os.system(r'"%s\candle.exe" -out %s\ %s.wxs' % (WIXPATH, dist_dir, APPNAME))
|
os.system(r'"%s\candle.exe" -out %s\ %s.wxs' % (WIXPATH, dist_dir, appname))
|
||||||
if not exists('%s/%s.wixobj' % (dist_dir, APPNAME)):
|
if not exists('%s/%s.wixobj' % (dist_dir, appname)):
|
||||||
raise AssertionError('No %s/%s.wixobj: candle.exe failed?' % (dist_dir, APPNAME))
|
raise AssertionError('No %s/%s.wixobj: candle.exe failed?' % (dist_dir, appname))
|
||||||
|
|
||||||
PKG = '%s_win_%s.msi' % (APPNAME, VERSION)
|
PKG = '%s_win_%s.msi' % (appname, appversion)
|
||||||
import subprocess
|
import subprocess
|
||||||
os.system(r'"%s\light.exe" -sacl -spdb -sw1076 %s\%s.wixobj -out %s' % (WIXPATH, dist_dir, APPNAME, PKG))
|
os.system(r'"%s\light.exe" -sacl -spdb -sw1076 %s\%s.wixobj -out %s' % (WIXPATH, dist_dir, appname, PKG))
|
||||||
if not exists(PKG):
|
if not exists(PKG):
|
||||||
raise AssertionError('light.exe failed, no %s' % (PKG))
|
raise AssertionError('light.exe failed, no %s' % (PKG))
|
||||||
|
|
||||||
# Seriously, this is how you make Windows Installer use the user's display language for its dialogs. What a crock.
|
# 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
|
# 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(',')]
|
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]
|
assert lcids[0]==1033, 'Default language is %d, should be 1033 (en_US)' % lcids[0]
|
||||||
shutil.copyfile(PKG, join(gettempdir(), '%s_1033.msi' % APPNAME))
|
shutil.copyfile(PKG, join(gettempdir(), '%s_1033.msi' % appname))
|
||||||
for lcid in lcids[1:]:
|
for lcid in lcids[1:]:
|
||||||
shutil.copyfile(join(gettempdir(), '%s_1033.msi' % APPNAME), join(gettempdir(), '%s_%d.msi' % (APPNAME, lcid)))
|
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'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'"%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))
|
os.system(r'cscript /nologo "%s\WiSubStg.vbs" %s %s\%d.mst %d' % (SDKPATH, PKG, gettempdir(), lcid, lcid))
|
||||||
else:
|
else:
|
||||||
raise AssertionError('Unsupported platform')
|
raise AssertionError('Unsupported platform')
|
||||||
|
|
||||||
|
if not exists(PKG):
|
||||||
|
raise AssertionError('No %s found prior to appcast' % (PKG))
|
||||||
|
# Make appcast entry
|
||||||
|
appcast = open('appcast_%s_%s.xml' % (sys.platform=='darwin' and 'mac' or 'win', appversion), 'w')
|
||||||
|
appcast.write('''
|
||||||
|
\t\t<item>
|
||||||
|
\t\t\t<title>Release {appversion}</title>
|
||||||
|
\t\t\t<description>
|
||||||
|
\t\t\t\t<![CDATA[
|
||||||
|
<style>{STYLE}</style>
|
||||||
|
<h2>Release {appversion}</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-{appversion}/{PKG}"
|
||||||
|
\t\t\t\tsparkle:os="{OS}"
|
||||||
|
\t\t\t\tsparkle:version="{appversion}"
|
||||||
|
\t\t\t\tlength="{LENGTH}"
|
||||||
|
\t\t\t\ttype="application/octet-stream"
|
||||||
|
\t\t\t/>
|
||||||
|
\t\t</item>
|
||||||
|
'''.format(appversion=appversion,
|
||||||
|
STYLE='{}'.format(
|
||||||
|
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%; }'),
|
||||||
|
PKG=PKG,
|
||||||
|
OS=''.format(sys.platform=='win32' and 'windows"\n\t\t\t\tsparkle:installerArguments="/passive LAUNCH=yes' or 'macos'),
|
||||||
|
LENGTH=os.stat(PKG).st_size)
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user