1+ # -*- coding: utf-8 -*-
12from __future__ import with_statement
2- import os , sys , shutil , zipfile
3+ import os , sys , shutil , zipfile , platform
34from contextlib import closing
45from zipfile import ZipFile , ZIP_DEFLATED
5- import os
6-
7- def zipdir (basedir , archivename ):
8- assert os .path .isdir (basedir )
9- with closing (ZipFile (archivename , "w" , ZIP_DEFLATED )) as z :
10- for root , dirs , files in os .walk (basedir ):
11- #NOTE: ignore empty directories
12- for fn in files :
13- absfn = os .path .join (root , fn )
14- zfn = absfn [len (basedir )+ len (os .sep ):]
15- z .write (absfn , zfn )
16- ## Update this for each new release ##
17-
186
7+ ## Update odmtools.meta.data whenever creating a release
8+ from odmtools .meta import data
199
20-
21- ##
2210BASE_DIR = os .path .dirname (os .path .realpath (__file__ ))
23- WIN_DIR = os .path .join (BASE_DIR , "Windows" )
24- MAC_DIR = os .path .join (BASE_DIR , "Mac" )
11+ SETUP_DIR = os .path .join (BASE_DIR , 'setup' )
12+ DIST_DIR = os .path .join (SETUP_DIR , 'Dist/' )
13+ WIN_DIR = os .path .join (SETUP_DIR , "Windows" )
14+ MAC_DIR = os .path .join (SETUP_DIR , "Mac" )
2515
2616MAC_WORK_DIR = os .path .join (MAC_DIR , "Temp" )
2717WORK_DIR = os .path .join (WIN_DIR , "Temp" )
2818
29- ICON_DIR = os .path .join (".." , 'odmtools' , 'common' , "icons" )
19+ ICON_DIR = os .path .join ('odmtools' , 'common' , "icons" )
3020WIN_ICON_FILE = os .path .join (ICON_DIR , "ODMTools.ico" )
3121MAC_ICON_FILE = os .path .join (ICON_DIR , "ODMTools.icns" )
3222
33- EXE_DIR = os .path .join (WIN_DIR , "ODMTools" )
3423APP_DIR = os .path .join (MAC_DIR , "ODMTools.app" )
3524# Location of Windows files
36- APP_FILE = os .path .join (".." , "ODMTools.py" )
25+ APP_FILE = os .path .join (BASE_DIR , "ODMTools.py" )
26+ MAKE_FILE = os .path .realpath (__file__ )
3727VERSION_FILE = os .path .join (BASE_DIR , "version.txt" )
3828
3929# Location of Innosetup Installer
@@ -42,41 +32,97 @@ def zipdir(basedir, archivename):
4232ICE_SCRIPT = os .path .join (MAC_DIR , "ODMTools.packproj" )
4333ICE_EXECUTABLE = 'freeze'
4434
45- print (BASE_DIR )
46-
4735def check_if_dirs_exist ():
4836 try :
49-
5037 if sys .platform == 'win32' :
5138 print "Trying to open WIN_DIR: " ,
52- assert os .path .exists (WIN_DIR )
39+ if not os .path .exists (WIN_DIR ):
40+ os .mkdir (WIN_DIR )
41+ print "Created: " , WIN_DIR
5342 print "Success"
43+
44+ print "Trying to confirm that INNO_SCRIPT exists: " ,
45+ assert os .path .exists (INNO_SCRIPT )
46+ print "Success: " , INNO_SCRIPT
5447 elif sys .platform == "darwin" :
5548 print "Trying to open MAC_DIR: "
5649 assert os .path .exists (MAC_DIR )
5750 print "Success"
5851
5952 print "Trying to open WORK_DIR: " ,
60- assert os .path .exists (WORK_DIR )
53+ if not os .path .exists (WORK_DIR ):
54+ print "Failed... Trying to create the folder..." ,
55+ os .mkdir (WORK_DIR )
56+ print "Created: " , WORK_DIR
6157 print "Success"
6258
63- print "Trying to open ICON_DIR: " ,
64- assert os .path .exists (ICON_DIR )
59+
60+ print "Trying to open DIST_DIR: " ,
61+ if not os .path .exists (DIST_DIR ):
62+ print "Failed... Trying to create the folder..." ,
63+ os .mkdir (DIST_DIR )
64+ print "Created: " , DIST_DIR
6565 print "Success"
6666
67- print "Trying to open EXE_DIR : " ,
68- assert os .path .exists (EXE_DIR )
67+ print "Trying to open ICON_DIR : " ,
68+ assert os .path .exists (ICON_DIR )
6969 print "Success"
7070
7171 except Exception as e :
7272 print e
7373
74- def delete_old_out_dir ():
75- if os .path .exists (EXE_DIR ):
76- shutil .rmtree (EXE_DIR )
74+ def zipdir (basedir , archivename ):
75+ assert os .path .isdir (basedir )
76+ with closing (ZipFile (archivename , "w" , ZIP_DEFLATED )) as z :
77+ for root , dirs , files in os .walk (basedir ):
78+ #NOTE: ignore empty directories
79+ for fn in files :
80+ absfn = os .path .join (root , fn )
81+ zfn = absfn [len (basedir )+ len (os .sep ):]
82+ z .write (absfn , zfn )
83+ def printInfo ():
84+ print "============================================================="
85+ print "= ODMTools Installer "
86+ print "= Be sure to update odmtools/meta/data with every release "
87+ print "= Building release: {version}" .format (version = data .version ),
88+ print "\n = Platform: {platform}, {architecture}" .format (platform = sys .platform , architecture = platform .architecture ()), "\n ="
89+ print "============================================================="
90+ print "Environment Variables: "
91+ print ("APP_FILE: " , APP_FILE )
92+ print ("MAKE_FILE: " , MAKE_FILE )
93+ print ("BASE_DIR: " , BASE_DIR )
94+ print ("SETUP_DIR: " , SETUP_DIR )
95+ print ("DIST_DIR: " , DIST_DIR )
96+
97+ ## Windows Specific Files/Directories
98+ print ("WIN_DIR: " , WIN_DIR )
99+ print ("WIN_ICON_FILE: " , WIN_ICON_FILE )
100+ print ("WORK_DIR: " , WORK_DIR )
101+ print ("INNO_SCRIPT: " , INNO_SCRIPT )
102+ print ("INNO_EXECUTABLE: " , INNO_EXECUTABLE )
103+
104+ ## OSX Specific Files/Directories
105+ print ("MAC_DIR: " , MAC_DIR )
106+ print ("MAC_ICON_FILE: " , MAC_ICON_FILE )
107+ print ("MAC_WORK_DIR: " , MAC_WORK_DIR )
108+
109+ print "============================================================="
110+ print "Checking if the required directories exist"
111+
112+ check_if_dirs_exist ()
77113
78- if os .path .exists (WORK_DIR ):
79- shutil .rmtree (WORK_DIR )
114+ def delete_old_out_dir ():
115+ loc_exists = os .path .exists (DIST_DIR )
116+ isFile = os .path .isfile (DIST_DIR )
117+ isDir = os .path .isdir (DIST_DIR )
118+ if loc_exists and isFile :
119+ print "Removing file DIST_DIR"
120+ os .remove (DIST_DIR )
121+ elif loc_exists and isDir :
122+ print "Removing directory DIST_DIR"
123+ shutil .rmtree (DIST_DIR )
124+ else :
125+ print "Nothing to remove"
80126
81127def run_pyinstaller ():
82128 try :
@@ -119,33 +165,50 @@ def mac_pyinstaller():
119165 print (e )
120166 return False
121167
168+ def move_to_dist (filename ):
169+ assert filename
170+
171+ if not os .path .isdir (DIST_DIR ):
172+ os .mkdir (DIST_DIR )
173+
174+ print "Moving {filename} to {dist}" .format (filename = os .path .abspath (filename ), dist = DIST_DIR ),
175+ try :
176+ shutil .move (os .path .abspath (filename ), DIST_DIR )
177+ print "Success"
178+ except shutil .Error as e :
179+ print (e )
180+
122181
123182def run_inno ():
124183 os .system (INNO_EXECUTABLE + " " + INNO_SCRIPT )
125184
126185def run_no_installer ():
127186 # pass
128- zipdir (os .path .join ('..' , 'odmtools' ), "Windows_Test_zip.zip" )
187+ filename = "{app}_{version}_{os}_{arch}_{type}.zip" .format (app = data .app_name ,
188+ version = data .version , os = sys .platform , arch = 'x86_64' , type = "No_Install" )
189+
190+ zipdir (os .path .join ('odmtools' ), filename )
191+ move_to_dist (filename )
129192
130- # zf = zipfile.ZipFile('')
131193
132194def run_iceberg ():
133195 os .system (ICE_EXECUTABLE + " " + ICE_SCRIPT )
134196
135-
136197def main ():
137- # delete_old_out_dir()
138- # check_if_dirs_exist ()
198+ delete_old_out_dir ()
199+ printInfo ()
139200
140201 if sys .platform == 'win32' :
141202 print "Creating Windows Executable..."
142203 if (run_pyinstaller ()):
143204 run_inno ()
144205
145- if sys .platform == 'darwin' :
206+ elif sys .platform == 'darwin' :
146207 if (mac_pyinstaller ()):
147208 run_iceberg ()
148- else :
209+
210+ elif sys .platform == 'linux2' :
211+ ## Testing, not officially supported
149212 run_no_installer ()
150213
151214
0 commit comments