1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-24 22:06:14 +01:00

Merge pull request #1009 from dmach/aggregatepac-flavor

Support flavors in aggregatepac
This commit is contained in:
Daniel Mach 2022-06-02 10:06:21 +02:00 committed by GitHub
commit a223dd085a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 8 deletions

View File

@ -3014,7 +3014,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
DESTPAC is omitted.
usage:
osc aggregatepac SOURCEPRJ SOURCEPAC DESTPRJ [DESTPAC]
osc aggregatepac SOURCEPRJ SOURCEPAC[:FLAVOR] DESTPRJ [DESTPAC]
${cmd_option_list}
"""

View File

@ -5339,19 +5339,28 @@ def link_pac(src_project, src_package, dst_project, dst_package, force, rev='',
http_PUT(u, data=link_template)
print('Done.')
def aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map = {}, disable_publish = False, nosources = False):
def aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map=None,
disable_publish=False, nosources=False, repo_check=True):
"""
aggregate package
- "src" is the original package
- "dst" is the "aggregate" package that we are creating here
- "map" is a dictionary SRC => TARGET repository mappings
- "repo_check" determines if presence of repos in the source and destination repos is checked
"""
meta_change = False
dst_meta = ''
apiurl = conf.config['apiurl']
repo_map = repo_map or {}
# we need to remove :flavor from the package names when accessing meta
src_package_meta = src_package.split(":")[0]
dst_package_meta = dst_package.split(":")[0]
try:
dst_meta = meta_exists(metatype='pkg',
path_args=(quote_plus(dst_project), quote_plus(dst_package)),
path_args=(quote_plus(dst_project), quote_plus(dst_package_meta)),
template_args=None,
create_new=False, apiurl=apiurl)
root = ET.fromstring(parse_meta_to_string(dst_meta))
@ -5363,9 +5372,37 @@ def aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map =
raise
meta_change = True
if repo_check:
src_repos = set(get_repositories_of_project(apiurl, src_project))
dst_repos = set(get_repositories_of_project(apiurl, dst_project))
if repo_map:
map_from = set(repo_map.keys())
map_to = set(repo_map.values())
# only repos that do not exist in src/dst remain
delta_from = map_from - src_repos
delta_to = map_to - dst_repos
if delta_from or delta_to:
msg = ["The following repos in repo map do not exist"]
if delta_from:
msg += [" Source repos: " + ", ".join(sorted(delta_from))]
if delta_to:
msg += [" Destination repos: " + ", ".join(sorted(delta_to))]
raise oscerr.OscBaseError("\n".join(msg))
else:
# no overlap between src and dst repos leads to the 'broken: missing repositories: <src_project>' message
if not src_repos & dst_repos:
msg = [
"The source and the destination project do not have any repository names in common.",
"Use repo map to specify actual repository mapping.",
]
raise oscerr.OscBaseError("\n".join(msg))
if meta_change:
src_meta = show_package_meta(apiurl, src_project, src_package)
dst_meta = replace_pkg_meta(src_meta, dst_package, dst_project)
src_meta = show_package_meta(apiurl, src_project, src_package_meta)
dst_meta = replace_pkg_meta(src_meta, dst_package_meta, dst_project)
meta_change = True
if disable_publish:
@ -5379,12 +5416,12 @@ def aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map =
dst_meta = ET.tostring(root, encoding=ET_ENCODING)
if meta_change:
edit_meta('pkg',
path_args=(dst_project, dst_package),
path_args=(dst_project, dst_package_meta),
data=dst_meta)
# create the _aggregate file
# but first, make sure not to overwrite an existing one
if '_aggregate' in meta_get_filelist(apiurl, dst_project, dst_package):
if '_aggregate' in meta_get_filelist(apiurl, dst_project, dst_package_meta):
print(file=sys.stderr)
print('_aggregate file already exists...! Aborting', file=sys.stderr)
sys.exit(1)
@ -5413,7 +5450,7 @@ def aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map =
</aggregatelist>
"""
u = makeurl(apiurl, ['source', dst_project, dst_package, '_aggregate'])
u = makeurl(apiurl, ['source', dst_project, dst_package_meta, '_aggregate'])
http_PUT(u, data=aggregate_template)
print('Done.')