1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-08 13:56:15 +01:00

Merge pull request #1627 from dirkmueller/use_findtext

Use findtext() instead of find().text
This commit is contained in:
Daniel Mach 2024-09-16 13:46:57 +02:00 committed by GitHub
commit 1951bb4648
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 46 deletions

View File

@ -91,7 +91,7 @@ class Buildinfo:
if root.find('error') is not None:
sys.stderr.write('buildinfo is broken... it says:\n')
error = root.find('error').text
error = root.findtext("error")
if error.startswith('unresolvable: '):
sys.stderr.write('unresolvable: ')
sys.stderr.write('\n '.join(error[14:].split(',')))
@ -125,20 +125,10 @@ class Buildinfo:
# buildarch: The architecture of the build result (host arch in GNU definition)
# hostarch: The architecture of the build environment (build arch in GNU defintion)
# crossarch: Same as hostarch, but indicating that a sysroot with an incompatible architecture exists
self.buildarch = root.find('arch').text
if root.find('crossarch') is not None:
self.crossarch = root.find('crossarch').text
else:
self.crossarch = None
if root.find('hostarch') is not None:
self.hostarch = root.find('hostarch').text
else:
self.hostarch = None
if root.find('release') is not None:
self.release = root.find('release').text
else:
self.release = None
self.buildarch = root.findtext("arch")
self.crossarch = root.findtext("crossarch")
self.hostarch = root.findtext("hostarch")
self.release = root.findtext("release")
if conf.config['api_host_options'][apiurl]['downloadurl']:
# Formerly, this was set to False, but we have to set it to True, because a large
# number of repos in OBS are misconfigured and don't actually have repos setup - they
@ -154,7 +144,7 @@ class Buildinfo:
self.debuginfo = 0
if root.find('debuginfo') is not None:
try:
self.debuginfo = int(root.find('debuginfo').text)
self.debuginfo = int(root.findtext("debuginfo"))
except ValueError:
pass
@ -718,7 +708,7 @@ def create_build_descr_data(
if topdir:
buildenv_file = os.path.join(topdir, f"_buildenv.{repo}.{arch}")
if not os.path.isfile(buildenv_file):
buildenv_file = os.path.join(topdir, f"_buildenv")
buildenv_file = os.path.join(topdir, "_buildenv")
if os.path.isfile(buildenv_file):
print(f"Using local file: {os.path.basename(buildenv_file)}", file=sys.stderr)
with open(buildenv_file, "rb") as f:

View File

@ -6489,7 +6489,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
cfg = f
root = ET.parse(cfg).getroot()
repo = root.get("repository")
arch = root.find("arch").text
arch = root.findtext("arch")
return repo, arch
@cmdln.alias('lbl')

View File

@ -381,10 +381,7 @@ class ReviewState(AbstractState):
self.by_package = review_node.get('by_package')
self.who = review_node.get('who')
self.when = review_node.get('when')
self.comment = ''
if not review_node.find('comment') is None and \
review_node.find('comment').text:
self.comment = review_node.find('comment').text.strip()
self.comment = review_node.findtext("comment", default="").strip()
def __repr__(self):
result = super().__repr__()
@ -421,17 +418,15 @@ class RequestHistory(AbstractState):
super().__init__(history_node.tag)
self.who = history_node.get('who')
self.when = history_node.get('when')
if not history_node.find('description') is None and \
history_node.find('description').text:
if history_node.find('description') is not None:
# OBS 2.6
self.description = history_node.find('description').text.strip()
self.description = history_node.findtext("description").strip()
else:
# OBS 2.5 and before
self.description = history_node.get('name')
self.description = history_node.get("name")
self.comment = ''
if not history_node.find('comment') is None and \
history_node.find('comment').text:
self.comment = history_node.find('comment').text.strip()
if history_node.find("comment") is not None:
self.comment = history_node.findtext("comment").strip()
self.name = self._parse_name(history_node)
def _parse_name(self, history_node):
@ -471,9 +466,8 @@ class RequestState(AbstractState):
# OBS 2.6 has it always, before it did not exist
self.description = state_node.get('description')
self.comment = ''
if not state_node.find('comment') is None and \
state_node.find('comment').text:
self.comment = state_node.find('comment').text.strip()
if state_node.find('comment') is not None:
self.comment = state_node.findtext("comment").strip()
def get_node_attrs(self):
return ('name', 'who', 'when', 'approver')
@ -744,14 +738,14 @@ class Request:
self.reviews.append(ReviewState(review))
for history_element in root.findall('history'):
self.statehistory.append(RequestHistory(history_element))
if not root.find('priority') is None and root.find('priority').text:
self.priority = root.find('priority').text.strip()
if not root.find('accept_at') is None and root.find('accept_at').text:
self.accept_at = root.find('accept_at').text.strip()
if not root.find('title') is None:
self.title = root.find('title').text.strip()
if not root.find('description') is None and root.find('description').text:
self.description = root.find('description').text.strip()
if root.findtext("priority"):
self.priority = root.findtext("priority").strip()
if root.findtext("accept_at"):
self.accept_at = root.findtext("accept_at").strip()
if root.findtext("title"):
self.title = root.findtext("title").strip()
if root.findtext("description"):
self.description = root.findtext("description").strip()
def add_action(self, type, **kwargs):
"""add a new action to the request"""
@ -3030,10 +3024,10 @@ def submit_action_diff(apiurl: str, action: Action):
if e.code != 404:
raise e
root = ET.fromstring(e.read())
return b'error: \'%s\' does not exist' % root.find('summary').text.encode()
return b'error: \'%s\' does not exist' % root.findtext("summary").encode()
elif e.code == 404:
root = ET.fromstring(e.read())
return b'error: \'%s\' does not exist' % root.find('summary').text.encode()
return b'error: \'%s\' does not exist' % root.findtext("summary").encode()
raise e
@ -4675,7 +4669,7 @@ def get_source_rev(apiurl: str, project: str, package: str, revision=None):
# remember the newest one.
if not ent:
ent = new
elif ent.find('time').text < new.find('time').text:
elif ent.findtext("time") < new.findtext("time"):
ent = new
if not ent:
return {'version': None, 'error': 'empty revisionlist: no such package?'}

View File

@ -136,11 +136,11 @@ class RepoDataQueryResult(packagequery.PackageQueryResult):
@_to_bytes_or_None
def arch(self):
return self.__element.find(namespace("common") + "arch").text
return self.__element.findtext(namespace("common") + "arch")
@_to_bytes_or_None
def description(self):
return self.__element.find(namespace("common") + "description").text
return self.__element.findtext(namespace("common") + "description")
def distribution(self):
return None
@ -151,7 +151,7 @@ class RepoDataQueryResult(packagequery.PackageQueryResult):
@_to_bytes_or_None
def name(self):
return self.__element.find(namespace("common") + "name").text
return self.__element.findtext(namespace("common") + "name")
def path(self):
locationElement = self.__element.find(namespace("common") + "location")