forked from pypiserver/pypiserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-standalone.py
executable file
·62 lines (48 loc) · 1.43 KB
/
gen-standalone.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
58
59
60
61
62
#! /usr/bin/env python
"""generate a single file pypi-server script"""
import os, zlib, base64, itertools
try:
import cPickle
except ImportError:
import pickle as cPickle
def find_files(path):
for dirpath, dirnames, filenames in os.walk(path):
for f in filenames:
yield os.path.join(dirpath, f)
def myExecFile(file, g, l):
try:
execfile(file, g, l)
except NameError:
with open(file) as fd:
txt = fd.read()
exec(txt, g, l)
def get_version():
d = {}
try:
myExecFile("pypiserver/__init__.py", d, d)
except (ImportError, RuntimeError):
pass
return d["__version__"]
def main():
name2src = {}
for f in itertools.chain(find_files("pypiserver"),
find_files("vendor")):
if not f.endswith(".py"):
continue
k = f.replace('/', '.')[:-3]
if k.startswith("vendor."):
k = k[len("vendor."):]
name2src[k] = open(f).read()
data = cPickle.dumps(name2src, 2)
data = zlib.compress(data, 9)
data = base64.encodestring(data)
data = '%s' % (data)
script = open("pypi-server-in.py").read()
script = script.replace("@VERSION@", get_version())
script = script.replace('@SOURCES@', data)
dst = "pypi-server-standalone.py"
open(dst, "w").write(script)
os.chmod(dst, 755)
print("created %s"%dst)
if __name__ == '__main__':
main()