openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
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.

54 lines
1.7 KiB

2 weeks ago
#!/usr/bin/env python3
2 weeks ago
import importlib
import shutil
2 weeks ago
import sys
2 weeks ago
import tempfile
2 weeks ago
import zipapp
from argparse import ArgumentParser
2 weeks ago
from pathlib import Path
2 weeks ago
from openpilot.common.basedir import BASEDIR
2 weeks ago
2 weeks ago
DIRS = ['cereal', 'openpilot']
EXTS = ['.png', '.py', '.svg', '.ttf', '.capnp']
2 weeks ago
INTERPRETER = '/usr/bin/env python3'
2 weeks ago
2 weeks ago
def copy(src, dest, follow_symlinks=False):
if any(src.endswith(ext) for ext in EXTS):
2 weeks ago
shutil.copy2(src, dest, follow_symlinks=True)
2 weeks ago
if __name__ == '__main__':
2 weeks ago
parser = ArgumentParser(prog='pack.py', description="package openpilot's raylib code into a portable executable", epilog='comma.ai')
2 weeks ago
parser.add_argument('-e', '--entrypoint', help="function to call in module, default is 'main'", default='main')
2 weeks ago
parser.add_argument('-o', '--output', help='output file')
2 weeks ago
parser.add_argument('module', help="the module to target, e.g. 'openpilot.system.ui.spinner'")
2 weeks ago
args = parser.parse_args()
2 weeks ago
2 weeks ago
if not args.output:
args.output = args.module
2 weeks ago
try:
2 weeks ago
print(args.module)
2 weeks ago
mod = importlib.import_module(args.module)
except ModuleNotFoundError:
print(f'{args.module} not found, typo?')
sys.exit(1)
2 weeks ago
if not hasattr(mod, args.entrypoint):
print(f'{args.module} does not have a {args.entrypoint}() function, typo?')
2 weeks ago
sys.exit(1)
2 weeks ago
with tempfile.TemporaryDirectory(delete=False) as tmp:
print(tmp)
for directory in DIRS:
shutil.copytree(BASEDIR + '/' + directory, tmp + '/' + directory, symlinks=False, dirs_exist_ok=True, copy_function=copy)
2 weeks ago
entry = f'{args.module}:{args.entrypoint}'
zipapp.create_archive(tmp, target=args.output, interpreter=INTERPRETER, main=entry)
2 weeks ago
print(f'created executable {Path(args.output).resolve()}')