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

Use implicit booleaness instead of len() to test if iterables are empty

This commit is contained in:
Daniel Mach 2022-08-29 13:23:29 +02:00
parent ff63226c2f
commit beaf312eee
3 changed files with 26 additions and 26 deletions

View File

@ -33,7 +33,7 @@ class Checker:
except KeyError as e:
print(e)
if not len(self.imported):
if not self.imported:
raise KeyError('', "no key imported")
rpm.delMacro("_dbpath")

View File

@ -3449,7 +3449,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if opts.update_project_attribute:
maintained_update_project_attribute = opts.update_project_attribute
if not len(args) or len(args) > 2:
if not args or len(args) > 2:
raise oscerr.WrongArgs('Wrong number of arguments.')
if len(args) >= 1:
package = args[0]
@ -3732,13 +3732,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
msg = edit_message()
# empty arguments result in recursive project delete ...
if not len(prj):
if not prj:
raise oscerr.WrongArgs('Project argument is empty')
if len(args) > 1:
pkg = args[1]
if not len(pkg):
if not pkg:
raise oscerr.WrongArgs('Package argument is empty')
## FIXME: core.py:commitDelPackage() should have something similar
@ -3816,13 +3816,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
msg = edit_message()
# empty arguments result in recursive project delete ...
if not len(prj):
if not prj:
raise oscerr.WrongArgs('Project argument is empty')
if len(args) > 1:
pkg = args[1]
if not len(pkg):
if not pkg:
raise oscerr.WrongArgs('Package argument is empty')
unlock_package(apiurl, prj, pkg, msg)
@ -6183,7 +6183,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
project = alternative_project or store_read_project('.')
apiurl = self.get_api_url()
repositories = list(get_repos_of_project(apiurl, project))
if not len(repositories):
if not repositories:
raise oscerr.WrongArgs('no repositories defined for project \'%s\'' % project)
if alternative_project is None:
# only persist our own repos
@ -7603,7 +7603,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
requests = get_user_projpkgs_request_list(apiurl, user, projpkgs=request_todo)
for r in sorted(requests, key=lambda x: x.reqid):
print(r.list_view(), '\n')
if not len(requests):
if not requests:
print(" -> try also 'osc my sr' to see more.")
else:
for i in sorted(roles.keys()):
@ -7834,7 +7834,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
result.append(node.get('filepath'))
results.append(result)
if not len(results):
if not results:
print('No matches found for \'%s\' in %ss' % (role_filter or search_term, kind))
continue
# construct a sorted, flat list
@ -8347,7 +8347,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if prj:
# not for user/group search
for role in roles:
if opts.bugowner and not len(maintainers.get(role, [])):
if opts.bugowner and not maintainers.get(role, []):
role = 'maintainer'
if pac:
print("%s%s of %s/%s : " % (indent, role, prj, pac))
@ -8357,7 +8357,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
emails = []
for maintainer in maintainers.get(role, []):
user = get_maintainer_data(apiurl, maintainer, verbose=False)
if len(user):
if user:
emails.append(''.join(user))
print(indent, end=' ')
print(', '.join(emails) or '-')
@ -8806,7 +8806,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
store_write_string(p.absdir, '_pulled', linkinfo_new.get('srcmd5') + '\n')
p.unmark_frozen()
print()
if len(p.in_conflict):
if p.in_conflict:
print('Please fix the conflicts (files marked with \'C\' above),')
print('run \'osc resolved ...\', and commit the changes')
print('to update the link information.')
@ -9076,7 +9076,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
return
section, opt, val = args[0], args[1], args[2:]
if len(val) and (opts.delete or opts.stdin or opts.prompt or opts.no_echo):
if val and (opts.delete or opts.stdin or opts.prompt or opts.no_echo):
raise oscerr.WrongOptions('Sorry, \'--delete\' or \'--stdin\' or \'--prompt\' or \'--no-echo\' ' \
'and the specification of a value argument are mutually exclusive')
elif (opts.prompt or opts.no_echo) and opts.stdin:
@ -9084,7 +9084,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
elif opts.stdin:
# strip lines
val = [i.strip() for i in sys.stdin.readlines() if i.strip()]
if not len(val):
if not val:
raise oscerr.WrongArgs('error: read empty value from stdin')
elif opts.no_echo or opts.prompt:
if opts.no_echo:
@ -9124,7 +9124,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
"""
pacs = findpacs(files)
for p in pacs:
if not len(p.todo):
if not p.todo:
p.todo = p.filenamelist + p.to_be_added
for f in p.todo:
p.revert(f)

View File

@ -894,7 +894,7 @@ class Project:
print('unsupported state')
def update(self, pacs = (), expand_link=False, unexpand_link=False, service_files=False):
if len(pacs):
if pacs:
for pac in pacs:
Package(os.path.join(self.dir, pac), progress_obj=self.progress_obj).update()
else:
@ -988,7 +988,7 @@ class Project:
self.write_packages()
def commit(self, pacs = (), msg = '', files = {}, verbose = False, skip_local_service_run = False, can_branch=False, force=False):
if len(pacs):
if pacs:
try:
for pac in pacs:
todo = []
@ -1553,7 +1553,7 @@ class Package:
if os.path.isdir(tdir):
shutil.rmtree(tdir)
os.mkdir(tdir)
while len(send) and tries:
while send and tries:
for filename in send[:]:
sys.stdout.write('.')
sys.stdout.flush()
@ -1562,7 +1562,7 @@ class Package:
tries -= 1
sfilelist = self.__send_commitlog(msg, filelist)
send = self.commit_get_missing(sfilelist)
if len(send):
if send:
raise oscerr.PackageInternalError(self.prjname, self.name,
'server does not accept filelist:\n%s\nmissing:\n%s\n' \
% (ET.tostring(filelist, encoding=ET_ENCODING), ET.tostring(sfilelist, encoding=ET_ENCODING)))
@ -4304,7 +4304,7 @@ def change_request_state(apiurl, reqid, newstate, message='', supersed=None, for
return root.get('code', 'unknown')
def change_request_state_template(req, newstate):
if not len(req.actions):
if not req.actions:
return ''
action = req.actions[0]
tmpl_name = '%srequest_%s_template' % (action.type, newstate)
@ -4492,7 +4492,7 @@ def get_user_projpkgs_request_list(apiurl, user, req_state=('new', 'review', ),
return []
xpath = ''
for prj, pacs in projpkgs.items():
if not len(pacs):
if not pacs:
xpath = xpath_join(xpath, 'action/target/@project=\'%s\'' % prj, inner=True)
else:
xp = ''
@ -5993,7 +5993,7 @@ def get_prj_results(apiurl, prj, hide_legend=False, csv=False, status_filter=Non
targets_to_show = enabled.keys()
pacs = [ i for i in pacs if i in pacs_to_show ]
if len(targets_to_show):
if targets_to_show:
targets = [ i for i in targets if i in targets_to_show ]
# csv output
@ -6143,7 +6143,7 @@ def streamfile(url, http_meth = http_GET, bufsize=8192, data=None, progress_obj=
read = 0
while True:
data = xread(bufsize)
if not len(data):
if not data:
break
read += len(data)
if progress_obj:
@ -7422,9 +7422,9 @@ def print_request_list(apiurl, project, package = None, states = ('new', 'review
msg = '\nPending requests for %s: %s (%s)'
if sys.stdout.isatty():
msg = f'\033[1m{msg}\033[0m'
if package is None and len(requests):
if package is None and requests:
print(msg % ('project', project, len(requests)))
elif len(requests):
elif requests:
print(msg % ('package', '/'.join([project, package]), len(requests)))
for r in requests:
print(r.list_view(), '\n')
@ -7871,7 +7871,7 @@ def find_default_project(apiurl=None, package=None):
look though the list of conf.config['getpac_default_project']
and find the first project where the given package exists in the build service.
"""
if not len(conf.config['getpac_default_project']):
if not conf.config['getpac_default_project']:
return None
candidates = re.split('[, ]+', conf.config['getpac_default_project'])
if package is None or len(candidates) == 1: