mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-27 10:16:14 +01:00
Use implicit booleaness instead of len() to test if iterables are empty
This commit is contained in:
parent
ff63226c2f
commit
beaf312eee
@ -33,7 +33,7 @@ class Checker:
|
|||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
if not len(self.imported):
|
if not self.imported:
|
||||||
raise KeyError('', "no key imported")
|
raise KeyError('', "no key imported")
|
||||||
|
|
||||||
rpm.delMacro("_dbpath")
|
rpm.delMacro("_dbpath")
|
||||||
|
@ -3449,7 +3449,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
if opts.update_project_attribute:
|
if opts.update_project_attribute:
|
||||||
maintained_update_project_attribute = 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.')
|
raise oscerr.WrongArgs('Wrong number of arguments.')
|
||||||
if len(args) >= 1:
|
if len(args) >= 1:
|
||||||
package = args[0]
|
package = args[0]
|
||||||
@ -3732,13 +3732,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
msg = edit_message()
|
msg = edit_message()
|
||||||
|
|
||||||
# empty arguments result in recursive project delete ...
|
# empty arguments result in recursive project delete ...
|
||||||
if not len(prj):
|
if not prj:
|
||||||
raise oscerr.WrongArgs('Project argument is empty')
|
raise oscerr.WrongArgs('Project argument is empty')
|
||||||
|
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
pkg = args[1]
|
pkg = args[1]
|
||||||
|
|
||||||
if not len(pkg):
|
if not pkg:
|
||||||
raise oscerr.WrongArgs('Package argument is empty')
|
raise oscerr.WrongArgs('Package argument is empty')
|
||||||
|
|
||||||
## FIXME: core.py:commitDelPackage() should have something similar
|
## 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()
|
msg = edit_message()
|
||||||
|
|
||||||
# empty arguments result in recursive project delete ...
|
# empty arguments result in recursive project delete ...
|
||||||
if not len(prj):
|
if not prj:
|
||||||
raise oscerr.WrongArgs('Project argument is empty')
|
raise oscerr.WrongArgs('Project argument is empty')
|
||||||
|
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
pkg = args[1]
|
pkg = args[1]
|
||||||
|
|
||||||
if not len(pkg):
|
if not pkg:
|
||||||
raise oscerr.WrongArgs('Package argument is empty')
|
raise oscerr.WrongArgs('Package argument is empty')
|
||||||
|
|
||||||
unlock_package(apiurl, prj, pkg, msg)
|
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('.')
|
project = alternative_project or store_read_project('.')
|
||||||
apiurl = self.get_api_url()
|
apiurl = self.get_api_url()
|
||||||
repositories = list(get_repos_of_project(apiurl, project))
|
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)
|
raise oscerr.WrongArgs('no repositories defined for project \'%s\'' % project)
|
||||||
if alternative_project is None:
|
if alternative_project is None:
|
||||||
# only persist our own repos
|
# 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)
|
requests = get_user_projpkgs_request_list(apiurl, user, projpkgs=request_todo)
|
||||||
for r in sorted(requests, key=lambda x: x.reqid):
|
for r in sorted(requests, key=lambda x: x.reqid):
|
||||||
print(r.list_view(), '\n')
|
print(r.list_view(), '\n')
|
||||||
if not len(requests):
|
if not requests:
|
||||||
print(" -> try also 'osc my sr' to see more.")
|
print(" -> try also 'osc my sr' to see more.")
|
||||||
else:
|
else:
|
||||||
for i in sorted(roles.keys()):
|
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'))
|
result.append(node.get('filepath'))
|
||||||
results.append(result)
|
results.append(result)
|
||||||
|
|
||||||
if not len(results):
|
if not results:
|
||||||
print('No matches found for \'%s\' in %ss' % (role_filter or search_term, kind))
|
print('No matches found for \'%s\' in %ss' % (role_filter or search_term, kind))
|
||||||
continue
|
continue
|
||||||
# construct a sorted, flat list
|
# construct a sorted, flat list
|
||||||
@ -8347,7 +8347,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
if prj:
|
if prj:
|
||||||
# not for user/group search
|
# not for user/group search
|
||||||
for role in roles:
|
for role in roles:
|
||||||
if opts.bugowner and not len(maintainers.get(role, [])):
|
if opts.bugowner and not maintainers.get(role, []):
|
||||||
role = 'maintainer'
|
role = 'maintainer'
|
||||||
if pac:
|
if pac:
|
||||||
print("%s%s of %s/%s : " % (indent, role, prj, 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 = []
|
emails = []
|
||||||
for maintainer in maintainers.get(role, []):
|
for maintainer in maintainers.get(role, []):
|
||||||
user = get_maintainer_data(apiurl, maintainer, verbose=False)
|
user = get_maintainer_data(apiurl, maintainer, verbose=False)
|
||||||
if len(user):
|
if user:
|
||||||
emails.append(''.join(user))
|
emails.append(''.join(user))
|
||||||
print(indent, end=' ')
|
print(indent, end=' ')
|
||||||
print(', '.join(emails) or '-')
|
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')
|
store_write_string(p.absdir, '_pulled', linkinfo_new.get('srcmd5') + '\n')
|
||||||
p.unmark_frozen()
|
p.unmark_frozen()
|
||||||
print()
|
print()
|
||||||
if len(p.in_conflict):
|
if p.in_conflict:
|
||||||
print('Please fix the conflicts (files marked with \'C\' above),')
|
print('Please fix the conflicts (files marked with \'C\' above),')
|
||||||
print('run \'osc resolved ...\', and commit the changes')
|
print('run \'osc resolved ...\', and commit the changes')
|
||||||
print('to update the link information.')
|
print('to update the link information.')
|
||||||
@ -9076,7 +9076,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
return
|
return
|
||||||
|
|
||||||
section, opt, val = args[0], args[1], args[2:]
|
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\' ' \
|
raise oscerr.WrongOptions('Sorry, \'--delete\' or \'--stdin\' or \'--prompt\' or \'--no-echo\' ' \
|
||||||
'and the specification of a value argument are mutually exclusive')
|
'and the specification of a value argument are mutually exclusive')
|
||||||
elif (opts.prompt or opts.no_echo) and opts.stdin:
|
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:
|
elif opts.stdin:
|
||||||
# strip lines
|
# strip lines
|
||||||
val = [i.strip() for i in sys.stdin.readlines() if i.strip()]
|
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')
|
raise oscerr.WrongArgs('error: read empty value from stdin')
|
||||||
elif opts.no_echo or opts.prompt:
|
elif opts.no_echo or opts.prompt:
|
||||||
if opts.no_echo:
|
if opts.no_echo:
|
||||||
@ -9124,7 +9124,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
"""
|
"""
|
||||||
pacs = findpacs(files)
|
pacs = findpacs(files)
|
||||||
for p in pacs:
|
for p in pacs:
|
||||||
if not len(p.todo):
|
if not p.todo:
|
||||||
p.todo = p.filenamelist + p.to_be_added
|
p.todo = p.filenamelist + p.to_be_added
|
||||||
for f in p.todo:
|
for f in p.todo:
|
||||||
p.revert(f)
|
p.revert(f)
|
||||||
|
22
osc/core.py
22
osc/core.py
@ -894,7 +894,7 @@ class Project:
|
|||||||
print('unsupported state')
|
print('unsupported state')
|
||||||
|
|
||||||
def update(self, pacs = (), expand_link=False, unexpand_link=False, service_files=False):
|
def update(self, pacs = (), expand_link=False, unexpand_link=False, service_files=False):
|
||||||
if len(pacs):
|
if pacs:
|
||||||
for pac in pacs:
|
for pac in pacs:
|
||||||
Package(os.path.join(self.dir, pac), progress_obj=self.progress_obj).update()
|
Package(os.path.join(self.dir, pac), progress_obj=self.progress_obj).update()
|
||||||
else:
|
else:
|
||||||
@ -988,7 +988,7 @@ class Project:
|
|||||||
self.write_packages()
|
self.write_packages()
|
||||||
|
|
||||||
def commit(self, pacs = (), msg = '', files = {}, verbose = False, skip_local_service_run = False, can_branch=False, force=False):
|
def commit(self, pacs = (), msg = '', files = {}, verbose = False, skip_local_service_run = False, can_branch=False, force=False):
|
||||||
if len(pacs):
|
if pacs:
|
||||||
try:
|
try:
|
||||||
for pac in pacs:
|
for pac in pacs:
|
||||||
todo = []
|
todo = []
|
||||||
@ -1553,7 +1553,7 @@ class Package:
|
|||||||
if os.path.isdir(tdir):
|
if os.path.isdir(tdir):
|
||||||
shutil.rmtree(tdir)
|
shutil.rmtree(tdir)
|
||||||
os.mkdir(tdir)
|
os.mkdir(tdir)
|
||||||
while len(send) and tries:
|
while send and tries:
|
||||||
for filename in send[:]:
|
for filename in send[:]:
|
||||||
sys.stdout.write('.')
|
sys.stdout.write('.')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
@ -1562,7 +1562,7 @@ class Package:
|
|||||||
tries -= 1
|
tries -= 1
|
||||||
sfilelist = self.__send_commitlog(msg, filelist)
|
sfilelist = self.__send_commitlog(msg, filelist)
|
||||||
send = self.commit_get_missing(sfilelist)
|
send = self.commit_get_missing(sfilelist)
|
||||||
if len(send):
|
if send:
|
||||||
raise oscerr.PackageInternalError(self.prjname, self.name,
|
raise oscerr.PackageInternalError(self.prjname, self.name,
|
||||||
'server does not accept filelist:\n%s\nmissing:\n%s\n' \
|
'server does not accept filelist:\n%s\nmissing:\n%s\n' \
|
||||||
% (ET.tostring(filelist, encoding=ET_ENCODING), ET.tostring(sfilelist, encoding=ET_ENCODING)))
|
% (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')
|
return root.get('code', 'unknown')
|
||||||
|
|
||||||
def change_request_state_template(req, newstate):
|
def change_request_state_template(req, newstate):
|
||||||
if not len(req.actions):
|
if not req.actions:
|
||||||
return ''
|
return ''
|
||||||
action = req.actions[0]
|
action = req.actions[0]
|
||||||
tmpl_name = '%srequest_%s_template' % (action.type, newstate)
|
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 []
|
return []
|
||||||
xpath = ''
|
xpath = ''
|
||||||
for prj, pacs in projpkgs.items():
|
for prj, pacs in projpkgs.items():
|
||||||
if not len(pacs):
|
if not pacs:
|
||||||
xpath = xpath_join(xpath, 'action/target/@project=\'%s\'' % prj, inner=True)
|
xpath = xpath_join(xpath, 'action/target/@project=\'%s\'' % prj, inner=True)
|
||||||
else:
|
else:
|
||||||
xp = ''
|
xp = ''
|
||||||
@ -5993,7 +5993,7 @@ def get_prj_results(apiurl, prj, hide_legend=False, csv=False, status_filter=Non
|
|||||||
targets_to_show = enabled.keys()
|
targets_to_show = enabled.keys()
|
||||||
|
|
||||||
pacs = [ i for i in pacs if i in pacs_to_show ]
|
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 ]
|
targets = [ i for i in targets if i in targets_to_show ]
|
||||||
|
|
||||||
# csv output
|
# csv output
|
||||||
@ -6143,7 +6143,7 @@ def streamfile(url, http_meth = http_GET, bufsize=8192, data=None, progress_obj=
|
|||||||
read = 0
|
read = 0
|
||||||
while True:
|
while True:
|
||||||
data = xread(bufsize)
|
data = xread(bufsize)
|
||||||
if not len(data):
|
if not data:
|
||||||
break
|
break
|
||||||
read += len(data)
|
read += len(data)
|
||||||
if progress_obj:
|
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)'
|
msg = '\nPending requests for %s: %s (%s)'
|
||||||
if sys.stdout.isatty():
|
if sys.stdout.isatty():
|
||||||
msg = f'\033[1m{msg}\033[0m'
|
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)))
|
print(msg % ('project', project, len(requests)))
|
||||||
elif len(requests):
|
elif requests:
|
||||||
print(msg % ('package', '/'.join([project, package]), len(requests)))
|
print(msg % ('package', '/'.join([project, package]), len(requests)))
|
||||||
for r in requests:
|
for r in requests:
|
||||||
print(r.list_view(), '\n')
|
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']
|
look though the list of conf.config['getpac_default_project']
|
||||||
and find the first project where the given package exists in the build service.
|
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
|
return None
|
||||||
candidates = re.split('[, ]+', conf.config['getpac_default_project'])
|
candidates = re.split('[, ]+', conf.config['getpac_default_project'])
|
||||||
if package is None or len(candidates) == 1:
|
if package is None or len(candidates) == 1:
|
||||||
|
Loading…
Reference in New Issue
Block a user