Skip to content
Snippets Groups Projects
Commit 2e8c52e9 authored by Daniel CARRON's avatar Daniel CARRON :b: Committed by André Anjos
Browse files

[cli] Fix info command

parent 1e2c50e0
No related branches found
No related tags found
1 merge request!46Create common library
......@@ -5,10 +5,52 @@
import click
from clapper.click import verbosity_option
from clapper.logging import setup
from clapper.rc import UserDefaults
logger = setup(__name__.split(".")[0], format="%(levelname)s: %(message)s")
def _echo(left: str, right: str, color: str = "white") -> None:
s = [
click.style(left, bold=True),
click.style(": ", bold=True),
click.style(right, fg=color),
]
click.echo("".join(s))
def database_configuration(
rc: UserDefaults, raw_databases: dict[str, dict[str, str]], lib_name: str
):
"""Display the database configuration for a particular library.
Parameters
----------
rc
The user defaults read from the user .toml configuration file.
raw_databases
List of all supported (raw) databases.
lib_name
Name of the library to show configurations for.
"""
if not rc.path.exists():
_echo(f"{lib_name} configuration", f"{str(rc.path)} [MISSING]", "white")
else:
_echo(f"{lib_name} configuration", str(rc.path), "white")
click.secho(f"configured {lib_name} databases:", bold=True)
for k, v in raw_databases.items():
if "datadir" not in v:
# this database does not have a "datadir"
continue
if v["datadir"] is not None:
_echo(f" - {k} ({v['module']})", f"{v['datadir']}", "green")
else:
_echo(f" - {k} ({v['module']})", "NOT installed", "red")
@click.command(
epilog="""Examples:
......@@ -28,20 +70,21 @@ def info(
import typing
from ..utils.rc import load_rc
from .database import _get_raw_databases
from .utils import execution_metadata
def _echo(left: str, right: str, color: str = "white") -> None:
s = [
click.style(left, bold=True),
click.style(": ", bold=True),
click.style(right, fg=color),
]
click.echo("".join(s))
from mednet.libs.classification.scripts.database import (
_get_raw_databases as _get_raw_databases_classification,
)
from mednet.libs.classification.utils.rc import (
load_rc as load_rc_classification,
)
from mednet.libs.common.scripts.utils import execution_metadata
from mednet.libs.segmentation.scripts.database import (
_get_raw_databases as _get_raw_databases_segmentation,
)
from mednet.libs.segmentation.utils.rc import (
load_rc as load_rc_segmentation,
)
m = execution_metadata()
c = load_rc()
_echo("mednet version", typing.cast(str, m["package-version"]), "green")
_echo("platform", typing.cast(str, m["platform"]), "yellow")
......@@ -51,21 +94,16 @@ def info(
"cyan",
)
if not c.path.exists():
_echo("configuration", f"{str(c.path)} [MISSING]", "white")
else:
_echo("configuration", str(c.path), "white")
dbs = _get_raw_databases()
click.secho("configured databases:", bold=True)
for k, v in dbs.items():
if "datadir" not in v:
# this database does not have a "datadir"
continue
if v["datadir"] is not None:
_echo(f" - {k} ({v['module']})", f"{v['datadir']}", "green")
else:
_echo(f" - {k} ({v['module']})", "NOT installed", "red")
database_configuration(
load_rc_classification(),
_get_raw_databases_classification(),
"classification",
)
database_configuration(
load_rc_segmentation(),
_get_raw_databases_segmentation(),
"segmentation",
)
click.secho("dependencies:", bold=True)
python = typing.cast(dict[str, str], m["python"])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment