Skip to content

Commit 7d4bf7c

Browse files
techtoniktechtonik
authored andcommitted
other/pack: Create .zip archive with patch.py
1 parent 6d6af8e commit 7d4bf7c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pack.py

100644100755
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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

2127
if not sys.argv[1:]:
2228
sys.exit("usage: pack.py <module.py>")
2329

2430
modpath = sys.argv[1]
25-
modname = os.path.basename(modpath)
31+
modname = os.path.basename(modpath)[:-3] # also strip extension
2632
version = get_version(modpath)
2733
packname = modname + "-" + version + ".zip"
2834
print("[*] 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

0 commit comments

Comments
 (0)