From 42b50cc43aec64af554478ee00aa834fa0d4e4ab Mon Sep 17 00:00:00 2001 From: Obijuan Date: Sun, 17 Mar 2024 21:15:31 +0100 Subject: [PATCH] apio system refactoring --- apio/commands/system.py | 63 ++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/apio/commands/system.py b/apio/commands/system.py index d59d1ff0..f7d8fdfa 100644 --- a/apio/commands/system.py +++ b/apio/commands/system.py @@ -1,43 +1,74 @@ # -*- coding: utf-8 -*- # -- This file is part of the Apio project -# -- (C) 2016-2019 FPGAwars -# -- Author Jesús Arroyo +# -- (C) 2016-2024 FPGAwars +# -- Authors +# -- * Jesús Arroyo (2016-2019) +# -- * Juan Gonzalez (obijuan) (2019-2024) # -- Licence GPLv2 -"""TODO""" +"""Main implementation of APIO SYSTEM command""" import click - from apio import util from apio.util import get_systype from apio.managers.system import System +# ------------------ +# -- CONSTANTS +# ------------------ +CMD = "system" # -- Comand name +LSFTDI = "lsftdi" # -- Option +LSUSB = "lsusb" # -- Option +LSSERIAL = "lsserial" # -- Option +INFO = "info" # -- Option + -@click.command("system", context_settings=util.context_settings()) +@click.command(CMD, context_settings=util.context_settings()) @click.pass_context @click.option( - "--lsftdi", is_flag=True, help="List all connected FTDI devices." + f"--{LSFTDI}", is_flag=True, help="List all connected FTDI devices." ) -@click.option("--lsusb", is_flag=True, help="List all connected USB devices.") @click.option( - "--lsserial", is_flag=True, help="List all connected Serial devices." + f"--{LSUSB}", is_flag=True, help="List all connected USB devices." ) -@click.option("-i", "--info", is_flag=True, help="Show system information.") -def cli(ctx, lsftdi, lsusb, lsserial, info): - """System tools.\n - Install with `apio install system`""" +@click.option( + f"--{LSSERIAL}", is_flag=True, help="List all connected Serial devices." +) +@click.option("-i", f"--{INFO}", is_flag=True, help="Show system information.") +def cli(ctx, **kwargs): + # def cli(ctx, lsftdi, lsusb, lsserial, info): + """System tools.""" + + # -- Extract the arguments + lsftdi = kwargs[LSFTDI] + lsusb = kwargs[LSUSB] + lsserial = kwargs[LSSERIAL] + info = kwargs[INFO] - exit_code = 0 + # -- Create the system object + system = System() + # -- List all connected ftdi devices if lsftdi: - exit_code = System().lsftdi() + exit_code = system.lsftdi() + + # -- List all connected USB devices elif lsusb: - exit_code = System().lsusb() + exit_code = system.lsusb() + + # -- List all connected serial devices elif lsserial: - exit_code = System().lsserial() + exit_code = system.lsserial() + + # -- Show system information elif info: click.secho("Platform: ", nl=False) click.secho(get_systype(), fg="yellow") + exit_code = 0 + + # -- Invalid option. Just show the help else: click.secho(ctx.get_help()) + exit_code = 0 + # -- Done! ctx.exit(exit_code)