@@ -5,10 +5,12 @@ import string
55import os
66import subprocess
77import plistlib
8+ import tempfile
9+ import shutil
810
911
1012quickpkg_version = '0.0'
11- supported_extensions = ['dmg' , 'app' ]
13+ supported_extensions = ['dmg' , 'app' , 'zip' ]
1214
1315# quickpkg
1416
@@ -180,14 +182,39 @@ if __name__ == "__main__":
180182
181183 app_path = foundapps [0 ]
182184
185+ # if item is zip, unzip to tmp location and find useful contents
186+ if item_extension == 'zip' :
187+ tmp_path = tempfile .mkdtemp ()
188+ unzip_cmd = ["/usr/bin/unzip" , "-d" , tmp_path , item_path ]
189+ result = cmdexec (unzip_cmd )
190+ if result ["return_code" ] != 0 :
191+ print "An error occured while unzipping:"
192+ print "%d, %s" % (result ["return_code" ], result ["stderr" ])
193+ exit (1 )
194+ foundapps = finditemswithextension (tmp_path , 'app' )
195+ if len (foundapps ) == 0 :
196+ print "Could not find an application!"
197+ shutil .rmtree (tmp_path )
198+ exit (1 )
199+ elif len (foundapps ) > 1 :
200+ print "Found too many Applications! Can't decide!"
201+ print foundapps
202+ shutil .rmtree (tmp_path )
203+ exit (1 )
204+
205+ app_path = foundapps [0 ]
206+
183207 logger ("Found application: %s" % app_path , 1 )
184208
185209 # extract version and other metadata
186210 (app_name , app_identifier , app_version ) = appNameAndVersion (app_path )
187211
188212 logger ("Name: %s, ID: %s, Version: %s" % (app_name , app_identifier , app_version ))
189213
214+ # TODO: get name syntax from prefs or parameter
190215 pkg_name = "{name}-{version}.pkg" .format (name = app_name , version = app_version , identifier = app_identifier )
216+ pkg_name = pkgname .replace (' ' , '' ) # remove spaces
217+ # run pkgutil to build result
191218
192219 pkgcmd = ["/usr/bin/pkgbuild" ,
193220 "--component" , app_path ,
@@ -197,11 +224,12 @@ if __name__ == "__main__":
197224 pkg_name ]
198225 result = cmdexec (pkgcmd )
199226
200- print result ["stdout" ]
227+ logger ( result ["stdout" ], 1 )
201228 if result ["return_code" ] != 0 :
202- print "Error Code: " + result ["return_code" ]
203- print result ["stderr" ]
229+ logger ("Error Code: " + result ["return_code" ], 1 )
230+ logger (result ["stderr" ], 1 )
231+ else :
232+ print pkg_name
204233
205- # run pkgutil to build result
206234 detachpaths (dmgvolumepaths )
207235
0 commit comments