-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |