1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-09 20:45:47 +01:00

Fix another bytes/unicode issues in core.link_pac() by replacing ElementTree code with XML models

This commit is contained in:
Daniel Mach 2024-11-29 15:49:20 +01:00
parent 33c67cac04
commit 6989fb8b6f
2 changed files with 29 additions and 42 deletions

View File

@ -39,3 +39,5 @@ Scenario: Run `osc linkpac on a locked package`
Given I execute osc with args "lock test:factory/test-pkgA" Given I execute osc with args "lock test:factory/test-pkgA"
When I execute osc with args "linkpac test:factory/test-pkgA home:Admin/test-pkgA" When I execute osc with args "linkpac test:factory/test-pkgA home:Admin/test-pkgA"
Then the exit code is 0 Then the exit code is 0
And I execute osc with args "api /source/home:Admin/test-pkgA/_meta"
And stdout doesn't contain "<lock>\s*<enable/>\s*</lock>"

View File

@ -3270,66 +3270,51 @@ def link_pac(
- "src" is the original package - "src" is the original package
- "dst" is the "link" package that we are creating here - "dst" is the "link" package that we are creating here
""" """
from . import obs_api
if src_project == dst_project and src_package == dst_package: if src_project == dst_project and src_package == dst_package:
raise oscerr.OscValueError("Cannot link package. Source and target are the same.") raise oscerr.OscValueError("Cannot link package. Source and target are the same.")
if not revision_is_empty(rev) and not checkRevision(src_project, src_package, rev): if not revision_is_empty(rev) and not checkRevision(src_project, src_package, rev):
raise oscerr.OscValueError(f"Revision doesn't exist: {rev}") raise oscerr.OscValueError(f"Revision doesn't exist: {rev}")
meta_change = False apiurl = conf.config["apiurl"]
dst_meta = ''
apiurl = conf.config['apiurl'] src_package_obj = obs_api.Package.from_api(apiurl, src_project, src_package)
try: try:
dst_meta = meta_exists(metatype='pkg', dst_package_obj = obs_api.Package.from_api(apiurl, dst_project, dst_package)
path_args=(dst_project, dst_package),
template_args=None,
create_new=False, apiurl=apiurl)
root = ET.fromstring(parse_meta_to_string(dst_meta))
if root.get('project') != dst_project:
# The source comes from a different project via a project link, we need to create this instance
meta_change = True
except HTTPError as e: except HTTPError as e:
if e.code != 404: if e.code != 404:
raise raise
meta_change = True
if meta_change:
if missing_target: if missing_target:
dst_meta = f'<package name="{dst_package}"><title/><description/></package>' # we start with empty values because we want has_changed() to return True
dst_package_obj = obs_api.Package(project="", name="")
else: else:
src_meta = show_package_meta(apiurl, src_project, src_package) dst_package_obj = copy.deepcopy(src_package_obj)
dst_meta = replace_pkg_meta(src_meta, dst_package, dst_project)
if disable_build or disable_publish: # purging unwanted fields; see also replace_pkg_meta()
meta_change = True # TODO: create Package.clone() or .copy() method instead of this
root = ET.fromstring(b"".join(dst_meta)) dst_package_obj.devel = None
dst_package_obj.group_list = []
dst_package_obj.lock = None
dst_package_obj.person_list = []
dst_package_obj.releasename = None
dst_package_obj.scmsync = None
if disable_build: dst_package_obj.project = dst_project
elm = root.find('build') dst_package_obj.name = dst_package
if not elm:
elm = ET.SubElement(root, 'build')
elm.clear()
ET.SubElement(elm, 'disable')
if disable_publish: if disable_build:
elm = root.find('publish') dst_package_obj.build_list = [{"flag": "disable"}]
if not elm:
elm = ET.SubElement(root, 'publish')
elm.clear()
ET.SubElement(elm, 'disable')
elm = root.find("scmsync") if disable_publish:
if elm is not None: dst_package_obj.publish_list = [{"flag": "disable"}]
root.remove(elm)
dst_meta = ET.tostring(root, encoding=ET_ENCODING) if dst_package_obj.has_changed():
dst_package_obj.to_api(apiurl)
dst_package_obj.scmsync = None
if meta_change:
root = ET.fromstring(''.join(dst_meta))
for scmsync in root.findall('scmsync'):
root.remove(scmsync)
edit_meta('pkg',
path_args=(dst_project, dst_package),
data=ET.tostring(root, encoding=ET_ENCODING))
# create the _link file # create the _link file
# but first, make sure not to overwrite an existing one # but first, make sure not to overwrite an existing one
if '_link' in meta_get_filelist(apiurl, dst_project, dst_package): if '_link' in meta_get_filelist(apiurl, dst_project, dst_package):