Skip to content

Commit 6d6af8e

Browse files
techtoniktechtonik
authored andcommitted
other/pack.py: Script for packing patch.py into executable .zip
0 parents commit 6d6af8e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pack.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
"""
3+
Wrap Python module into executable .zip file
4+
5+
Public domain work by:
6+
anatoly techtonik <techtonik@gmail.com>
7+
"""
8+
import os
9+
import sys
10+
11+
def get_version(path):
12+
'''Read version info from a file without importing it'''
13+
for line in open(path, 'rb'):
14+
# Decode to unicode for PY2/PY3 in a fail-safe way
15+
line = line.decode('cp437')
16+
if '__version__' in line:
17+
# __version__ = "0.9"
18+
return line.split('"')[1]
19+
20+
21+
if not sys.argv[1:]:
22+
sys.exit("usage: pack.py <module.py>")
23+
24+
modpath = sys.argv[1]
25+
modname = os.path.basename(modpath)
26+
version = get_version(modpath)
27+
packname = modname + "-" + version + ".zip"
28+
print("[*] Packing %s into %s" % (modpath, packname))
29+

0 commit comments

Comments
 (0)