1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 06:46:15 +01:00

Properly test for None

This commit is contained in:
Daniel Mach 2022-08-29 12:56:57 +02:00
parent a4ac558fa6
commit ff63226c2f
6 changed files with 79 additions and 79 deletions

View File

@ -81,7 +81,7 @@ class Buildinfo:
self.apiurl = apiurl
if root.find('error') != None:
if root.find('error') is not None:
sys.stderr.write('buildinfo is broken... it says:\n')
error = root.find('error').text
if error.startswith('unresolvable: '):
@ -118,16 +118,16 @@ class Buildinfo:
# 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') != None:
if root.find('crossarch') is not None:
self.crossarch = root.find('crossarch').text
else:
self.crossarch = None
if root.find('hostarch') != None:
if root.find('hostarch') is not None:
self.hostarch = root.find('hostarch').text
else:
self.hostarch = None
if root.find('release') != None:
if root.find('release') is not None:
self.release = root.find('release').text
else:
self.release = None
@ -141,7 +141,7 @@ class Buildinfo:
self.downloadurl = root.get('downloadurl')
self.debuginfo = 0
if root.find('debuginfo') != None:
if root.find('debuginfo') is not None:
try:
self.debuginfo = int(root.find('debuginfo').text)
except ValueError:
@ -162,7 +162,7 @@ class Buildinfo:
apiurl, localpkgs)
else:
pac_arch = self.crossarch
if pac_arch == None:
if pac_arch is None:
pac_arch = self.buildarch
p = Pac(node, pac_arch, self.pacsuffix,
apiurl, localpkgs)
@ -187,7 +187,7 @@ class Buildinfo:
self.noinstall_list = [ dep.name for dep in self.deps if dep.noinstall ]
self.installonly_list = [ dep.name for dep in self.deps if dep.installonly ]
if root.find('preinstallimage') != None:
if root.find('preinstallimage') is not None:
self.preinstallimage = root.find('preinstallimage')
else:
self.preinstallimage = None
@ -1030,7 +1030,7 @@ def main(apiurl, opts, argv):
# vs.
# arch we are supposed to build for
if vm_type != "emulator" and vm_type != "qemu":
if bi.hostarch != None:
if bi.hostarch is not None:
if hostarch != bi.hostarch and not bi.hostarch in can_also_build.get(hostarch, []):
print('Error: hostarch \'%s\' is required.' % (bi.hostarch), file=sys.stderr)
return 1
@ -1175,7 +1175,7 @@ def main(apiurl, opts, argv):
target_mtime = i.mtime,
progress_meter = True)
if old_pkg_dir != None:
if old_pkg_dir is not None:
buildargs.append('--oldpackages=%s' % old_pkg_dir)
# Make packages from buildinfo available as repos for kiwi/docker/fissile

View File

@ -509,7 +509,7 @@ class Osc(cmdln.Cmdln):
project = self._process_project_name(args[0])
package = args[1]
if project == None or package == None:
if project is None or package is None:
raise oscerr.WrongArgs('Either specify project and package or call it from a package working copy')
query = {'cmd': 'addcontainers'}
@ -1317,7 +1317,7 @@ class Osc(cmdln.Cmdln):
root = ET.parse(f).getroot()
_check_service(root)
linkinfo = root.find('linkinfo')
if linkinfo == None:
if linkinfo is None:
if len(args) < 1:
print("Package ", p, " is not a source link and no target specified.")
sys.exit("This is currently not supported.")
@ -1462,7 +1462,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
f = http_GET(u)
root = ET.parse(f).getroot()
linkinfo = root.find('linkinfo')
if linkinfo == None:
if linkinfo is None:
rev = root.get('rev')
else:
if linkinfo.get('project') != dst_project or linkinfo.get('package') != dst_package:
@ -1543,7 +1543,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
value = []
if not hasattr(parser.values, 'actiondata'):
setattr(parser.values, 'actiondata', [])
if parser.values.actions == None:
if parser.values.actions is None:
parser.values.actions = []
rargs = parser.rargs
@ -1581,7 +1581,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
f = http_GET(u)
root = ET.parse(f).getroot()
linkinfo = root.find('linkinfo')
if linkinfo == None:
if linkinfo is None:
print("Package ", p, " is not a source link.")
sys.exit("This is currently not supported.")
if linkinfo.get('error'):
@ -1751,7 +1751,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
actionxml = """ <action type="add_role"> <target project="%s" package="%s" /> <person name="%s" role="%s" /> </action> """ % \
(project, package, user, role)
if get_user_meta(apiurl, user) == None:
if get_user_meta(apiurl, user) is None:
raise oscerr.WrongArgs('osc: an error occurred.')
return actionxml
@ -1775,7 +1775,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
actionxml = """ <action type="add_role"> <target project="%s" package="%s" /> <person name="%s" role="%s" /> </action> """ % \
(project, package, user, role)
if get_user_meta(apiurl, user) == None:
if get_user_meta(apiurl, user) is None:
raise oscerr.WrongArgs('osc: an error occured.')
return actionxml
@ -1799,7 +1799,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
actionxml = """ <action type="add_role"> <target project="%s" package="%s" /> <group name="%s" role="%s" /> </action> """ % \
(project, package, group, role)
if get_group_meta(apiurl, group) == None:
if get_group_meta(apiurl, group) is None:
raise oscerr.WrongArgs('osc: an error occured.')
return actionxml
@ -1822,12 +1822,12 @@ Please submit there instead, or use --nodevelproject to force direct submission.
group = user.replace('group:', '')
actionxml = """ <action type="set_bugowner"> <target project="%s" %s /> <group name="%s" /> </action> """ % \
(project, package, group)
if get_group_meta(apiurl, group) == None:
if get_group_meta(apiurl, group) is None:
raise oscerr.WrongArgs('osc: an error occurred.')
else:
actionxml = """ <action type="set_bugowner"> <target project="%s" %s /> <person name="%s" /> </action> """ % \
(project, package, user)
if get_user_meta(apiurl, user) == None:
if get_user_meta(apiurl, user) is None:
raise oscerr.WrongArgs('osc: an error occured.')
@ -2689,7 +2689,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
file = http_GET(link_url)
root = ET.parse(file).getroot()
link_node = root.find('linkinfo')
if link_node != None:
if link_node is not None:
links_to_project = link_node.get('project') or project
links_to_package = link_node.get('package') or package
except HTTPError as e:
@ -2917,7 +2917,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if opts.current and not opts.new_package:
rev, vrev = show_upstream_rev_vrev(apiurl, src_project, src_package, expand=True)
if rev == None or len(rev) < 32:
if rev is None or len(rev) < 32:
# vrev is only needed for srcmd5 and OBS instances < 2.1.17 do not support it
vrev = None
@ -3911,7 +3911,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
f = http_GET(u)
root = ET.parse(f).getroot()
linkinfo = root.find('linkinfo')
if linkinfo == None:
if linkinfo is None:
raise oscerr.APIError('package is not a source link')
baserev = linkinfo.get('baserev')
opts.revision = baserev
@ -4532,7 +4532,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
raise oscerr.WrongOptions('-D | --deleted can only be used with a package')
rev, dummy = parseRevisionOption(opts.revision)
if rev == None:
if rev is None:
rev = "latest"
if rev and rev != "latest" and not checkRevision(project, package, rev):
@ -4571,7 +4571,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
show_project_meta(apiurl, project)
scm_url = show_scmsync(apiurl, project)
if scm_url != None:
if scm_url is not None:
if not os.path.isfile('/usr/lib/obs/service/obs_scm_bridge'):
raise oscerr.OscIOError(None, 'Install the obs-scm-bridge package to work on packages managed in scm (git)!')
os.putenv("OSC_VERSION", get_osc_version())
@ -4580,7 +4580,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
Project.init_project(apiurl, prj_dir, project, conf.config['do_package_tracking'], scm_url=scm_url)
print(statfrmt('A', prj_dir))
if scm_url != None:
if scm_url is not None:
return
# all packages
@ -4768,7 +4768,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if opts.recursive:
for pac in prj.pacs_have:
state = prj.get_state(pac)
if state != None and state != 'D':
if state is not None and state != 'D':
pac_dir = getTransActPath(os.path.join(prj.dir, pac))
args.append(pac_dir)
args.remove(arg)
@ -5317,7 +5317,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if len(args) > 1:
package = args[1]
if project == None:
if project is None:
raise oscerr.WrongOptions("No project given")
if opts.failed and opts.status_filter:
@ -5327,7 +5327,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
opts.status_filter = 'failed'
opts.brief = True
if package == None:
if package is None:
opts.hide_legend = None
opts.name_filter = None
opts.show_non_building = None
@ -7356,7 +7356,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
continue
for i in binaries:
if binary != None and binary != i.name:
if binary is not None and binary != i.name:
continue
# skip source rpms
if not opts.sources and (i.name.endswith('.src.rpm') or i.name.endswith('.sdeb')):
@ -7504,13 +7504,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
fp = http_GET(p)
issues = ET.parse(fp).findall('issue')
for issue in issues:
if issue.find('state') == None or issue.find('state').text != "OPEN":
if issue.find('state') is None or issue.find('state').text != "OPEN":
continue
if issue.find('owner') == None or issue.find('owner').find('login').text != user:
if issue.find('owner') is None or issue.find('owner').find('login').text != user:
continue
print(" #", issue.find('label').text, ': ', end=' ')
desc = issue.find('summary')
if desc != None:
if desc is not None:
print(desc.text)
else:
print("\n")
@ -7800,7 +7800,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if not package is None:
result.append(package)
if opts.version and package != None:
if opts.version and package is not None:
sr = get_source_rev(apiurl, project, package)
v = sr.get('version')
r = sr.get('rev')
@ -8204,9 +8204,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
# try the package name first, it is faster and may catch cases where no
# binary with that name exists for the given package name
searchresult = owner(apiurl, search_term, "package", usefilter=filterroles, devel=None, limit=limit)
if searchresult == None or len(searchresult) == 0:
if searchresult is None or len(searchresult) == 0:
searchresult = owner(apiurl, search_term, "binary", usefilter=filterroles, devel=None, limit=limit)
if searchresult != None and len(searchresult) == 0:
if searchresult is not None and len(searchresult) == 0:
# We talk to an OBS 2.4 or later understanding the call
if opts.set_bugowner or opts.set_bugowner_request:
# filtered search did not succeed, but maybe we want to set an owner initially?
@ -8529,9 +8529,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
f = http_GET(u)
root = ET.parse(f).getroot()
linkinfo = root.find('linkinfo')
if linkinfo == None:
if linkinfo is None:
raise oscerr.APIError('package is not a source link')
if linkinfo.get('error') == None:
if linkinfo.get('error') is None:
raise oscerr.APIError('source link is not broken')
workingrev = None
@ -8541,21 +8541,21 @@ Please submit there instead, or use --nodevelproject to force direct submission.
f = http_GET(u)
root = ET.parse(f).getroot()
linkinfo = root.find('linkinfo')
if linkinfo.get('error') == None:
if linkinfo.get('error') is None:
workingrev = linkinfo.get('xsrcmd5')
if workingrev == None:
if workingrev is None:
query = { 'lastworking': 1 }
u = makeurl(apiurl, ['source', prj, package], query=query)
f = http_GET(u)
root = ET.parse(f).getroot()
linkinfo = root.find('linkinfo')
if linkinfo == None:
if linkinfo is None:
raise oscerr.APIError('package is not a source link')
if linkinfo.get('error') == None:
if linkinfo.get('error') is None:
raise oscerr.APIError('source link is not broken')
workingrev = linkinfo.get('lastworking')
if workingrev == None:
if workingrev is None:
raise oscerr.APIError('source link never worked')
print("using last working link target")
else:
@ -8575,9 +8575,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
f = http_GET(u)
root_oldpatched = ET.parse(f).getroot()
linkinfo_oldpatched = root_oldpatched.find('linkinfo')
if linkinfo_oldpatched == None:
if linkinfo_oldpatched is None:
raise oscerr.APIError('working rev is not a source link?')
if linkinfo_oldpatched.get('error') != None:
if linkinfo_oldpatched.get('error') is not None:
raise oscerr.APIError('working rev is not working?')
dir_oldpatched = { 'apiurl': apiurl, 'project': prj, 'package': package }
dir_oldpatched['srcmd5'] = root_oldpatched.get('srcmd5')
@ -8709,7 +8709,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
raise oscerr.WrongArgs('osc pull only works on expanded links.')
linkinfo = p.linkinfo
baserev = linkinfo.baserev
if baserev == None:
if baserev is None:
raise oscerr.WrongArgs('osc pull only works on links containing a base revision.')
# get revisions we need
@ -8719,9 +8719,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
meta = f.readlines()
root_new = ET.fromstring(b''.join(meta))
linkinfo_new = root_new.find('linkinfo')
if linkinfo_new == None:
if linkinfo_new is None:
raise oscerr.APIError('link is not a really a link?')
if linkinfo_new.get('error') != None:
if linkinfo_new.get('error') is not None:
raise oscerr.APIError('link target is broken')
if linkinfo_new.get('srcmd5') == baserev:
print("Already up-to-date.")

View File

@ -431,7 +431,7 @@ your credentials for this apiurl.
def parse_apisrv_url(scheme, apisrv):
if apisrv.startswith('http://') or apisrv.startswith('https://'):
url = apisrv
elif scheme != None:
elif scheme is not None:
url = scheme + apisrv
else:
url = "https://" + apisrv

View File

@ -423,7 +423,7 @@ class Serviceinfo:
os.putenv("OSC_VERSION", get_osc_version())
# set environment when using OBS 2.3 or later
if self.project != None:
if self.project is not None:
# These need to be kept in sync with bs_service
os.putenv("OBS_SERVICE_APIURL", self.apiurl)
os.putenv("OBS_SERVICE_PROJECT", self.project)
@ -499,7 +499,7 @@ class Linkinfo:
elementtree node.
If the passed element is ``None``, the method does nothing.
"""
if linkinfo_node == None:
if linkinfo_node is None:
return
self.project = linkinfo_node.get('project')
self.package = linkinfo_node.get('package')
@ -698,7 +698,7 @@ class Project:
global store
dirty_files = []
req_storefiles = Project.REQ_STOREFILES
if conf.config['do_package_tracking'] and self.scm_url == None:
if conf.config['do_package_tracking'] and self.scm_url is None:
req_storefiles += ('_packages',)
for fname in req_storefiles:
if not os.path.exists(os.path.join(self.absdir, store, fname)):
@ -779,7 +779,7 @@ class Project:
def set_state(self, pac, state):
node = self.get_package_node(pac)
if node == None:
if node is None:
self.new_package_entry(pac, state)
else:
node.set('state', state)
@ -797,7 +797,7 @@ class Project:
def get_state(self, pac):
node = self.get_package_node(pac)
if node != None:
if node is not None:
return node.get('state')
else:
return None
@ -845,7 +845,7 @@ class Project:
msg = 'invalid package name: \'%s\' (see \'exclude_glob\' config option)' % pac
raise oscerr.OscIOError(None, msg)
state = self.get_state(pac)
if state == None or state == 'D':
if state is None or state == 'D':
self.new_package_entry(pac, 'A')
self.write_packages()
# sometimes the new pac doesn't exist in the list because
@ -888,7 +888,7 @@ class Project:
print(statfrmt('D', pac.name))
else:
print('package \'%s\' has local modifications (see osc st for details)' % pac.name)
elif state == None:
elif state is None:
print('package is not under version control')
else:
print('unsupported state')
@ -932,7 +932,7 @@ class Project:
p = Package(os.path.join(self.dir, pac), progress_obj=self.progress_obj)
rev = None
needs_update = True
if p.scm_url != None:
if p.scm_url is not None:
# git managed.
print("Skipping git managed package ", pac)
continue
@ -1011,7 +1011,7 @@ class Project:
print('osc: \'%s\' is not under version control' % pac)
elif pac in self.pacs_broken or not os.path.exists(os.path.join(self.dir, pac)):
print('osc: \'%s\' package not found' % pac)
elif state == None:
elif state is None:
self.commitExtPackage(pac, msg, todo, verbose=verbose, skip_local_service_run=skip_local_service_run)
finally:
self.write_packages()
@ -2161,7 +2161,7 @@ rev: %s
root.find('title').text = self.summary
root.find('description').text = ''.join(self.descr)
url = root.find('url')
if url == None:
if url is None:
url = ET.SubElement(root, 'url')
url.text = self.url
@ -2671,7 +2671,7 @@ class Action:
Examples::
r = Action('set_bugowner', tgt_project='foo', person_name='buguser')
# available attributes: r.type (== 'set_bugowner'), r.tgt_project (== 'foo'), r.tgt_package (== None)
# available attributes: r.type (== 'set_bugowner'), r.tgt_project (== 'foo'), r.tgt_package (is None)
r.to_str() ->
<action type="set_bugowner">
<target project="foo" />
@ -3893,7 +3893,7 @@ def show_upstream_srcmd5(apiurl, prj, pac, expand=False, revision=None, meta=Fal
if include_service_files:
try:
sinfo = et.find('serviceinfo')
if sinfo != None and sinfo.get('xsrcmd5') and not sinfo.get('error'):
if sinfo is not None and sinfo.get('xsrcmd5') and not sinfo.get('error'):
return sinfo.get('xsrcmd5')
except:
pass
@ -3965,7 +3965,7 @@ def show_upstream_rev(apiurl, prj, pac, revision=None, expand=False, linkrev=Non
if include_service_files:
try:
sinfo = et.find('serviceinfo')
if sinfo != None and sinfo.get('xsrcmd5') and not sinfo.get('error'):
if sinfo is not None and sinfo.get('xsrcmd5') and not sinfo.get('error'):
return sinfo.get('xsrcmd5')
except:
pass
@ -4610,7 +4610,7 @@ def get_user_meta(apiurl, user):
def _get_xml_data(meta, *tags):
data = []
if meta != None:
if meta is not None:
root = ET.fromstring(meta)
for tag in tags:
elm = root.find(tag)
@ -5057,7 +5057,7 @@ def checkout_package(apiurl, project, package,
# exists
meta_data = b''.join(show_package_meta(apiurl, quote_plus(project), quote_plus(package)))
root = ET.fromstring(meta_data)
if root.find('scmsync') != None and root.find('scmsync').text != None:
if root.find('scmsync') is not None and root.find('scmsync').text is not None:
if not os.path.isfile('/usr/lib/obs/service/obs_scm_bridge'):
raise oscerr.OscIOError(None, 'Install the obs-scm-bridge package to work on packages managed in scm (git)!')
scm_url = root.find('scmsync').text
@ -5918,7 +5918,7 @@ def get_prj_results(apiurl, prj, hide_legend=False, csv=False, status_filter=Non
targets = []
# {package: {(repo,arch): status}}
status = {}
if root.find('result') == None:
if root.find('result') is None:
return []
for results in root.findall('result'):
for node in results:
@ -6300,7 +6300,7 @@ def get_source_rev(apiurl, project, package, revision=None):
def get_buildhistory(apiurl, prj, package, repository, arch, format = 'text', limit = None):
import time
query = {}
if limit != None and int(limit) > 0:
if limit is not None and int(limit) > 0:
query['limit'] = int(limit)
u = makeurl(apiurl, ['build', prj, repository, arch, package, '_history'], query)
f = http_GET(u)
@ -6315,7 +6315,7 @@ def get_buildhistory(apiurl, prj, package, repository, arch, format = 'text', li
duration = node.get('duration')
t = time.gmtime(int(node.get('time')))
t = time.strftime('%Y-%m-%d %H:%M:%S', t)
if duration == None:
if duration is None:
duration = ""
if format == 'csv':
@ -6334,7 +6334,7 @@ def print_jobhistory(apiurl, prj, current_package, repository, arch, format = 't
query = {}
if current_package:
query['package'] = current_package
if limit != None and int(limit) > 0:
if limit is not None and int(limit) > 0:
query['limit'] = int(limit)
u = makeurl(apiurl, ['build', prj, repository, arch, '_jobhistory'], query )
f = http_GET(u)
@ -6866,9 +6866,9 @@ def owner(apiurl, search_term=None, mode="binary", attribute=None,
query['project'] = project
if devel:
query['devel'] = devel
if limit != None:
if limit is not None:
query['limit'] = limit
if usefilter != None:
if usefilter is not None:
query['filter'] = ",".join(usefilter)
u = makeurl(apiurl, [ 'search', 'owner' ], query)
res = None
@ -7027,7 +7027,7 @@ def addPerson(apiurl, prj, pac, user, role="maintainer"):
template_args=None,
create_new=False)
if data and get_user_meta(apiurl, user) != None:
if data and get_user_meta(apiurl, user) is not None:
root = ET.fromstring(parse_meta_to_string(data))
found = False
for person in root.getiterator('person'):
@ -7060,7 +7060,7 @@ def delPerson(apiurl, prj, pac, user, role="maintainer"):
path_args=path,
template_args=None,
create_new=False)
if data and get_user_meta(apiurl, user) != None:
if data and get_user_meta(apiurl, user) is not None:
root = ET.fromstring(parse_meta_to_string(data))
found = False
for person in root.getiterator('person'):
@ -7117,9 +7117,9 @@ def setDevelProject(apiurl, prj, pac, dprj, dpkg=None):
template_args=None,
create_new=False)
if data and show_project_meta(apiurl, dprj) != None:
if data and show_project_meta(apiurl, dprj) is not None:
root = ET.fromstring(parse_meta_to_string(data))
if not root.find('devel') != None:
if not root.find('devel') is not None:
ET.SubElement(root, 'devel')
elem = root.find('devel')
if dprj:
@ -7162,7 +7162,7 @@ def createPackageDir(pathname, prj_obj=None):
def stripETxml(node):
node.tail = None
if node.text != None:
if node.text is not None:
node.text = node.text.replace(" ", "").replace("\n", "")
for child in node:
stripETxml(child)

View File

@ -97,9 +97,9 @@ class Ar:
re.DOTALL)
def __init__(self, fn = None, fh = None):
if fn == None and fh == None:
raise ValueError('either \'fn\' or \'fh\' must be != None')
if fh != None:
if fn is None and fh is None:
raise ValueError('either \'fn\' or \'fh\' must be is not None')
if fh is not None:
self.__file = fh
self.__closefile = False
self.filename = fh.name

View File

@ -51,14 +51,14 @@ class ArchQuery(packagequery.PackageQuery, packagequery.PackageQueryResult):
def version(self):
pkgver = self.fields['pkgver'][0] if 'pkgver' in self.fields else None
if pkgver != None:
if pkgver is not None:
pkgver = re.sub(br'[0-9]+:', b'', pkgver, 1)
pkgver = re.sub(br'-[^-]*$', b'', pkgver)
return pkgver
def release(self):
pkgver = self.fields['pkgver'][0] if 'pkgver' in self.fields else None
if pkgver != None:
if pkgver is not None:
m = re.search(br'-([^-])*$', pkgver)
if m:
return m.group(1)