Skip to content

Commit 93775ac

Browse files
committed
Removed most Ahorn and Julia specific code. Started working on click interface.
1 parent 8b6a925 commit 93775ac

2 files changed

Lines changed: 34 additions & 94 deletions

File tree

syrup.py

Lines changed: 21 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
1-
import requests
21
import hashlib
32
import urllib
43
import os
54
import sys
65
import subprocess
76
import shutil
87
import stat
8+
99
from PIL import Image
10+
import requests
11+
import click
1012

11-
JULIA_VERSION = (0, 6, 4)
1213
CHECKSUM_TYPE = "sha256"
1314

14-
JULIA_BIN_FILENAME = "julia-{v[0]}.{v[1]}.{v[2]}-win64.exe".format(v=JULIA_VERSION)
15-
JULIA_BIN = "https://julialang-s3.julialang.org/bin/winnt/x64/{v[0]}.{v[1]}/{file}".format(v=JULIA_VERSION, file=JULIA_BIN_FILENAME)
16-
JULIA_CHECKSUMS = "https://julialang-s3.julialang.org/bin/checksums/julia-{v[0]}.{v[1]}.{v[2]}.{checksum}".format(v=JULIA_VERSION, checksum=CHECKSUM_TYPE)
17-
18-
LOGO_FILE = "logo-1024-a.png"
1915
ICON_SIZES = [16, 32, 48, 64, 96, 128, 256]
2016

21-
JULIA_JUNK = [
22-
"$PLUGINSDIR",
23-
"Uninstall.exe",
24-
]
25-
2617
TEMP_DIR = "tmp"
2718
BUILD_DIR = "build"
2819
SRC_DIR = "src"
@@ -150,40 +141,10 @@ def checksum_file(path, checksum_type=CHECKSUM_TYPE):
150141
data = fh.read(1_048_576)
151142
return cs.hexdigest()
152143

153-
154-
def downloadJulia():
155-
outfn = os.path.join(TEMP_DIR, JULIA_BIN_FILENAME)
156-
csfile = "{}.{}".format(outfn, CHECKSUM_TYPE)
157-
158-
if os.path.exists(csfile) and os.path.exists(outfn):
159-
cs = parse_checksum_file(open(csfile).read()).get(JULIA_BIN_FILENAME)
160-
if cs == checksum_file(outfn):
161-
print("Cached Julia installer ok.")
162-
return outfn
163-
164-
checksums = parse_checksum_file(requests.get(JULIA_CHECKSUMS).text)
165-
os.makedirs(os.path.dirname(outfn), exist_ok=True)
166-
167-
print("Downloading Julia installer file...")
168-
fn, dlcs = download_file(JULIA_BIN, outfn)
169-
170-
cs = checksums.get(os.path.basename(fn))
171-
172-
assert dlcs == cs, "Checksum verification on download `{}` failed. `{}` != `{}`".format(JULIA_BIN, dlcs, cs)
173-
174-
with open(csfile, "w", encoding="utf-8") as fh:
175-
fh.write(cs)
176-
fh.write(" ")
177-
fh.write(os.path.basename(fn))
178-
fh.write("\n")
179-
print("Download of `{}` completed and verified.".format(fn))
180-
181-
return outfn
182-
183144
def cleanBuild():
184145
print("Cleaning build directory...")
185146
if os.path.exists(BUILD_DIR):
186-
for path, dirs, files in os.walk(BUILD_DIR):
147+
for path, _dirs, files in os.walk(BUILD_DIR):
187148
for name in files:
188149
pathname = os.path.join(path, name)
189150
# Silly git readonly files.
@@ -195,28 +156,6 @@ def cleanArtifacts():
195156
print("Cleaning artifact directory...")
196157
shutil.rmtree("artifacts", onerror=lambda func, path, exec_info: print("WARNING: Failed to delete ", path, exec_info))
197158

198-
def extractJulia():
199-
print("Extracting Julia...")
200-
jbin1 = downloadJulia()
201-
jbin2 = p7zip_extract_file(jbin1, "julia-installer.exe", target=TEMP_DIR)
202-
203-
jbuild = os.path.join(BUILD_DIR, "julia")
204-
205-
if os.path.exists(jbuild):
206-
shutil.rmtree(jbuild)
207-
208-
p7zip_extract(jbin2, jbuild)
209-
210-
for name in JULIA_JUNK:
211-
p = os.path.join(jbuild, name)
212-
213-
if os.path.isdir(p):
214-
shutil.rmtree(p)
215-
elif os.path.exists(p):
216-
os.remove(p)
217-
218-
print(jbin2)
219-
220159
def copySrc():
221160
print("Copying src/*...")
222161
for name in os.listdir(SRC_DIR):
@@ -226,20 +165,20 @@ def copySrc():
226165
else:
227166
shutil.copy(src, BUILD_DIR)
228167

229-
def makeIco():
168+
def makeIco(logo):
230169
"Generates .ico file from .png"
231170
print("Generating .ico file...")
232-
im = Image.open(LOGO_FILE)
171+
im = Image.open(logo)
233172
im.save(os.path.join(BUILD_DIR, "ahorn.ico"), sizes=[(x,x) for x in ICON_SIZES])
234173

235174
def compileNSISTemplate():
236175
"Generates NSIS script from jinja2 template"
237176
print("Generating NSIS script...")
238177
import jinja2
239-
loader = jinja2.FileSystemLoader('templates')
240-
env = jinja2.Environment(loader=loader, autoescape=False)
178+
loader = jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates'))
179+
env = jinja2.Environment(loader=loader, autoescape=False, undefined=jinja2.StrictUndefined)
241180

242-
template = env.get_template("Ahorn.nsi.j2")
181+
template = env.get_template("generic.nsi.j2")
243182

244183
install_files = []
245184
install_dirs = []
@@ -262,7 +201,7 @@ def compileNSISTemplate():
262201
'outfile': os.path.join(ARTIFACT_DIR, "setup-${APPNAME}-${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.exe"),
263202
}
264203

265-
with open("Ahorn.nsi", "w") as fh:
204+
with open("generic.nsi", "w") as fh: # TODO: Temp file name.
266205
template.stream(**template_variables).dump(fh)
267206

268207
def NSISBuildInstaller():
@@ -271,18 +210,19 @@ def NSISBuildInstaller():
271210
os.makedirs(ARTIFACT_DIR, exist_ok=True)
272211

273212
# http://nsis.sourceforge.net/Docs/Chapter3.html#usage
274-
print(cmd([TOOLS_NSIS, "/INPUTCHARSET", "UTF8", "/P3", "/V3", "Ahorn.nsi"], stdout=sys.stdout, stderr=sys.stderr, encoding="utf8"))
213+
print(cmd([TOOLS_NSIS, "/INPUTCHARSET", "UTF8", "/P3", "/V3", "generic.nsi"], stdout=sys.stdout, stderr=sys.stderr, encoding="utf8"))
275214

276-
def setupAhorn():
277-
print("Running Ahorn setup...")
278-
return cmd([os.path.join(BUILD_DIR, "julia.bat"), "setup-ahorn.jl"], stdout=None, stderr=None)
279215

280-
if __name__ == "__main__":
216+
@click.command()
217+
def main():
281218
print(cleanArtifacts())
282219
print(cleanBuild())
283-
print(extractJulia())
284-
print(copySrc())
285-
print(makeIco())
286-
print(setupAhorn())
220+
#print(copySrc())
221+
#print(makeIco("fixme.png"))
222+
287223
print(compileNSISTemplate())
288-
print(NSISBuildInstaller())
224+
225+
print(NSISBuildInstaller())
226+
227+
if __name__ == "__main__":
228+
main()

templates/generic.nsi.j2

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
# If you change the names "app.exe", "logo.ico", or "license.rtf" you should do a search and replace - they
88
# show up in a few places.
99
# All the other settings can be tweaked by editing the !defines at the top of this script
10-
!define APPNAME "Ahorn"
11-
!define COMPANYNAME "CelestialCartographers"
12-
!define DESCRIPTION "Visual Map Maker and Level Editor for the game Celeste"
10+
!define APPNAME "{{ app }}"
11+
!define COMPANYNAME "{{ company }}"
12+
!define DESCRIPTION "{{ description }}"
1313
# These three must be integers
14-
!define VERSIONMAJOR 0
15-
!define VERSIONMINOR 0
16-
!define VERSIONBUILD 3
14+
!define VERSIONMAJOR {{ version.major }}
15+
!define VERSIONMINOR {{ version.minor }}
16+
!define VERSIONBUILD {{ version.build }}
1717
# These will be displayed by the "Click here for support information" link in "Add/Remove Programs"
1818
# It is possible to use "mailto:" links in here to open the email client
19-
!define HELPURL "https://github.com/CelestialCartographers/Ahorn/issues" # "Support Information" link
20-
!define UPDATEURL "https://github.com/CelestialCartographers/Ahorn/releases" # "Product Updates" link
21-
!define ABOUTURL "https://github.com/CelestialCartographers/Ahorn" # "Publisher" link
19+
!define HELPURL "{{ help_url }}" # "Support Information" link
20+
!define UPDATEURL "{{ update_url }}" # "Product Updates" link
21+
!define ABOUTURL "{{ website_url }}" # "Publisher" link
2222
# This is the size (in kB) of all the files copied into "Program Files"
23-
!define INSTALLSIZE 7233
23+
!define INSTALLSIZE {{ size }}
2424

2525
#RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on)
2626
RequestExecutionLevel user
@@ -32,7 +32,7 @@ InstallDir "$LOCALAPPDATA\${COMPANYNAME}\${APPNAME}"
3232
LicenseData "license.rtf"
3333
# This will be in the installer/uninstaller's title bar
3434
Name "${COMPANYNAME} - ${APPNAME}"
35-
Icon "build/ahorn.ico"
35+
Icon "{{ icon }}"
3636
OutFile "{{ outfile }}"
3737

3838
!include LogicLib.nsh
@@ -73,15 +73,15 @@ section "install"
7373

7474
# Start Menu
7575
createDirectory "$SMPROGRAMS\${COMPANYNAME}"
76-
createShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk" "$INSTDIR\ahorn.bat" "" "$INSTDIR\ahorn.ico"
76+
createShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk" "$INSTDIR\{{ executable }}" "" "$INSTDIR\application.ico"
7777

7878

7979
# Registry information for add/remove programs
8080
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
8181
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
8282
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
8383
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
84-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\ahorn.ico$\""
84+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\application.ico$\""
8585
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "Publisher" "$\"${COMPANYNAME}$\""
8686
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "HelpLink" "$\"${HELPURL}$\""
8787
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\""

0 commit comments

Comments
 (0)