1- import requests
21import hashlib
32import urllib
43import os
54import sys
65import subprocess
76import shutil
87import stat
8+
99from PIL import Image
10+ import requests
11+ import click
1012
11- JULIA_VERSION = (0 , 6 , 4 )
1213CHECKSUM_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"
1915ICON_SIZES = [16 , 32 , 48 , 64 , 96 , 128 , 256 ]
2016
21- JULIA_JUNK = [
22- "$PLUGINSDIR" ,
23- "Uninstall.exe" ,
24- ]
25-
2617TEMP_DIR = "tmp"
2718BUILD_DIR = "build"
2819SRC_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-
183144def 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-
220159def 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
235174def 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
268207def 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 ()
0 commit comments