summaryrefslogtreecommitdiff
path: root/win/generate.py
blob: b5fc96fac478e31de5473419d9e7f20419210077 (plain)
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
"""
generate.py

Generate a NSI installer for a given provider.
"""

import sys
from string import Template

from provider import *


TEMPLATE = 'template.nsi'
INSTALLER = APP_NAME + '-installer.nsi'
VERSION = sys.argv[1]
if not VERSION:
    VERSION = "installer"

def get_files(which):
    files = "\n"
    if which == 'install':
        action = "File "
    elif which == 'uninstall':
        action = "Delete $INSTDIR\\"
    else:
        action = ""

    # TODO get relative path
    for item in open('payload/' + which).readlines():
        files += "  {action}{item}".format(
            action=action, item=item)
    return files


vardict = {
    'app_name': APP_NAME,
    'app_name_lower': APP_NAME.lower(),
    'url': URL,
    'extra_install_files': get_files('install'),
    'extra_uninstall_files': get_files('uninstall'),
    'version': VERSION
}


template = Template(open(TEMPLATE).read())
with open(INSTALLER, 'w') as output:
    output.write(template.safe_substitute(vardict))

print("[+] NSIS installer script written to {path}".format(path=INSTALLER))