You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
1 week ago
|
#!/usr/bin/env python3
|
||
|
|
||
1 week ago
|
import importlib
|
||
1 week ago
|
import shutil
|
||
1 week ago
|
import sys
|
||
1 week ago
|
import tempfile
|
||
1 week ago
|
import zipapp
|
||
|
from argparse import ArgumentParser
|
||
1 week ago
|
from pathlib import Path
|
||
1 week ago
|
|
||
|
from openpilot.common.basedir import BASEDIR
|
||
|
|
||
1 week ago
|
|
||
1 week ago
|
EXTS = ['.png', '.py']
|
||
1 week ago
|
INTERPRETER = '/usr/bin/env python3'
|
||
|
|
||
1 week ago
|
|
||
1 week ago
|
def copy(src, dest, follow_symlinks=False):
|
||
|
if any(src.endswith(ext) for ext in EXTS):
|
||
|
shutil.copy2(src, dest, follow_symlinks=follow_symlinks)
|
||
1 week ago
|
|
||
|
|
||
1 week ago
|
if __name__ == '__main__':
|
||
1 week ago
|
parser = ArgumentParser(prog='pack-raylib.py', description="package openpilot's raylib code into a portable executable", epilog='comma.ai')
|
||
|
parser.add_argument('-e', '--entrypoint', help="function to call in module, default is 'main'", default='main')
|
||
1 week ago
|
parser.add_argument('-o', '--output', help='output file')
|
||
1 week ago
|
parser.add_argument('module', help="the module to target, e.g. 'openpilot.system.ui.spinner'")
|
||
1 week ago
|
args = parser.parse_args()
|
||
1 week ago
|
|
||
1 week ago
|
if not args.output:
|
||
|
args.output = args.module
|
||
|
|
||
1 week ago
|
try:
|
||
|
mod = importlib.import_module(args.module)
|
||
|
except ModuleNotFoundError:
|
||
|
print(f'{args.module} not found, typo?')
|
||
|
sys.exit(1)
|
||
|
|
||
1 week ago
|
if not hasattr(mod, args.entrypoint):
|
||
|
print(f'{args.module} does not have a {args.entrypoint}() function, typo?')
|
||
1 week ago
|
sys.exit(1)
|
||
|
|
||
1 week ago
|
with tempfile.TemporaryDirectory() as tmp:
|
||
1 week ago
|
shutil.copytree(BASEDIR + '/openpilot', tmp, symlinks=False, dirs_exist_ok=True, copy_function=copy)
|
||
1 week ago
|
entry = f'{args.module}:{args.entrypoint}'
|
||
1 week ago
|
zipapp.create_archive(tmp, target=args.output, interpreter=INTERPRETER, main=entry)
|
||
1 week ago
|
|
||
|
print(f'created executable {Path(args.output).resolve()}')
|
||
|
|