Skip to content

Commit

Permalink
Use findtext() instead of find().text
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmueller committed Sep 11, 2024
1 parent 0302053 commit e217c00
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 44 deletions.
22 changes: 6 additions & 16 deletions osc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self, filename, apiurl, buildtype='spec', localpkgs=None, binarytyp

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(',')))
Expand Down Expand Up @@ -125,20 +125,10 @@ def __init__(self, filename, apiurl, buildtype='spec', localpkgs=None, binarytyp
# 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
Expand All @@ -154,7 +144,7 @@ def __init__(self, filename, apiurl, buildtype='spec', localpkgs=None, binarytyp
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

Expand Down
2 changes: 1 addition & 1 deletion osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6489,7 +6489,7 @@ def _find_last_repo_arch(self, repo=None, fatal=True):
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')
Expand Down
42 changes: 18 additions & 24 deletions osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,7 @@ def __init__(self, review_node):
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__()
Expand Down Expand Up @@ -421,17 +418,15 @@ def __init__(self, history_node):
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.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):
Expand Down Expand Up @@ -471,9 +466,8 @@ def __init__(self, state_node):
# 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')
Expand Down Expand Up @@ -744,14 +738,14 @@ def read(self, root, apiurl=None):
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"""
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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?'}
Expand Down
6 changes: 3 additions & 3 deletions osc/util/repodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ def __versionElement(self):

@_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
Expand All @@ -151,7 +151,7 @@ def epoch(self):

@_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")
Expand Down

0 comments on commit e217c00

Please sign in to comment.