-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create installer script for Windows.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |