Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access and notice to list of platforms via manager #58

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions ixmp4/cli/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,37 @@ def remove(
settings.toml.remove_platform(name)


def tabulate_platforms(
platforms: list[TomlPlatformInfo] | list[ManagerPlatformInfo],
):
utils.echo("Platform".ljust(15) + "DSN\n".ljust(15))
total = 0
for p in platforms:
name = p.name
if len(name) > 12:
name = name[:9] + "..."
name = name.ljust(15)
def tabulate_toml_platforms(platforms: list[TomlPlatformInfo]):
toml_path_str = typer.style(settings.toml.path, fg=typer.colors.CYAN)
utils.echo(f"\nPlatforms registered in '{toml_path_str}'")
if len(platforms):
utils.echo("\nName".ljust(21) + "DSN")
for p in platforms:
utils.important(_shorten(p.name, 20), nl=False)
utils.echo(_shorten(p.dsn, 60))
utils.echo("Total: " + typer.style(str(len(platforms)), fg=typer.colors.GREEN))

utils.important(name, nl=False)
utils.echo(p.dsn.ljust(10))
total += 1

utils.info("\n" + str(total), nl=False)
utils.echo(" total \n")
def tabulate_manager_platforms(
platforms: list[ManagerPlatformInfo],
):
manager_url_str = typer.style(settings.manager.url, fg=typer.colors.CYAN)
utils.echo(f"\nPlatforms accessible via '{manager_url_str}'")
utils.echo("\nName".ljust(21) + "Access".ljust(10) + "Notice")
for p in platforms:
utils.important(_shorten(p.name, 20), nl=False)
utils.echo(str(p.accessibility.value.lower()).ljust(10), nl=False)
if p.notice is not None:
utils.echo(_shorten(p.notice, 58), nl=False)
utils.echo()
utils.echo("Total: " + typer.style(str(len(platforms)), fg=typer.colors.GREEN))


@app.command("list", help="Lists all registered platforms.")
def list_():
toml_path_str = typer.style(settings.toml.path, fg=typer.colors.CYAN)
toml_platforms = settings.toml.list_platforms()
utils.echo(f"Platforms in '{toml_path_str}':")
tabulate_platforms(toml_platforms)

tabulate_toml_platforms(settings.toml.list_platforms())
if settings.manager is not None:
manager_url_str = typer.style(settings.manager.url, fg=typer.colors.CYAN)
manager_platforms = settings.manager.list_platforms()
utils.echo(f"Platforms accessible via '{manager_url_str}':")
tabulate_platforms(manager_platforms)
tabulate_manager_platforms(settings.manager.list_platforms())


@app.command(
Expand Down Expand Up @@ -279,3 +279,10 @@ def generate_data(generator: MockDataGenerator):
)
for df in generator.yield_datapoints(runs, variable_names, units, regions):
progress.advance(task, len(df))


def _shorten(value: str, length: int):
"""Shorten and adjust a string to a given length adding `...` if necessary"""
if len(value) > length - 4:
value = value[: length - 4] + "..."
return value.ljust(length)
Loading