pep8 fixes

pull/1648/head
Michael DeHaan 12 years ago
parent 27e518a0b1
commit c0747b7baa

@ -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

@ -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))

@ -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)

@ -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

@ -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):

@ -154,7 +154,7 @@ def add_job(name,job,tmpfile):
def update_job(name,job,tmpfile):
return _update_job(name,job,tmpfile,do_add_job)
def do_add_job (lines, comment, job):
def do_add_job(lines, comment, job):
lines.append(comment)
lines.append(job)

@ -77,7 +77,7 @@ syslog.openlog('ansible-%s' % os.path.basename(__file__))
PIDFILE = os.path.expanduser("~/.fireball.pid")
def log(msg):
syslog.syslog(syslog.LOG_NOTICE, msg)
syslog.syslog(syslog.LOG_NOTICE, msg)
if os.path.exists(PIDFILE):
try:
@ -92,17 +92,17 @@ if os.path.exists(PIDFILE):
HAS_ZMQ = False
try:
import zmq
HAS_ZMQ = True
import zmq
HAS_ZMQ = True
except ImportError:
pass
pass
HAS_KEYCZAR = False
try:
from keyczar.keys import AesKey
HAS_KEYCZAR = True
from keyczar.keys import AesKey
HAS_KEYCZAR = True
except ImportError:
pass
pass
# NOTE: this shares a fair amount of code in common with async_wrapper, if async_wrapper were a new module we could move
# this into utils.module_common and probably should anyway
@ -163,9 +163,9 @@ def command(data):
def fetch(data):
if 'data' not in data:
return dict(failed=True, msg='internal error: data is required')
return dict(failed=True, msg='internal error: data is required')
if 'in_path' not in data:
return dict(failed=True, msg='internal error: out_path is required')
return dict(failed=True, msg='internal error: out_path is required')
fh = open(data['in_path'])
data = fh.read()

@ -157,12 +157,14 @@ def absent(module, dest, regexp, backup):
f.close()
cre = re.compile(regexp)
found = []
def matcher(line):
if cre.search(line):
found.append(line)
return False
else:
return True
lines = filter(matcher, lines)
changed = len(found) > 0
if changed:

@ -176,7 +176,7 @@ def privileges_get(cursor, user,host):
privileges = res.group(1).split(", ")
privileges = ['ALL' if x=='ALL PRIVILEGES' else x for x in privileges]
if "WITH GRANT OPTION" in res.group(4):
privileges.append('GRANT')
privileges.append('GRANT')
db = res.group(2).replace('`', '')
output[db] = privileges
return output
@ -213,8 +213,7 @@ def privileges_grant(cursor, user,host,db_table,priv):
priv_string = ",".join(filter(lambda x: x != 'GRANT', priv))
query = "GRANT %s ON %s TO '%s'@'%s'" % (priv_string,db_table,user,host)
if 'GRANT' in priv:
query = query + " WITH GRANT OPTION"
query = query + " WITH GRANT OPTION"
cursor.execute(query)
def load_mycnf():

@ -149,7 +149,7 @@ def main():
# To use defaults values, keyword arguments must be absent, so
# check which values are empty and don't include in the **kw
# dictionary
params_map = {
params_map = {
"login_host":"host",
"login_user":"user",
"login_password":"password",

@ -379,7 +379,7 @@ def main():
# To use defaults values, keyword arguments must be absent, so
# check which values are empty and don't include in the **kw
# dictionary
params_map = {
params_map = {
"login_host":"host",
"login_user":"user",
"login_password":"password",

@ -853,19 +853,19 @@ def run_setup(module):
# templating w/o making a nicer key for it (TODO)
if os.path.exists("/usr/bin/ohai"):
cmd = subprocess.Popen("/usr/bin/ohai", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
ohai = True
try:
ohai_ds = json.loads(out)
except:
ohai = False
if ohai:
for (k,v) in ohai_ds.items():
if type(v) == str or type(v) == unicode:
k2 = "ohai_%s" % k.replace('-', '_')
setup_options[k2] = v
cmd = subprocess.Popen("/usr/bin/ohai", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
ohai = True
try:
ohai_ds = json.loads(out)
except:
ohai = False
if ohai:
for (k,v) in ohai_ds.items():
if type(v) == str or type(v) == unicode:
k2 = "ohai_%s" % k.replace('-', '_')
setup_options[k2] = v
setup_result = {}
setup_result['ansible_facts'] = setup_options

Loading…
Cancel
Save