2023-05-12 10:10:08 +02:00
|
|
|
import osc.commandline
|
2023-05-30 09:08:53 +02:00
|
|
|
from ..output import KeyValueTable
|
2023-05-12 10:10:08 +02:00
|
|
|
from .._private.project import ProjectMeta
|
|
|
|
|
|
|
|
|
|
|
|
class RepoListCommand(osc.commandline.OscCommand):
|
|
|
|
"""
|
|
|
|
List repositories in project meta
|
|
|
|
"""
|
|
|
|
|
|
|
|
name = "list"
|
|
|
|
aliases = ["ls"]
|
|
|
|
parent = "RepoCommand"
|
|
|
|
|
|
|
|
def init_arguments(self):
|
|
|
|
self.add_argument(
|
|
|
|
"project",
|
|
|
|
help="Name of the project",
|
|
|
|
)
|
|
|
|
|
|
|
|
def run(self, args):
|
|
|
|
meta = ProjectMeta.from_api(args.apiurl, args.project)
|
2023-07-07 13:14:27 +02:00
|
|
|
|
|
|
|
repo_flags = meta.resolve_repository_flags()
|
|
|
|
flag_map = {}
|
|
|
|
for (repo_name, arch), data in repo_flags.items():
|
|
|
|
for flag_name, flag_value in data.items():
|
|
|
|
if flag_value is None:
|
|
|
|
continue
|
|
|
|
action = "enable" if flag_value else "disable"
|
|
|
|
flag_map.setdefault(repo_name, {}).setdefault(flag_name, {}).setdefault(action, []).append(arch)
|
|
|
|
|
2023-05-30 09:08:53 +02:00
|
|
|
table = KeyValueTable()
|
2023-05-12 10:10:08 +02:00
|
|
|
for repo in meta.repository_list():
|
2023-05-30 09:08:53 +02:00
|
|
|
table.add("Repository", repo["name"], color="bold")
|
|
|
|
table.add("Architectures", ", ".join(repo["archs"]))
|
|
|
|
if repo["paths"]:
|
|
|
|
paths = [f"{path['project']}/{path['repository']}" for path in repo["paths"]]
|
|
|
|
table.add("Paths", paths)
|
2023-07-07 13:14:27 +02:00
|
|
|
|
|
|
|
if repo["name"] in flag_map:
|
|
|
|
table.add("Flags", None)
|
|
|
|
for flag_name in flag_map[repo["name"]]:
|
|
|
|
lines = []
|
|
|
|
for action, archs in flag_map[repo["name"]][flag_name].items():
|
|
|
|
lines.append(f"{action + ':':<8s} {', '.join(archs)}")
|
|
|
|
lines.sort()
|
|
|
|
table.add(flag_name, lines, indent=4)
|
|
|
|
|
2023-05-30 09:08:53 +02:00
|
|
|
table.newline()
|
|
|
|
print(str(table))
|