-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphite.py
More file actions
executable file
·54 lines (39 loc) · 1.4 KB
/
Copy pathgraphite.py
File metadata and controls
executable file
·54 lines (39 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env -S uv run --script
# SPDX-FileCopyrightText: 2024-2025 Andrew Gunnerson
# SPDX-License-Identifier: GPL-3.0-only
import logging
import os
import subprocess
import tempfile
from pathlib import Path
from lib import commands, dependencies, external
logger = logging.getLogger(__name__)
def main():
logging.basicConfig(
level=logging.DEBUG, # TODO: support DEBUG env var
format='\x1b[1m[%(levelname)s] %(message)s\x1b[0m',
)
# Parse and validate args
args = commands.parse_args()
# Download tool binaries
dependencies.download_avbroot(external.BINARIES_DIR)
dependencies.download_afsr(external.BINARIES_DIR)
dependencies.download_custota_tool(external.BINARIES_DIR)
# Add binaries dir to path
os.environ['PATH'] = str(external.BINARIES_DIR) + ':' + os.environ['PATH']
# Run subcommand
failure = False
try:
actions = commands.all_command_actions()
with tempfile.TemporaryDirectory() as temp_dir:
actions[args.command](args, Path(temp_dir))
except Exception as e:
failure = True
logging.error(f'Failed to run {args.command} command!', exc_info=e)
if getattr(args, 'debug_shell', False):
shell = os.getenv('SHELL', 'bash')
logger.info(f'Debug shell: {shell}')
subprocess.run([shell], cwd=temp_dir)
exit(1 if failure else 0)
if __name__ == '__main__':
main()