mirror of
https://github.com/pypiserver/pypiserver
synced 2024-11-09 16:45:51 +01:00
generate single file script "pypi-server-standalone.py".
This commit is contained in:
parent
c9484e177d
commit
f37dc30f3a
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,3 +18,4 @@ __pycache__/
|
|||||||
/dist/
|
/dist/
|
||||||
/MANIFEST
|
/MANIFEST
|
||||||
/README.html
|
/README.html
|
||||||
|
/pypi-server-standalone.py
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
include .gitignore
|
include .gitignore
|
||||||
include MANIFEST.in
|
include MANIFEST.in
|
||||||
include README.rst
|
include README.rst
|
||||||
|
include gen-standalone.py
|
||||||
include pypi-server
|
include pypi-server
|
||||||
|
include pypi-server-in.py
|
||||||
include pypiserver/__init__.py
|
include pypiserver/__init__.py
|
||||||
include pypiserver/__main__.py
|
include pypiserver/__main__.py
|
||||||
include pypiserver/bottle.py
|
include pypiserver/bottle.py
|
||||||
|
36
gen-standalone.py
Executable file
36
gen-standalone.py
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
|
||||||
|
"""generate a single file pypi-server script"""
|
||||||
|
|
||||||
|
import os, zlib, cPickle, base64, glob
|
||||||
|
|
||||||
|
def get_version():
|
||||||
|
d = {}
|
||||||
|
try:
|
||||||
|
execfile("pypiserver/__init__.py", d, d)
|
||||||
|
except (ImportError, RuntimeError):
|
||||||
|
pass
|
||||||
|
return d["__version__"]
|
||||||
|
|
||||||
|
def main():
|
||||||
|
name2src = {}
|
||||||
|
for f in glob.glob("pypiserver/*.py"):
|
||||||
|
k = f.replace('/', '.')[:-3]
|
||||||
|
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, 0755)
|
||||||
|
print "created", dst
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
main()
|
52
pypi-server-in.py
Normal file
52
pypi-server-in.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#! /usr/bin/env python
|
||||||
|
"""standalone pypi-server, version @VERSION@"""
|
||||||
|
|
||||||
|
sources = """
|
||||||
|
@SOURCES@"""
|
||||||
|
|
||||||
|
import sys, base64, zlib, cPickle
|
||||||
|
|
||||||
|
sources = cPickle.loads(zlib.decompress(base64.decodestring(sources)))
|
||||||
|
|
||||||
|
|
||||||
|
class DictImporter(object):
|
||||||
|
sources = sources
|
||||||
|
|
||||||
|
def find_module(self, fullname, path=None):
|
||||||
|
if fullname in self.sources:
|
||||||
|
return self
|
||||||
|
if fullname + '.__init__' in self.sources:
|
||||||
|
return self
|
||||||
|
return None
|
||||||
|
|
||||||
|
def load_module(self, fullname):
|
||||||
|
try:
|
||||||
|
s = self.sources[fullname]
|
||||||
|
is_pkg = False
|
||||||
|
except KeyError:
|
||||||
|
s = self.sources[fullname + '.__init__']
|
||||||
|
is_pkg = True
|
||||||
|
|
||||||
|
co = compile(s, fullname, 'exec')
|
||||||
|
module = sys.modules.setdefault(fullname, type(sys)(fullname))
|
||||||
|
module.__file__ = __file__
|
||||||
|
module.__loader__ = self
|
||||||
|
if is_pkg:
|
||||||
|
module.__path__ = [fullname]
|
||||||
|
|
||||||
|
exec co in module.__dict__
|
||||||
|
return sys.modules[fullname]
|
||||||
|
|
||||||
|
def get_source(self, name):
|
||||||
|
res = self.sources.get(name)
|
||||||
|
if res is None:
|
||||||
|
res = self.sources.get(name + '.__init__')
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
importer = DictImporter()
|
||||||
|
sys.meta_path.append(importer)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from pypiserver.core import main
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user