mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Revert "minor style for for len usage and one "== None" occurrence"
This reverts commit 3cc77e21b5
.
Conflicts:
salt/utils/pyobjects.py
This commit is contained in:
parent
5c1ae24829
commit
23d7be7628
27 changed files with 47 additions and 47 deletions
|
@ -160,7 +160,7 @@ def auth(username, password):
|
|||
)
|
||||
)
|
||||
result = _ldap.search_s(basedn, int(scope), paramvalues['filter'])
|
||||
if not len(result):
|
||||
if len(result) < 1:
|
||||
log.warn('Unable to find user {0}'.format(username))
|
||||
return False
|
||||
elif len(result) > 1:
|
||||
|
|
|
@ -815,7 +815,7 @@ class Cloud(object):
|
|||
})
|
||||
|
||||
# destroying in parallel
|
||||
if self.opts['parallel'] and len(parallel_data):
|
||||
if self.opts['parallel'] and len(parallel_data) > 0:
|
||||
# set the pool size based on configuration or default to
|
||||
# the number of machines we're destroying
|
||||
if 'pool_size' in self.opts:
|
||||
|
@ -1938,7 +1938,7 @@ class Map(Cloud):
|
|||
for name in dmap.get('destroy', ()):
|
||||
output[name] = self.destroy(name)
|
||||
|
||||
if self.opts['parallel'] and len(parallel_data):
|
||||
if self.opts['parallel'] and len(parallel_data) > 0:
|
||||
if 'pool_size' in self.opts:
|
||||
pool_size = self.opts['pool_size']
|
||||
else:
|
||||
|
|
|
@ -460,9 +460,9 @@ def __get_host(node):
|
|||
'''
|
||||
Return public IP, private IP, or hostname for the libcloud 'node' object
|
||||
'''
|
||||
if len(node.public_ips):
|
||||
if len(node.public_ips) > 0:
|
||||
return node.public_ips[0]
|
||||
if len(node.private_ips):
|
||||
if len(node.private_ips) > 0:
|
||||
return node.private_ips[0]
|
||||
return node.name
|
||||
|
||||
|
@ -507,7 +507,7 @@ def _parse_allow(allow):
|
|||
seen_protos[pairs[0]].append(pairs[1])
|
||||
for k in seen_protos:
|
||||
d = {'IPProtocol': k}
|
||||
if len(seen_protos[k]):
|
||||
if len(seen_protos[k]) > 0:
|
||||
d['ports'] = seen_protos[k]
|
||||
allow_dict.append(d)
|
||||
log.debug("firewall allowed protocols/ports: {0}".format(allow_dict))
|
||||
|
|
|
@ -240,11 +240,11 @@ def create(vm_):
|
|||
# Still not running, trigger another iteration
|
||||
return
|
||||
|
||||
if isinstance(data['ips'], list) and len(data['ips']):
|
||||
if isinstance(data['ips'], list) and len(data['ips']) > 0:
|
||||
return data
|
||||
|
||||
if 'ips' in data:
|
||||
if isinstance(data['ips'], list) and not len(data['ips']):
|
||||
if isinstance(data['ips'], list) and len(data['ips']) <= 0:
|
||||
log.info(
|
||||
'New joyent asynchronous machine creation api detected...'
|
||||
'\n\t\t-- please wait for IP addresses to be assigned...'
|
||||
|
|
|
@ -370,7 +370,7 @@ def create(vm_):
|
|||
node_info = pass_conn.getVirtualGuests(id=response['id'], mask=mask)
|
||||
for node in node_info:
|
||||
if node['id'] == response['id']:
|
||||
if 'passwords' in node['operatingSystem'] and len(node['operatingSystem']['passwords']):
|
||||
if 'passwords' in node['operatingSystem'] and len(node['operatingSystem']['passwords']) > 0:
|
||||
return node['operatingSystem']['passwords'][0]['password']
|
||||
time.sleep(5)
|
||||
return False
|
||||
|
|
|
@ -542,7 +542,7 @@ def create(vm_):
|
|||
node_info = pass_conn.getVirtualGuests(id=response['id'], mask=mask)
|
||||
for node in node_info:
|
||||
if node['id'] == response['id']:
|
||||
if 'passwords' in node['operatingSystem'] and len(node['operatingSystem']['passwords']):
|
||||
if 'passwords' in node['operatingSystem'] and len(node['operatingSystem']['passwords']) > 0:
|
||||
return node['operatingSystem']['passwords'][0]['password']
|
||||
time.sleep(5)
|
||||
return False
|
||||
|
|
|
@ -1479,7 +1479,7 @@ def build_network_settings(**settings):
|
|||
_write_file_network(hostname, _DEB_HOSTNAME_FILE)
|
||||
|
||||
# Write domainname to /etc/resolv.conf
|
||||
if len(sline):
|
||||
if len(sline) > 0:
|
||||
domainname = sline[1]
|
||||
|
||||
contents = _parse_resolve()
|
||||
|
|
|
@ -559,7 +559,7 @@ def install(name=None,
|
|||
# We need to delete quotes around use flag list elements
|
||||
verstr = verstr.replace("'", "")
|
||||
# If no prefix characters were supplied and verstr contains a version, use '='
|
||||
if len(verstr) and verstr[0] != ':' and verstr[0] != '[':
|
||||
if len(verstr) > 0 and verstr[0] != ':' and verstr[0] != '[':
|
||||
prefix = prefix or '='
|
||||
target = '"{0}{1}-{2}"'.format(prefix, param, verstr)
|
||||
else:
|
||||
|
|
|
@ -51,7 +51,7 @@ def add(overlay):
|
|||
# If we did not have any overlays before and we successfully added
|
||||
# a new one. We need to ensure the make.conf is sourcing layman's
|
||||
# make.conf so emerge can see the overlays
|
||||
if len(old_overlays) == 0 and len(new_overlays):
|
||||
if len(old_overlays) == 0 and len(new_overlays) > 0:
|
||||
srcline = 'source /var/lib/layman/make.conf'
|
||||
makeconf = _get_makeconf()
|
||||
if not __salt__['file.contains'](makeconf, 'layman'):
|
||||
|
|
|
@ -211,10 +211,10 @@ def create(*args):
|
|||
cmd = "echo y | mdadm --create --verbose {new_array}{opts_raw}{opts_val} {disks_to_array}"
|
||||
cmd = cmd.format(new_array=arguments['new_array'],
|
||||
opts_raw=(' --' + ' --'.join(arguments['opt_raw'])
|
||||
if len(arguments['opt_raw'])
|
||||
if len(arguments['opt_raw']) > 0
|
||||
else ''),
|
||||
opts_val=(' --' + ' --'.join(key + '=' + arguments['opt_val'][key] for key in arguments['opt_val'])
|
||||
if len(arguments['opt_val'])
|
||||
if len(arguments['opt_val']) > 0
|
||||
else ''),
|
||||
disks_to_array=' '.join(arguments['disks_to_array']))
|
||||
|
||||
|
|
|
@ -871,11 +871,11 @@ def get_disks(vm_):
|
|||
for elem in doc.getElementsByTagName('disk'):
|
||||
sources = elem.getElementsByTagName('source')
|
||||
targets = elem.getElementsByTagName('target')
|
||||
if len(sources):
|
||||
if len(sources) > 0:
|
||||
source = sources[0]
|
||||
else:
|
||||
continue
|
||||
if len(targets):
|
||||
if len(targets) > 0:
|
||||
target = targets[0]
|
||||
else:
|
||||
continue
|
||||
|
|
|
@ -203,7 +203,7 @@ def version(*names, **kwargs):
|
|||
versions = _get_package_info(name)
|
||||
if versions:
|
||||
for val in versions.itervalues():
|
||||
if 'full_name' in val and len(val.get('full_name', '')):
|
||||
if 'full_name' in val and len(val.get('full_name', '')) > 0:
|
||||
reverse_dict[val.get('full_name', '')] = name
|
||||
win_names.append(val.get('full_name', ''))
|
||||
else:
|
||||
|
@ -211,7 +211,7 @@ def version(*names, **kwargs):
|
|||
nums = __salt__['pkg_resource.version'](*win_names, **kwargs)
|
||||
if len(nums):
|
||||
for num, val in nums.iteritems():
|
||||
if len(val):
|
||||
if len(val) > 0:
|
||||
try:
|
||||
ret[reverse_dict[num]] = val
|
||||
except KeyError:
|
||||
|
|
|
@ -47,7 +47,7 @@ def render(yaml_data, saltenv='base', sls='', argline='', **kws):
|
|||
raise SaltRenderError(err_type, line_num, exc.problem_mark.buffer)
|
||||
except ConstructorError as exc:
|
||||
raise SaltRenderError(exc)
|
||||
if len(warn_list):
|
||||
if len(warn_list) > 0:
|
||||
for item in warn_list:
|
||||
log.warn(
|
||||
'{warn} found in salt://{sls} environment={saltenv}'.format(
|
||||
|
|
|
@ -194,7 +194,7 @@ def get_fun(fun):
|
|||
|
||||
# Skip the minion if we didn't get any rows back. ( IE function that
|
||||
# they're looking for has a typo in it or some such ).
|
||||
if not len(_response['rows']):
|
||||
if len(_response['rows']) < 1:
|
||||
continue
|
||||
|
||||
# Set the respnse ..
|
||||
|
|
|
@ -1114,7 +1114,7 @@ class State(object):
|
|||
if isinstance(arg, dict):
|
||||
# It is not a function, verify that the arg is a
|
||||
# requisite in statement
|
||||
if not len(arg):
|
||||
if len(arg) < 1:
|
||||
# Empty arg dict
|
||||
# How did we get this far?
|
||||
continue
|
||||
|
@ -1171,7 +1171,7 @@ class State(object):
|
|||
if not isinstance(ind, dict):
|
||||
# Malformed req_in
|
||||
continue
|
||||
if not len(ind):
|
||||
if len(ind) < 1:
|
||||
continue
|
||||
_state = next(iter(ind))
|
||||
name = ind[_state]
|
||||
|
@ -1378,7 +1378,7 @@ class State(object):
|
|||
# smart to not raise another KeyError as the name is easily
|
||||
# guessable and fallback in all cases to present the real
|
||||
# exception to the user
|
||||
if len(cdata['args']):
|
||||
if len(cdata['args']) > 0:
|
||||
name = cdata['args'][0]
|
||||
elif 'name' in cdata['kwargs']:
|
||||
name = cdata['kwargs']['name']
|
||||
|
@ -2251,7 +2251,7 @@ class BaseHighState(object):
|
|||
|
||||
for arg in state[name][s_dec]:
|
||||
if isinstance(arg, dict):
|
||||
if len(arg):
|
||||
if len(arg) > 0:
|
||||
if arg.keys()[0] == 'order':
|
||||
found = True
|
||||
if not found:
|
||||
|
|
|
@ -162,7 +162,7 @@ def extracted(name,
|
|||
files = results['stdout']
|
||||
if not files:
|
||||
files = 'no tar output so far'
|
||||
if len(files):
|
||||
if len(files) > 0:
|
||||
ret['result'] = True
|
||||
ret['changes']['directories_created'] = [name]
|
||||
if if_missing != name:
|
||||
|
|
|
@ -170,7 +170,7 @@ def latest(name,
|
|||
branch = __salt__['git.current_branch'](target, user=user)
|
||||
# We're only interested in the remote branch if a branch
|
||||
# (instead of a hash, for example) was provided for rev.
|
||||
if len(branch) and branch == rev:
|
||||
if len(branch) > 0 and branch == rev:
|
||||
remote_rev = __salt__['git.ls_remote'](target,
|
||||
repository=name,
|
||||
branch=branch, user=user,
|
||||
|
|
|
@ -43,7 +43,7 @@ def present(name):
|
|||
changes = __salt__['layman.add'](name)
|
||||
|
||||
# The overlay failed to add
|
||||
if not len(changes):
|
||||
if len(changes) < 1:
|
||||
ret['comment'] = 'Overlay {0} failed to add'.format(name)
|
||||
ret['result'] = False
|
||||
# Success
|
||||
|
@ -78,7 +78,7 @@ def absent(name):
|
|||
changes = __salt__['layman.delete'](name)
|
||||
|
||||
# The overlay failed to delete
|
||||
if not len(changes):
|
||||
if len(changes) < 1:
|
||||
ret['comment'] = 'Overlay {0} failed to delete'.format(name)
|
||||
ret['result'] = False
|
||||
# Success
|
||||
|
|
|
@ -117,7 +117,7 @@ def present(name, value=None, contains=None, excludes=None):
|
|||
contains_set = _make_set(contains)
|
||||
excludes_set = _make_set(excludes)
|
||||
old_value_set = _make_set(old_value)
|
||||
if len(contains_set.intersection(excludes_set)):
|
||||
if len(contains_set.intersection(excludes_set)) > 0:
|
||||
msg = 'Variable {0} cannot contain and exclude the same value'
|
||||
ret['comment'] = msg.format(name)
|
||||
ret['result'] = False
|
||||
|
@ -134,9 +134,9 @@ def present(name, value=None, contains=None, excludes=None):
|
|||
else:
|
||||
if __opts__['test']:
|
||||
msg = 'Variable {0} is set to'.format(name)
|
||||
if len(to_append):
|
||||
if len(to_append) > 0:
|
||||
msg += ' append "{0}"'.format(list(to_append))
|
||||
if len(to_trim):
|
||||
if len(to_trim) > 0:
|
||||
msg += ' trim "{0}"'.format(list(to_trim))
|
||||
msg += ' in make.conf'
|
||||
ret['comment'] = msg
|
||||
|
|
|
@ -68,7 +68,7 @@ def _send_command(cmd,
|
|||
cmd
|
||||
)
|
||||
return ret
|
||||
elif len(errors):
|
||||
elif len(errors) > 0:
|
||||
ret['msg'] = 'the following minions return False'
|
||||
ret['minions'] = errors
|
||||
return ret
|
||||
|
|
|
@ -137,7 +137,7 @@ class Initiator(Transaction):
|
|||
'''
|
||||
Process time based handling of transaction like timeout or retries
|
||||
'''
|
||||
if self.timeout and self.timer.expired:
|
||||
if self.timeout > 0.0 and self.timer.expired:
|
||||
self.stack.removeTransaction(self.index, transaction=self)
|
||||
|
||||
class Correspondent(Transaction):
|
||||
|
@ -219,7 +219,7 @@ class Joiner(Initiator):
|
|||
'''
|
||||
Perform time based processing of transaction
|
||||
'''
|
||||
if self.timeout and self.timer.expired:
|
||||
if self.timeout > 0.0 and self.timer.expired:
|
||||
if self.txPacket and self.txPacket.data['pk'] == raeting.pcktKinds.request:
|
||||
self.remove(self.txPacket.index) #index changes after accept
|
||||
else:
|
||||
|
@ -498,7 +498,7 @@ class Joinent(Correspondent):
|
|||
Perform time based processing of transaction
|
||||
|
||||
'''
|
||||
if self.timeout and self.timer.expired:
|
||||
if self.timeout > 0.0 and self.timer.expired:
|
||||
self.nackJoin()
|
||||
console.concise("Joinent timed out at {0}\n".format(self.stack.store.stamp))
|
||||
return
|
||||
|
@ -668,7 +668,7 @@ class Joinent(Correspondent):
|
|||
self.stack.dumpRemote(remote)
|
||||
self.reid = remote.eid # auto generated at instance creation above
|
||||
|
||||
if status is None or status == raeting.acceptances.pending:
|
||||
if status == None or status == raeting.acceptances.pending:
|
||||
self.ackJoin()
|
||||
elif status == raeting.acceptances.accepted:
|
||||
duration = min(
|
||||
|
@ -844,7 +844,7 @@ class Allower(Initiator):
|
|||
'''
|
||||
Perform time based processing of transaction
|
||||
'''
|
||||
if self.timeout and self.timer.expired:
|
||||
if self.timeout > 0.0 and self.timer.expired:
|
||||
self.remove()
|
||||
console.concise("Allower timed out at {0}\n".format(self.stack.store.stamp))
|
||||
return
|
||||
|
@ -1123,7 +1123,7 @@ class Allowent(Correspondent):
|
|||
Perform time based processing of transaction
|
||||
|
||||
'''
|
||||
if self.timeout and self.timer.expired:
|
||||
if self.timeout > 0.0 and self.timer.expired:
|
||||
self.nack()
|
||||
console.concise("Allowent timed out at {0}\n".format(self.stack.store.stamp))
|
||||
return
|
||||
|
|
|
@ -878,7 +878,7 @@ def deploy_script(host, port=22, timeout=900, username='root',
|
|||
)
|
||||
if sudo:
|
||||
comps = tmp_dir.lstrip('/').rstrip('/').split('/')
|
||||
if len(comps):
|
||||
if len(comps) > 0:
|
||||
if len(comps) > 1 or comps[0] != 'tmp':
|
||||
ret = root_cmd(
|
||||
'chown {0}. {1}'.format(username, tmp_dir),
|
||||
|
|
|
@ -176,7 +176,7 @@ def _parse_size(value):
|
|||
else:
|
||||
style = '='
|
||||
|
||||
if len(scalar):
|
||||
if len(scalar) > 0:
|
||||
multiplier = {'b': 2 ** 0,
|
||||
'k': 2 ** 10,
|
||||
'm': 2 ** 20,
|
||||
|
|
|
@ -2150,7 +2150,7 @@ class SaltRunOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
|
|||
)
|
||||
|
||||
def _mixin_after_parsed(self):
|
||||
if len(self.args):
|
||||
if len(self.args) > 0:
|
||||
self.config['fun'] = self.args[0]
|
||||
else:
|
||||
self.config['fun'] = ''
|
||||
|
@ -2279,7 +2279,7 @@ class SaltSSHOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
|
|||
self.config['tgt'] = self.args[0].split()
|
||||
else:
|
||||
self.config['tgt'] = self.args[0]
|
||||
if len(self.args):
|
||||
if len(self.args) > 0:
|
||||
self.config['arg_str'] = ' '.join(self.args[1:])
|
||||
|
||||
def setup_config(self):
|
||||
|
|
|
@ -154,7 +154,7 @@ class StateFactory(object):
|
|||
self.valid_funcs = valid_funcs
|
||||
|
||||
def __getattr__(self, func):
|
||||
if len(self.valid_funcs) and func not in self.valid_funcs:
|
||||
if len(self.valid_funcs) > 0 and func not in self.valid_funcs:
|
||||
raise InvalidFunction("The function '%s' does not exist in the "
|
||||
"StateFactory for '%s'" % (func, self.module))
|
||||
|
||||
|
|
|
@ -27,5 +27,5 @@ def set_inventory_base_uri_default(config, opts):
|
|||
return
|
||||
|
||||
base_roots = config.get('file_roots', {}).get('base', [])
|
||||
if len(base_roots):
|
||||
if len(base_roots) > 0:
|
||||
opts['inventory_base_uri'] = base_roots[0]
|
||||
|
|
|
@ -11,7 +11,7 @@ def to_dict(xmltree):
|
|||
'''
|
||||
# If this object has no children, the for..loop below will return nothing
|
||||
# for it, so just return a single dict representing it.
|
||||
if not len(xmltree.getchildren()):
|
||||
if len(xmltree.getchildren()) < 1:
|
||||
name = xmltree.tag
|
||||
if '}' in name:
|
||||
comps = name.split('}')
|
||||
|
@ -28,7 +28,7 @@ def to_dict(xmltree):
|
|||
comps = name.split('}')
|
||||
name = comps[1]
|
||||
if name not in xmldict:
|
||||
if len(item.getchildren()):
|
||||
if len(item.getchildren()) > 0:
|
||||
xmldict[name] = to_dict(item)
|
||||
else:
|
||||
xmldict[name] = item.text
|
||||
|
|
Loading…
Add table
Reference in a new issue