-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselfextract.py
57 lines (48 loc) · 1.26 KB
/
selfextract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""\
Self installs IronPkg into the current IronPython environment.
egg: EGGNAME
md5: EGGMD5
Options:
-h, --help show this help message and exit
--install self install
"""
import os
import sys
import base64
import hashlib
import tempfile
import zipfile
from os.path import dirname, isdir, join
b64eggdata = 'EGGDATA'
def unzip(zip_file, dir_path):
"""Unzip the zip_file into the directory dir_path."""
z = zipfile.ZipFile(zip_file)
for name in z.namelist():
if name.endswith('/'):
continue
path = join(dir_path, *name.split('/'))
if not isdir(dirname(path)):
os.makedirs(dirname(path))
fo = open(path, 'wb')
fo.write(z.read(name))
fo.close()
z.close()
def self_install():
tmp_dir = tempfile.mkdtemp()
egg_path = join(tmp_dir, 'EGGNAME')
data = base64.b64decode(b64eggdata)
assert hashlib.md5(data).hexdigest() == 'EGGMD5'
fo = open(egg_path, 'wb')
fo.write(data)
fo.close()
unzip(egg_path, tmp_dir)
sys.path.insert(0, tmp_dir)
import egginst
print "Bootstrapping:", egg_path
ei = egginst.EggInst(egg_path)
ei.install()
if __name__ == '__main__':
if '--install' in sys.argv:
self_install()
else:
print __doc__