mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-14 01:26:23 +01:00
Migrate repo {list,add,remove} commands to obs_api.Project
This commit is contained in:
parent
7768684461
commit
6d692ac52b
@ -5,6 +5,7 @@ class RepoCommand(osc.commandline.OscCommand):
|
||||
"""
|
||||
Manage repositories in project meta
|
||||
"""
|
||||
|
||||
name = "repo"
|
||||
|
||||
def run(self, args):
|
||||
|
@ -1,9 +1,9 @@
|
||||
import difflib
|
||||
|
||||
import osc.commandline
|
||||
from .. import obs_api
|
||||
from .. import oscerr
|
||||
from .._private.project import ProjectMeta
|
||||
from ..core import raw_input
|
||||
from ..output import get_user_input
|
||||
|
||||
|
||||
class RepoAddCommand(osc.commandline.OscCommand):
|
||||
@ -61,22 +61,50 @@ class RepoAddCommand(osc.commandline.OscCommand):
|
||||
project, repo = path.split("/")
|
||||
paths.append({"project": project, "repository": repo})
|
||||
|
||||
meta = ProjectMeta.from_api(args.apiurl, args.project)
|
||||
old_meta = meta.to_string().splitlines()
|
||||
project_obj = obs_api.Project.from_api(args.apiurl, args.project)
|
||||
old = project_obj.to_string()
|
||||
|
||||
matching_repos = [i for i in project_obj.repository_list or [] if i.name == args.repo]
|
||||
if matching_repos:
|
||||
raise oscerr.OscValueError(f"Repository '{args.repo}' already exists in project meta")
|
||||
|
||||
project_obj.repository_list.append(
|
||||
{
|
||||
"name": args.repo,
|
||||
"arch_list": args.arches,
|
||||
"path_list": paths,
|
||||
}
|
||||
)
|
||||
|
||||
meta.repository_add(args.repo, args.arches, paths)
|
||||
if args.disable_publish:
|
||||
meta.publish_add_disable_repository(args.repo)
|
||||
|
||||
new_meta = meta.to_string().splitlines()
|
||||
diff = difflib.unified_diff(old_meta, new_meta, fromfile="old", tofile="new")
|
||||
print("\n".join(diff))
|
||||
matching_publish_disable_repos = [
|
||||
i for i in project_obj.publish_list or [] if i.flag == "disable" and i.repository == args.repo
|
||||
]
|
||||
if not matching_publish_disable_repos:
|
||||
if project_obj.publish_list is None:
|
||||
project_obj.publish_list = []
|
||||
project_obj.publish_list.append(
|
||||
{
|
||||
"flag": "disable",
|
||||
"repository": args.repo,
|
||||
}
|
||||
)
|
||||
|
||||
if not args.yes:
|
||||
new = project_obj.to_string()
|
||||
diff = difflib.unified_diff(old.splitlines(), new.splitlines(), fromfile="old", tofile="new")
|
||||
print("\n".join(diff))
|
||||
print()
|
||||
print(f"You're changing meta of project '{args.project}'")
|
||||
reply = raw_input("Do you want to apply the changes? [y/N] ").lower()
|
||||
if reply != "y":
|
||||
|
||||
reply = get_user_input(
|
||||
f"""
|
||||
You're changing meta of project '{args.project}'
|
||||
Do you want to apply the changes?
|
||||
""",
|
||||
answers={"y": "yes", "n": "no"},
|
||||
)
|
||||
|
||||
if reply == "n":
|
||||
raise oscerr.UserAbort()
|
||||
|
||||
meta.to_api(args.apiurl, args.project)
|
||||
project_obj.to_api(args.apiurl)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import osc.commandline
|
||||
from .. import obs_api
|
||||
from ..output import KeyValueTable
|
||||
from .._private.project import ProjectMeta
|
||||
|
||||
|
||||
class RepoListCommand(osc.commandline.OscCommand):
|
||||
@ -19,9 +19,9 @@ class RepoListCommand(osc.commandline.OscCommand):
|
||||
)
|
||||
|
||||
def run(self, args):
|
||||
meta = ProjectMeta.from_api(args.apiurl, args.project)
|
||||
project_obj = obs_api.Project.from_api(args.apiurl, args.project)
|
||||
repo_flags = project_obj.resolve_repository_flags()
|
||||
|
||||
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():
|
||||
@ -31,18 +31,18 @@ class RepoListCommand(osc.commandline.OscCommand):
|
||||
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"]]
|
||||
for repo in project_obj.repository_list or []:
|
||||
table.add("Repository", repo.name, color="bold")
|
||||
table.add("Architectures", ", ".join(repo.arch_list))
|
||||
if repo.path_list:
|
||||
paths = [f"{path.project}/{path.repository}" for path in repo.path_list]
|
||||
table.add("Paths", paths)
|
||||
|
||||
if repo["name"] in flag_map:
|
||||
if repo.name in flag_map:
|
||||
table.add("Flags", None)
|
||||
for flag_name in flag_map[repo["name"]]:
|
||||
for flag_name in flag_map[repo.name]:
|
||||
lines = []
|
||||
for action, archs in flag_map[repo["name"]][flag_name].items():
|
||||
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)
|
||||
|
@ -1,9 +1,9 @@
|
||||
import difflib
|
||||
|
||||
import osc.commandline
|
||||
from .. import obs_api
|
||||
from .. import oscerr
|
||||
from .._private.project import ProjectMeta
|
||||
from ..core import raw_input
|
||||
from ..output import get_user_input
|
||||
|
||||
|
||||
class RepoRemoveCommand(osc.commandline.OscCommand):
|
||||
@ -34,22 +34,35 @@ class RepoRemoveCommand(osc.commandline.OscCommand):
|
||||
)
|
||||
|
||||
def run(self, args):
|
||||
meta = ProjectMeta.from_api(args.apiurl, args.project)
|
||||
old_meta = meta.to_string().splitlines()
|
||||
project_obj = obs_api.Project.from_api(args.apiurl, args.project)
|
||||
old = project_obj.to_string()
|
||||
|
||||
for repo in args.repo:
|
||||
meta.repository_remove(repo)
|
||||
meta.publish_remove_disable_repository(repo)
|
||||
if project_obj.repository_list is not None:
|
||||
project_obj.repository_list = [i for i in project_obj.repository_list if i.name != repo]
|
||||
if project_obj.publish_list is not None:
|
||||
project_obj.publish_list = [
|
||||
i for i in project_obj.publish_list if i.flag != "disable" or i.repository != repo
|
||||
]
|
||||
|
||||
new_meta = meta.to_string().splitlines()
|
||||
diff = difflib.unified_diff(old_meta, new_meta, fromfile="old", tofile="new")
|
||||
print("\n".join(diff))
|
||||
if not project_obj.has_changed():
|
||||
return
|
||||
|
||||
if not args.yes:
|
||||
new = project_obj.to_string()
|
||||
diff = difflib.unified_diff(old.splitlines(), new.splitlines(), fromfile="old", tofile="new")
|
||||
print("\n".join(diff))
|
||||
print()
|
||||
print(f"You're changing meta of project '{args.project}'")
|
||||
reply = raw_input("Do you want to apply the changes? [y/N] ").lower()
|
||||
if reply != "y":
|
||||
|
||||
reply = get_user_input(
|
||||
f"""
|
||||
You're changing meta of project '{args.project}'
|
||||
Do you want to apply the changes?
|
||||
""",
|
||||
answers={"y": "yes", "n": "no"},
|
||||
)
|
||||
|
||||
if reply == "n":
|
||||
raise oscerr.UserAbort()
|
||||
|
||||
meta.to_api(args.apiurl, args.project)
|
||||
project_obj.to_api(args.apiurl)
|
||||
|
Loading…
Reference in New Issue
Block a user