Merge pull request #6976 from malinoff/fixed-range-syntax

Fixed range syntax
This commit is contained in:
Thomas S Hatch 2013-08-31 19:49:41 -07:00
commit 66daa60d75
11 changed files with 21 additions and 25 deletions

View File

@ -117,14 +117,14 @@ def init():
'''
bp_ = os.path.join(__opts__['cachedir'], 'gitfs')
repos = []
for ind in range(len(__opts__['gitfs_remotes'])):
for ind, opt in enumerate(__opts__['gitfs_remotes']):
rp_ = os.path.join(bp_, str(ind))
if not os.path.isdir(rp_):
os.makedirs(rp_)
repo = git.Repo.init(rp_)
if not repo.remotes:
try:
repo.create_remote('origin', __opts__['gitfs_remotes'][ind])
repo.create_remote('origin', opt)
except Exception:
# This exception occurs when two processes are trying to write
# to the git config at once, go ahead and pass over it since

View File

@ -115,7 +115,7 @@ def init():
'''
bp_ = os.path.join(__opts__['cachedir'], 'hgfs')
repos = []
for ind in range(len(__opts__['hgfs_remotes'])):
for ind, opt in enumerate(__opts__['hgfs_remotes']):
rp_ = os.path.join(bp_, str(ind))
if not os.path.isdir(rp_):
os.makedirs(rp_)
@ -126,8 +126,7 @@ def init():
hgconfpath = os.path.join(rp_, '.hg', 'hgrc')
with salt.utils.fopen(hgconfpath, 'w+') as hgconfig:
hgconfig.write('[paths]\n')
hgconfig.write('default = {0}\n'.format(
__opts__['hgfs_remotes'][ind]))
hgconfig.write('default = {0}\n'.format(opt))
repos.append(repo)
repo.close()

View File

@ -32,7 +32,7 @@ def _render_tab(lst):
ret = []
for pre in lst['pre']:
ret.append('{0}\n'.format(pre))
if len(ret):
if ret:
if ret[-1] != TAG:
ret.append(TAG)
else:

View File

@ -126,8 +126,8 @@ def set_host(ip, alias):
if not os.path.isfile(hfn):
return False
lines = salt.utils.fopen(hfn).readlines()
for ind in range(len(lines)):
tmpline = lines[ind].strip()
for ind, line in enumerate(lines):
tmpline = line.strip()
if not tmpline:
continue
if tmpline.startswith('#'):

View File

@ -93,7 +93,7 @@ def send(func, *args, **kwargs):
data = {}
arg_data = salt.utils.arg_lookup(__salt__[func])
func_data = {}
for ind in range(len(arg_data.get('args', []))):
for ind, _ in enumerate(arg_data.get('args', [])):
try:
func_data[arg_data[ind]] = args[ind]
except IndexError:

View File

@ -142,11 +142,11 @@ def list_pkgs(versions_as_list=False, **kwargs):
# lines, the package name is in the first column. On odd-offset lines, the
# package version is in the second column.
lines = __salt__['cmd.run'](cmd).splitlines()
for index in range(0, len(lines)):
for index, line in enumerate(lines):
if index % 2 == 0:
name = lines[index].split()[0].strip()
name = line.split()[0].strip()
if index % 2 == 1:
version_num = lines[index].split()[1].strip()
version_num = line.split()[1].strip()
__salt__['pkg_resource.add_pkg'](ret, name, version_num)
__salt__['pkg_resource.sort_pkglist'](ret)
@ -185,7 +185,7 @@ def latest_version(*names, **kwargs):
salt '*' pkgutil.latest_version CSWpython
salt '*' pkgutil.latest_version <package1> <package2> <package3> ...
'''
if len(names) == 0:
if not names:
return ''
ret = {}
# Initialize the dict with empty strings

View File

@ -93,11 +93,11 @@ def list_pkgs(versions_as_list=False, **kwargs):
# lines, the package name is in the first column. On odd-offset lines, the
# package version is in the second column.
lines = __salt__['cmd.run'](cmd).splitlines()
for index in range(0, len(lines)):
for index, line in enumerate(lines):
if index % 2 == 0:
name = lines[index].split()[0].strip()
name = line.split()[0].strip()
if index % 2 == 1:
version_num = lines[index].split()[1].strip()
version_num = line.split()[1].strip()
__salt__['pkg_resource.add_pkg'](ret, name, version_num)
__salt__['pkg_resource.sort_pkglist'](ret)
@ -128,7 +128,7 @@ def latest_version(*names, **kwargs):
package.
'''
ret = {}
if len(names) == 0:
if not names:
return ''
for name in names:
ret[name] = ''

View File

@ -302,7 +302,7 @@ def diskusage(*args):
# select fstype
fstypes.add(arg)
if len(fstypes) > 0:
if fstypes:
# determine which mount points host the specified fstypes
regex = re.compile(
'|'.join(

View File

@ -51,10 +51,7 @@ def get_path():
ret = __salt__['reg.read_key']('HKEY_LOCAL_MACHINE', 'SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment', 'PATH').split(';')
# Trim ending backslash
for i in range(0, len(ret)):
ret[i] = _normalize_dir(ret[i])
return ret
return map(_normalize_dir, ret)
def exists(path):
'''

View File

@ -269,13 +269,13 @@ def node_info():
cpu_speeds = [int(host_cpu_rec["speed"])
for host_cpu_it in host_cpu_rec
if "speed" in host_cpu_it]
if len(cpu_speeds) > 0:
if cpu_speeds:
return sum(cpu_speeds) / len(cpu_speeds)
else:
return 0
def getCpuFeatures():
if len(host_cpu_rec) > 0:
if host_cpu_rec:
return host_cpu_rec['features']
def getFreeCpuCount():

View File

@ -70,7 +70,7 @@ def run(command):
if __name__ == '__main__':
opts = parse()
for ind in range(opts['runs']):
for _ in opts['runs']:
for command in opts['command'].split(','):
print('-' * 30)
print('Running command {0}'.format(command))