2015-09-21 19:53:37 +00:00
|
|
|
#!/usr/bin/env python
|
2016-10-21 16:21:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-10-23 17:16:11 +00:00
|
|
|
import sys
|
2015-09-21 19:53:37 +00:00
|
|
|
import marshal
|
|
|
|
import struct
|
|
|
|
import base64
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
|
|
|
remove_stdout="""
|
|
|
|
import sys
|
|
|
|
class Blackhole(object):
|
|
|
|
softspace = 0
|
|
|
|
def read(self):
|
|
|
|
pass
|
|
|
|
def write(self, text):
|
|
|
|
pass
|
|
|
|
def flush(self):
|
|
|
|
pass
|
|
|
|
sys.stdout = Blackhole()
|
|
|
|
sys.stderr = Blackhole()
|
|
|
|
del Blackhole
|
|
|
|
"""
|
2016-10-21 16:21:54 +00:00
|
|
|
|
2015-10-23 17:16:11 +00:00
|
|
|
if len(sys.argv)==2 and sys.argv[1].strip().lower()=="debug":
|
2016-03-16 22:17:03 +00:00
|
|
|
remove_stdout="print 'DEBUG activated'\n"
|
2016-10-21 16:21:54 +00:00
|
|
|
|
2015-09-21 19:53:37 +00:00
|
|
|
def get_load_module_code(code, modulename):
|
|
|
|
loader="""
|
2016-10-21 16:21:54 +00:00
|
|
|
import marshal, imp, sys
|
2015-09-21 19:53:37 +00:00
|
|
|
fullname={}
|
|
|
|
mod = imp.new_module(fullname)
|
|
|
|
mod.__file__ = "<bootloader>\\%s" % fullname
|
2016-10-21 16:21:54 +00:00
|
|
|
exec marshal.loads({}) in mod.__dict__
|
2015-09-21 19:53:37 +00:00
|
|
|
sys.modules[fullname]=mod
|
|
|
|
""".format(repr(modulename),repr(code))
|
|
|
|
return loader
|
|
|
|
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
code_bytes=[]
|
|
|
|
code=""
|
|
|
|
code_bytes.append(compile(remove_stdout, "<string>", "exec"))
|
2016-10-21 16:21:54 +00:00
|
|
|
code_bytes.append(compile("import sys; sys.argv = [];", "<string>", "exec"))
|
2015-09-21 19:53:37 +00:00
|
|
|
with open(os.path.join("..", "..", "pupy", "packages","all", "pupyimporter.py")) as f:
|
|
|
|
code=f.read()
|
2016-10-21 16:21:54 +00:00
|
|
|
|
|
|
|
code=marshal.dumps(compile(code, '<string>', 'exec'))
|
|
|
|
|
2015-09-21 19:53:37 +00:00
|
|
|
code_bytes.append(compile(get_load_module_code(code,"pupyimporter")+"\n", "<string>", "exec"))
|
2016-10-21 16:21:54 +00:00
|
|
|
code_bytes.append(compile("import pupyimporter;pupyimporter.install();\n", "<string>", "exec"))
|
2015-10-23 17:16:11 +00:00
|
|
|
with open(os.path.join("..",'..','pupy',"pp.py")) as f:
|
2015-09-21 19:53:37 +00:00
|
|
|
code=f.read()
|
|
|
|
code_bytes.append(compile(code+"\n", "<string>", "exec"))
|
|
|
|
code_bytes=marshal.dumps(code_bytes)
|
|
|
|
with open(os.path.join("resources","bootloader.pyc"),'wb') as w:
|
|
|
|
w.write(code_bytes)
|