toolforge-components-cli 0.0.4__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: toolforge-components-cli
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Summary: Toolforge components client
5
5
  License: GPLv3
6
6
  Author: Slavina Stefanova
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "toolforge-components-cli"
3
- version = "0.0.4"
3
+ version = "0.0.6"
4
4
  description = "Toolforge components client"
5
5
  authors = ["Slavina Stefanova <sstefanova@wikimedia.org>"]
6
6
  license = "GPLv3"
@@ -6,9 +6,12 @@ import logging
6
6
  import os
7
7
  import subprocess
8
8
  import sys
9
+ from textwrap import indent
10
+ from typing import Any
9
11
 
10
12
  import click
11
13
  import yaml
14
+ from tabulate import tabulate
12
15
  from toolforge_weld.errors import (
13
16
  ToolforgeError,
14
17
  ToolforgeUserError,
@@ -88,12 +91,34 @@ def _display_deployment(deployment_data: dict, as_json: bool, prefix: str = "")
88
91
  else:
89
92
  if prefix:
90
93
  click.echo(prefix)
91
- click.echo(f"Deployment ID: {deployment_data.get('deploy_id')}")
92
- click.echo(f"Created: {deployment_data.get('creation_time')}")
94
+ click.echo(
95
+ click.style("Deployment ID: ", bold=True) + deployment_data["deploy_id"]
96
+ )
97
+ click.echo(
98
+ click.style("Created: ", bold=True) + deployment_data["creation_time"]
99
+ )
100
+ click.echo(
101
+ click.style("Status: ", bold=True)
102
+ + _format_status(deployment_data.get("status", "unknown"))
103
+ )
104
+ click.echo(
105
+ click.style("Long status: ", bold=True)
106
+ + "\n"
107
+ + indent(text=deployment_data.get("long_status", "unknown"), prefix=" ")
108
+ )
93
109
  if deployment_data.get("builds"):
94
- click.echo("\nBuilds:" if not prefix else "Builds:")
110
+ click.echo("\n" + click.style("Builds:", bold=True))
95
111
  for component, build in deployment_data["builds"].items():
96
- click.echo(f" {component}: {build.get('build_id')}")
112
+ click.echo(
113
+ f" {component}({_format_status(build['build_status'])}): {build['build_id']}"
114
+ )
115
+
116
+ if deployment_data.get("runs"):
117
+ click.echo("\n" + click.style("Runs:", bold=True))
118
+ for component, run in deployment_data["runs"].items():
119
+ click.echo(
120
+ f" {component}({_format_status(run['run_status'])}): {run.get('run_long_status', '')}"
121
+ )
97
122
 
98
123
 
99
124
  @click.version_option(prog_name="Toolforge Components CLI")
@@ -349,7 +374,50 @@ def deployment_create(ctx, as_json: bool) -> None:
349
374
  if deployment_data.get("builds"):
350
375
  click.echo("\nBuilds:")
351
376
  for component, build in deployment_data["builds"].items():
352
- click.echo(f" {component}: {build.get('build_id')}")
377
+ click.echo(
378
+ f" {component}({_format_status(build['build_status'])}): {build['build_id']}"
379
+ )
380
+ if deployment_data.get("runs"):
381
+ click.echo("\nRuns:")
382
+ for component, run in deployment_data["runs"].items():
383
+ click.echo(
384
+ f" {component}({_format_status(run['run_status'])}): {run.get('run_long_status', '')}"
385
+ )
386
+
387
+
388
+ def _format_headers(headers: list[str]) -> list[str]:
389
+ return [click.style(item, bold=True) for item in headers]
390
+
391
+
392
+ def _format_builds(builds: dict[str, dict[str, Any]]) -> str:
393
+ builds_strings: list[str] = []
394
+ for component_name, build_info in builds.items():
395
+ builds_strings.append(
396
+ f"{component_name}({_format_status(build_info['build_status'])}): {build_info['build_id']}"
397
+ )
398
+ return "\n".join(builds_strings)
399
+
400
+
401
+ def _format_runs(runs: dict[str, dict[str, Any]]) -> str:
402
+ runs_strings: list[str] = []
403
+ for component_name, run_info in runs.items():
404
+ runs_strings.append(
405
+ f"{component_name}({_format_status(run_info['run_status'])}): {run_info.get('run_long_status', '')}"
406
+ )
407
+ return "\n".join(runs_strings)
408
+
409
+
410
+ def _format_status(status: str) -> str:
411
+ fg_color = "yellow"
412
+
413
+ if status in ("running", "pending"):
414
+ fg_color = "yellow"
415
+ elif status == "failed":
416
+ fg_color = "red"
417
+ elif status == "successful":
418
+ fg_color = "green"
419
+
420
+ return click.style(status, fg=fg_color)
353
421
 
354
422
 
355
423
  @deployment.command(name="list", help="List all deployments.")
@@ -371,13 +439,24 @@ def deployment_list(ctx, as_json: bool) -> None:
371
439
  return
372
440
 
373
441
  deployments = response.get("data", {}).get("deployments", [])
374
- for deployment in deployments:
375
- click.echo(f"\nDeployment ID: {deployment.get('deploy_id')}")
376
- click.echo(f"Created: {deployment.get('creation_time')}")
377
- if deployment.get("builds"):
378
- click.echo("Builds:")
379
- for component, build in deployment["builds"].items():
380
- click.echo(f" {component}: {build.get('build_id')}")
442
+ formatted_deployments = [
443
+ [
444
+ deployment["deploy_id"],
445
+ deployment["creation_time"],
446
+ _format_status(deployment.get("status", "unknown")),
447
+ _format_builds(deployment.get("builds", {})),
448
+ _format_runs(deployment.get("runs", {})),
449
+ ]
450
+ for deployment in deployments
451
+ ]
452
+ click.echo(
453
+ tabulate(
454
+ formatted_deployments,
455
+ headers=_format_headers(
456
+ ["ID", "Creation time", "Status", "Builds", "Runs"]
457
+ ),
458
+ )
459
+ )
381
460
 
382
461
 
383
462
  @deployment.command(name="show", help="Show details of a specific deployment.")
@@ -430,6 +509,7 @@ def deployment_delete(
430
509
 
431
510
 
432
511
  def main() -> int:
512
+ debug = False
433
513
  try:
434
514
  args = sys.argv[1:]
435
515
  debug = "-d" in args or "--debug" in args