Skip to content

Commit

Permalink
Add create installer script for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsorby committed May 27, 2021
1 parent ae8e424 commit 9993721
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions res/win/create_installer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os
import sys
import subprocess
import tempfile


class ReplaceOnlyDict(dict):

def __missing__(self, key):
return '{' + key + '}'


def run_build(pyi_config, spec_file, **kwargs):
import PyInstaller.building.build_main
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)


def run_command(cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
for stdout_line in iter(p.stdout.readline, ''):
yield stdout_line

return_code = p.wait()
yield 'command returned with value: %s' % return_code


def run_makensis(repo_root_dir, app_version):
if not os.path.exists(os.path.join(repo_root_dir, 'package')):
os.mkdir(os.path.join(repo_root_dir, 'package'))

nsis_exe = os.path.join(os.environ['PROGRAMFILES(X86)'], 'NSIS', 'BIN', 'makensis.exe')
if os.path.exists(nsis_exe):
# Create NSIS script from template
with tempfile.NamedTemporaryFile(delete=False) as outputfile:
with open(os.path.join(repo_root_dir, 'res', 'win', 'nsis.nsi.template')) as f:
contents = f.read()

match_keys = ReplaceOnlyDict(map_client_version=app_version.__version__,
dist_dir=os.path.join(repo_root_dir, 'res', 'pyinstaller', 'dist', 'MAP-Client'),
win_res_dir=os.path.join(repo_root_dir, 'res', 'win'),
package_dir=os.path.join(repo_root_dir, 'package'))
formatted_contents = contents.format_map(match_keys)
outputfile.write(formatted_contents.encode())
outputfile.flush()
# os.chdir(os.path.join(repo_root_dir, 'res', 'win'))
for line in run_command([nsis_exe, outputfile.name]):
print(line.strip())

if os.path.isfile(outputfile.name):
os.remove(outputfile.name)


if __name__ == '__main__':
'''
Create a Windows application installer with NSIS and pyinsatller.
'''
here = os.path.realpath(os.path.dirname(__file__))

root_dir = os.path.realpath(os.path.join(here, '..', '..'))

src_dir = os.path.join(root_dir, 'src')
sys.path.append(src_dir)

from mapclient.settings import version as app_version

run_makensis(root_dir, app_version)

0 comments on commit 9993721

Please sign in to comment.