Skip to content

Commit

Permalink
apio system refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Mar 17, 2024
1 parent 2274982 commit 42b50cc
Showing 1 changed file with 47 additions and 16 deletions.
63 changes: 47 additions & 16 deletions apio/commands/system.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 42b50cc

Please sign in to comment.