2009-12-28 06:03:04 +08:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
sources = """
|
|
|
|
@SOURCES@"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import base64
|
|
|
|
import zlib
|
|
|
|
import imp
|
|
|
|
|
|
|
|
class DictImporter(object):
|
2010-01-16 01:45:06 +08:00
|
|
|
def __init__(self, sources):
|
|
|
|
self.sources = sources
|
|
|
|
|
2009-12-28 06:03:04 +08:00
|
|
|
def find_module(self, fullname, path=None):
|
|
|
|
if fullname in self.sources:
|
|
|
|
return self
|
2010-11-14 06:33:50 +08:00
|
|
|
if fullname + '.__init__' in self.sources:
|
2009-12-28 06:03:04 +08:00
|
|
|
return self
|
|
|
|
return None
|
|
|
|
|
|
|
|
def load_module(self, fullname):
|
|
|
|
# print "load_module:", fullname
|
2009-12-31 00:08:45 +08:00
|
|
|
from types import ModuleType
|
2009-12-28 06:03:04 +08:00
|
|
|
try:
|
|
|
|
s = self.sources[fullname]
|
|
|
|
is_pkg = False
|
|
|
|
except KeyError:
|
2010-11-14 06:33:50 +08:00
|
|
|
s = self.sources[fullname + '.__init__']
|
2009-12-28 06:03:04 +08:00
|
|
|
is_pkg = True
|
2010-07-27 03:15:15 +08:00
|
|
|
|
2009-12-28 06:03:04 +08:00
|
|
|
co = compile(s, fullname, 'exec')
|
2009-12-31 00:08:45 +08:00
|
|
|
module = sys.modules.setdefault(fullname, ModuleType(fullname))
|
2009-12-28 06:03:04 +08:00
|
|
|
module.__file__ = "%s/%s" % (__file__, fullname)
|
|
|
|
module.__loader__ = self
|
|
|
|
if is_pkg:
|
|
|
|
module.__path__ = [fullname]
|
2010-07-27 03:15:15 +08:00
|
|
|
|
2009-12-31 00:08:45 +08:00
|
|
|
do_exec(co, module.__dict__)
|
2009-12-28 06:03:04 +08:00
|
|
|
return sys.modules[fullname]
|
|
|
|
|
2009-12-31 02:01:46 +08:00
|
|
|
def get_source(self, name):
|
|
|
|
res = self.sources.get(name)
|
|
|
|
if res is None:
|
2010-11-14 06:33:50 +08:00
|
|
|
res = self.sources.get(name + '.__init__')
|
2009-12-31 02:01:46 +08:00
|
|
|
return res
|
|
|
|
|
2009-12-28 06:03:04 +08:00
|
|
|
if __name__ == "__main__":
|
2010-11-14 06:33:50 +08:00
|
|
|
if sys.version_info >= (3, 0):
|
2010-01-16 01:45:06 +08:00
|
|
|
exec("def do_exec(co, loc): exec(co, loc)\n")
|
|
|
|
import pickle
|
2010-07-27 03:15:15 +08:00
|
|
|
sources = sources.encode("ascii") # ensure bytes
|
2010-01-16 01:45:06 +08:00
|
|
|
sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)))
|
|
|
|
else:
|
|
|
|
import cPickle as pickle
|
|
|
|
exec("def do_exec(co, loc): exec co in loc\n")
|
|
|
|
sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
|
|
|
|
|
|
|
|
importer = DictImporter(sources)
|
2013-02-13 05:59:29 +08:00
|
|
|
sys.meta_path.insert(0, importer)
|
2010-01-16 01:45:06 +08:00
|
|
|
|
2010-10-16 09:10:14 +08:00
|
|
|
entry = "@ENTRY@"
|
|
|
|
do_exec(entry, locals())
|