kupferbootstrap/main.py

61 lines
1.7 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import click
from traceback import format_exc as get_trace
import subprocess
from logger import logging, setup_logging, verbose_option
from wrapper import nowrapper_option
from config import config, config_option, cmd_config
from forwarding import cmd_forwarding
2021-08-04 18:36:37 +02:00
from packages import cmd_packages
from telnet import cmd_telnet
from chroot import cmd_chroot
2021-08-04 18:36:37 +02:00
from cache import cmd_cache
from image import cmd_image
from boot import cmd_boot
from flash import cmd_flash
from ssh import cmd_ssh
2021-08-04 18:36:37 +02:00
@click.group()
@click.option('--error-shell', '-E', 'error_shell', is_flag=True, default=False, help='Spawn shell after error occurs')
@verbose_option
@config_option
@nowrapper_option
def cli(verbose: bool = False, config_file: str = None, no_wrapper: bool = False, error_shell: bool = False):
setup_logging(verbose)
config.runtime['verbose'] = verbose
config.runtime['no_wrap'] = no_wrapper
config.runtime['error_shell'] = error_shell
config.try_load_file(config_file)
2021-08-04 18:36:37 +02:00
def main():
try:
return cli(prog_name='kupferbootstrap')
except Exception as ex:
if config.runtime['verbose']:
logging.fatal(get_trace())
else:
logging.fatal(ex)
if config.runtime['error_shell']:
logging.info('Starting error shell. Type exit to quit.')
subprocess.call('/bin/bash')
exit(1)
2021-08-04 18:36:37 +02:00
cli.add_command(cmd_config)
2021-08-04 18:36:37 +02:00
cli.add_command(cmd_cache)
cli.add_command(cmd_packages)
cli.add_command(cmd_image)
cli.add_command(cmd_boot)
cli.add_command(cmd_flash)
cli.add_command(cmd_ssh)
cli.add_command(cmd_forwarding)
2021-08-17 20:47:14 +02:00
cli.add_command(cmd_telnet)
cli.add_command(cmd_chroot)
if __name__ == '__main__':
main()