Skip to content

Commit

Permalink
Merge pull request #1495 from dmach/xmlmodel-migrate-from-show_projec…
Browse files Browse the repository at this point in the history
…t_meta-show_package_meta

Migrate more code from show_project_meta() and show_package_meta() to xml models
  • Loading branch information
dmach committed Feb 26, 2024
2 parents f164258 + 6d692ac commit 88f2faf
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 283 deletions.
154 changes: 0 additions & 154 deletions osc/_private/project.py

This file was deleted.

2 changes: 1 addition & 1 deletion osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9048,7 +9048,7 @@ def setBugownerHelper(apiurl, project, package, bugowner):
delPerson(apiurl, prj, pac, opts.delete, role)
elif opts.devel_project:
# XXX: does it really belong to this command?
setDevelProject(apiurl, prj, pac, opts.devel_project)
set_devel_project(apiurl, prj, pac, opts.devel_project)
else:
if pac:
m = show_package_meta(apiurl, prj, pac)
Expand Down
1 change: 1 addition & 0 deletions osc/commands/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class RepoCommand(osc.commandline.OscCommand):
"""
Manage repositories in project meta
"""

name = "repo"

def run(self, args):
Expand Down
56 changes: 42 additions & 14 deletions osc/commands/repo_add.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -61,22 +61,50 @@ def run(self, args):
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()

meta.repository_add(args.repo, args.arches, paths)
if args.disable_publish:
meta.publish_add_disable_repository(args.repo)
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,
}
)

new_meta = meta.to_string().splitlines()
diff = difflib.unified_diff(old_meta, new_meta, fromfile="old", tofile="new")
print("\n".join(diff))
if args.disable_publish:
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)
22 changes: 11 additions & 11 deletions osc/commands/repo_list.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -19,9 +19,9 @@ def init_arguments(self):
)

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():
Expand All @@ -31,18 +31,18 @@ def run(self, args):
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)
Expand Down
39 changes: 26 additions & 13 deletions osc/commands/repo_remove.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -34,22 +34,35 @@ def init_arguments(self):
)

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

0 comments on commit 88f2faf

Please sign in to comment.