1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-27 02:16:12 +01:00
github.com_openSUSE_osc/osc/commands/repo_list.py

52 lines
1.7 KiB
Python

import osc.commandline
from ..output import KeyValueTable
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)
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)
table = KeyValueTable()
for repo in meta.repository_list():
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)
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)
table.newline()
print(str(table))