Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Commit

Permalink
Merge branch 'stable' of github.com:jflesch/paperwork into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
jflesch committed Aug 25, 2017
2 parents f75a46e + 63a36ed commit e734733
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions nsis/gen_installer_nsi.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
import sys

from paperwork_backend.util import find_language


DOWNLOAD_URI = "https://github.com/openpaperwork/paperwork/releases/download/${PRODUCT_SHORT_VERSION}/paperwork_${PRODUCT_VERSION}_win64.zip"

ALL_LANGUAGES = [
"eng", # English (always first)

"afr",
"sqi", # Albanian
"amh",
Expand Down Expand Up @@ -105,8 +109,8 @@
"vie",
"cym", # Welsh
"yid",
]

]
UNKNOWN_LANGUAGE = {
'download_section': """
Section /o "{long}" SEC_{upper}
Expand Down Expand Up @@ -178,14 +182,16 @@
},
}

VERSION = """!define PRODUCT_VERSION "{version}\""""
VERSION = """!define PRODUCT_VERSION "{version}\"
!define PRODUCT_SHORT_VERSION "{short_version}\""""

HEADER = """
!define PRODUCT_NAME "Paperwork"
!define PRODUCT_PUBLISHER "Openpaper.work"
!define PRODUCT_WEB_SITE "https://openpaper.work"
!define PRODUCT_UNINST_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_DOWNLOAD_URI "{download_uri}"
!addplugindir ".\dll"
Expand Down Expand Up @@ -243,7 +249,7 @@
SetOutPath "$INSTDIR"
SetOverwrite on
inetc::get "https://github.com/openpaperwork/paperwork/releases/download/${PRODUCT_VERSION}/paperwork_${PRODUCT_VERSION}_win64.zip" "$PLUGINSDIR\\paperwork.zip" /END
inetc::get "${PRODUCT_DOWNLOAD_URI}" "$PLUGINSDIR\\paperwork.zip" /END
Pop $0
StrCmp $0 "OK" +3
MessageBox MB_OK "Download failed"
Expand All @@ -266,7 +272,7 @@
; CreateShortCut "$DESKTOP.lnk" "$INSTDIR\\paperwork.exe"
; CreateShortCut "$STARTMENU.lnk" "$INSTDIR\\paperwork.exe"
SetOutPath "$INSTDIR\\Tesseract"
CreateDirectory "$INSTDIR\\Tesseract"
nsisunz::UnzipToLog "$PLUGINSDIR\\tesseract.zip" "$INSTDIR"
Expand Down Expand Up @@ -392,7 +398,7 @@ def get_lang_infos(lang_name):
suffix = "" if len(lang) <= 1 else lang[1]

lang = find_language(lang_name)

if not suffix:
long_name = lang.name
else:
Expand All @@ -406,16 +412,23 @@ def get_lang_infos(lang_name):


def main(args):
if (len(args) < 3):
print ("Syntax:")
print ("\t{} <version> <output file>".format(args[0]))
if (len(args) < 2):
print ("ARGS: {} <version> [<download URI>]".format(args[0]))
return

version = args[1]
output_file = args[2]
download_uri = DOWNLOAD_URI

if len(args) == 3:
version = short_version = args[1]
download_uri = args[2]
else:
version = args[1]
m = re.match("([\d\.]+)", version) # match everything but the suffix
short_version = m.string[m.start():m.end()]
download_uri = DOWNLOAD_URI

with open(output_file, "w") as out_fd:
out_fd.write(VERSION.format(version=version))
with open("out.nsi", "w") as out_fd:
out_fd.write(VERSION.format(version=version, short_version=short_version, download_uri=download_uri))
out_fd.write(HEADER)


Expand All @@ -431,12 +444,12 @@ def main(args):
txt = txt.format(**get_lang_infos(lang_name))
out_fd.write(txt)
out_fd.write("""
SectionGroupEnd
SectionGroupEnd
""")


out_fd.write(MIDDLE)

for lang_name in ALL_LANGUAGES:
print ("Adding strings section {}".format(lang_name))
lang = UNKNOWN_LANGUAGE
Expand All @@ -445,7 +458,7 @@ def main(args):
txt = lang['lang_strings']
txt = txt.format(**get_lang_infos(lang_name))
out_fd.write(txt)

out_fd.write("""
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SEC_PAPERWORK} $(DESC_SEC_PAPERWORK)
Expand All @@ -462,8 +475,7 @@ def main(args):
""")

out_fd.write(FOOTER)

print ("{} generated".format(output_file))
print ("out.nsi written")

if __name__ == "__main__":
main(sys.argv)
main(sys.argv)

0 comments on commit e734733

Please sign in to comment.