1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-26 09:56:13 +01:00

Handle bytes vs. str error when parsing meta (#683)

In all the cases where meta_exists returns either
string data, bytes data or a list, the output needs
to be parsed correctly.

Signed-off-by: Kristoffer Grönlund <kgronlund@suse.com>
This commit is contained in:
Kristoffer Grönlund 2019-11-18 09:36:09 +01:00
parent 19b86e4708
commit 16a3fcfabf
2 changed files with 21 additions and 20 deletions

View File

@ -7973,7 +7973,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
'name': pac,
'user': user}), apiurl=apiurl)
if data:
data = ET.fromstring(''.join(data))
data = ET.fromstring(parse_meta_to_string(data))
data.find('title').text = ''.join(title)
data.find('description').text = ''.join(descr)
data.find('url').text = url

View File

@ -3802,6 +3802,19 @@ def make_meta_url(metatype, path_args=None, apiurl=None, force=False, remove_lin
return makeurl(apiurl, [path], query)
def parse_meta_to_string(data):
"""
Converts the output of meta_exists into a string value
"""
# data can be a bytes object, a list with strings, a list with bytes, just a string.
# So we need the following even if it is ugly.
if sys.version_info >= (3, 0):
if isinstance(data, bytes):
data = decode_it(data)
elif isinstance(data, list):
data = decode_list(data)
return ''.join(data)
def edit_meta(metatype,
path_args=None,
@ -3831,19 +3844,7 @@ def edit_meta(metatype,
if metatype == 'pkg':
# check if the package is a link to a different project
project, package = path_args
# data can be a bytes object, a list with strings, a list with bytes, just a string.
# So we need the following even if it is ugly.
if sys.version_info >= (3, 0):
if isinstance(data, bytes):
data = decode_it(data)
orgprj = ET.fromstring(''.join(data)).get('project')
elif isinstance(data, list):
decode_data = decode_list(data)
orgprj = ET.fromstring(''.join(decode_data)).get('project')
else:
orgprj = ET.fromstring(''.join(data)).get('project')
else:
orgprj = ET.fromstring(''.join(data)).get('project')
orgprj = ET.fromstring(parse_meta_to_string(data)).get('project')
if orgprj is not None and unquote(project) != orgprj:
print('The package is linked from a different project.')
@ -5142,7 +5143,7 @@ def link_pac(src_project, src_package, dst_project, dst_package, force, rev='',
path_args=(quote_plus(dst_project), quote_plus(dst_package)),
template_args=None,
create_new=False, apiurl=apiurl)
root = ET.fromstring(b''.join(dst_meta))
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
@ -5237,7 +5238,7 @@ def aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map =
path_args=(quote_plus(dst_project), quote_plus(dst_package)),
template_args=None,
create_new=False, apiurl=apiurl)
root = ET.fromstring(b''.join(dst_meta))
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
@ -6939,7 +6940,7 @@ def addPerson(apiurl, prj, pac, user, role="maintainer"):
create_new=False)
if data and get_user_meta(apiurl, user) != None:
root = ET.fromstring(b''.join(data))
root = ET.fromstring(parse_meta_to_string(data))
found = False
for person in root.getiterator('person'):
if person.get('userid') == user and person.get('role') == role:
@ -6972,7 +6973,7 @@ def delPerson(apiurl, prj, pac, user, role="maintainer"):
template_args=None,
create_new=False)
if data and get_user_meta(apiurl, user) != None:
root = ET.fromstring(''.join(data))
root = ET.fromstring(parse_meta_to_string(data))
found = False
for person in root.getiterator('person'):
if person.get('userid') == user and person.get('role') == role:
@ -7003,7 +7004,7 @@ def setBugowner(apiurl, prj, pac, user=None, group=None):
group=user.replace('group:', '')
user=None
if data:
root = ET.fromstring(b''.join(data))
root = ET.fromstring(parse_meta_to_string(data))
for group_element in root.getiterator('group'):
if group_element.get('role') == "bugowner":
root.remove(group_element)
@ -7029,7 +7030,7 @@ def setDevelProject(apiurl, prj, pac, dprj, dpkg=None):
create_new=False)
if data and show_project_meta(apiurl, dprj) != None:
root = ET.fromstring(''.join(data))
root = ET.fromstring(parse_meta_to_string(data))
if not root.find('devel') != None:
ET.SubElement(root, 'devel')
elem = root.find('devel')