pep8 fixes

This commit is contained in:
Michael DeHaan 2012-10-30 20:42:07 -04:00
commit c0747b7baa
12 changed files with 60 additions and 56 deletions

View file

@ -300,7 +300,7 @@ class Inventory(object):
groups = [ g.name for g in host.get_groups() if g.name != 'all' ]
results['group_names'] = sorted(groups)
vars.update(results)
else:
else:
vars.update(host.get_variables())
return vars

View file

@ -123,7 +123,7 @@ class Play(object):
include_file = utils.template(self.basedir, tokens[0], mv)
data = utils.parse_yaml_from_file(utils.path_dwim(self.basedir, include_file))
for y in data:
results.append(Task(self,y,module_vars=mv.copy()))
results.append(Task(self,y,module_vars=mv.copy()))
elif type(x) == dict:
task_vars = self.vars.copy()
results.append(Task(self,x,module_vars=task_vars))

View file

@ -99,10 +99,10 @@ class Task(object):
# delegate_to can use variables
if not (self.delegate_to is None):
self.delegate_to = utils.template(None, self.delegate_to, self.module_vars)
# delegate_to: localhost should use local transport
if self.delegate_to in ['127.0.0.1', 'localhost']:
self.transport = 'local'
self.delegate_to = utils.template(None, self.delegate_to, self.module_vars)
# delegate_to: localhost should use local transport
if self.delegate_to in ['127.0.0.1', 'localhost']:
self.transport = 'local'
# notified by is used by Playbook code to flag which hosts
# need to run a notifier
@ -195,37 +195,37 @@ class Task(object):
# when: str $x != $y
if type(expression) not in [ str, unicode ]:
raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)
raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)
tokens = expression.split()
if len(tokens) < 2:
raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)
raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)
# when_set / when_unset
if tokens[0] in [ 'set', 'unset' ]:
if len(tokens) != 2:
raise errors.AnsibleError("usage: when: <set|unset> <$variableName>")
return "is_%s('%s')" % (tokens[0], tokens[1])
if len(tokens) != 2:
raise errors.AnsibleError("usage: when: <set|unset> <$variableName>")
return "is_%s('%s')" % (tokens[0], tokens[1])
# when_integer / when_float / when_string
elif tokens[0] in [ 'integer', 'float', 'string' ]:
cast = None
if tokens[0] == 'integer':
cast = 'int'
elif tokens[0] == 'string':
cast = 'str'
elif tokens[0] == 'float':
cast = 'float'
tcopy = tokens[1:]
for (i,t) in enumerate(tokens[1:]):
if t.find("$") != -1:
# final variable substitution will happen in Runner code
tcopy[i] = "%s('%s')" % (cast, t)
else:
tcopy[i] = t
return " ".join(tcopy)
cast = None
if tokens[0] == 'integer':
cast = 'int'
elif tokens[0] == 'string':
cast = 'str'
elif tokens[0] == 'float':
cast = 'float'
tcopy = tokens[1:]
for (i,t) in enumerate(tokens[1:]):
if t.find("$") != -1:
# final variable substitution will happen in Runner code
tcopy[i] = "%s('%s')" % (cast, t)
else:
tcopy[i] = t
return " ".join(tcopy)
else:
raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)
raise errors.AnsibleError("invalid usage of when_ operator: %s" % expression)

View file

@ -369,7 +369,7 @@ class Runner(object):
conn = None
actual_host = inject.get('ansible_ssh_host', host)
actual_port = port
if self.transport in ['paramiko', 'ssh' ]:
if self.transport in [ 'paramiko', 'ssh' ]:
actual_port = inject.get('ansible_ssh_port', port)
# the delegated host may have different SSH port configured, etc

View file

@ -142,10 +142,13 @@ def is_failed(result):
return ((result.get('rc', 0) != 0) or (result.get('failed', False) in [ True, 'True', 'true']))
def check_conditional(conditional):
def is_set(var):
return not var.startswith("$")
def is_unset(var):
return var.startswith("$")
return eval(conditional.replace("\n", "\\n"))
def is_executable(path):