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