@@ -59,46 +59,48 @@ def make_tarball (base_name, base_dir, compress="gzip",
5959
6060def make_zipfile (base_name , base_dir , verbose = 0 , dry_run = 0 ):
6161 """Create a zip file from all the files under 'base_dir'. The output
62- zip file will be named 'base_dir' + ".zip". Uses either the InfoZIP
63- "zip" utility (if installed and found on the default search path) or
64- the "zipfile" Python module (if available). If neither tool is
65- available, raises DistutilsExecError. Returns the name of the output
66- zip file.
62+ zip file will be named 'base_dir' + ".zip". Uses either the "zipfile"
63+ Python module (if available) or the InfoZIP "zip" utility (if installed
64+ and found on the default search path). If neither tool is available,
65+ raises DistutilsExecError. Returns the name of the output zip file.
6766 """
68- # This initially assumed the Unix 'zip' utility -- but
69- # apparently InfoZIP's zip.exe works the same under Windows, so
70- # no changes needed!
71-
67+ try :
68+ import zipfile
69+ except ImportError :
70+ zipfile = None
71+
7272 zip_filename = base_name + ".zip"
7373 mkpath (os .path .dirname (zip_filename ), dry_run = dry_run )
74- try :
75- spawn (["zip" , "-rq" , zip_filename , base_dir ],
76- dry_run = dry_run )
77- except DistutilsExecError :
78-
79- # XXX really should distinguish between "couldn't find
80- # external 'zip' command" and "zip failed" -- shouldn't try
81- # again in the latter case. (I think fixing this will
82- # require some cooperation from the spawn module -- perhaps
83- # a utility function to search the path, so we can fallback
84- # on zipfile.py without the failed spawn.)
74+
75+ # If zipfile module is not available, try spawning an external
76+ # 'zip' command.
77+ if zipfile is None :
78+ if verbose :
79+ zipoptions = "-r"
80+ else :
81+ zipoptions = "-rq"
82+
8583 try :
86- import zipfile
87- except ImportError :
84+ spawn (["zip" , zipoptions , zip_filename , base_dir ],
85+ dry_run = dry_run )
86+ except DistutilsExecError :
87+ # XXX really should distinguish between "couldn't find
88+ # external 'zip' command" and "zip failed".
8889 raise DistutilsExecError , \
89- ("unable to create zip file '%s': " +
90- "could neither find a standalone zip utility nor " +
91- "import the 'zipfile' module " ) % zip_filename
90+ ("unable to create zip file '%s': "
91+ "could neither import the 'zipfile' module nor "
92+ "find a standalone zip utility " ) % zip_filename
9293
93-
94- log .info ("creating '%s' and adding '%s' to it" ,
94+ else :
95+ log .info ("creating '%s' and adding '%s' to it" ,
9596 zip_filename , base_dir )
96-
97+
9798 def visit (z , dirname , names ):
9899 for name in names :
99100 path = os .path .normpath (os .path .join (dirname , name ))
100101 if os .path .isfile (path ):
101102 z .write (path , path )
103+ log .info ("adding '%s'" % path )
102104
103105 if not dry_run :
104106 z = zipfile .ZipFile (zip_filename , "w" ,
0 commit comments