File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -17,13 +17,22 @@ def get_version(path):
1717 # __version__ = "0.9"
1818 return line .split ('"' )[1 ]
1919
20+ def zipadd (archive , filename , newname ):
21+ '''Add filename to archive. `newname` is required. Otherwise
22+ zipfile may create unsafe entries, such as "../patch.py" '''
23+ import zipfile
24+ zf = zipfile .ZipFile (archive , 'a' , zipfile .ZIP_DEFLATED )
25+ zf .write (filename , newname )
2026
2127if not sys .argv [1 :]:
2228 sys .exit ("usage: pack.py <module.py>" )
2329
2430modpath = sys .argv [1 ]
25- modname = os .path .basename (modpath )
31+ modname = os .path .basename (modpath )[: - 3 ] # also strip extension
2632version = get_version (modpath )
2733packname = modname + "-" + version + ".zip"
2834print ("[*] Packing %s into %s" % (modpath , packname ))
35+ if os .path .exists (packname ):
36+ os .remove (packname )
37+ zipadd (packname , modpath , os .path .basename (modpath ))
2938
You can’t perform that action at this time.
0 commit comments