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' ] groups = [ g.name for g in host.get_groups() if g.name != 'all' ]
results['group_names'] = sorted(groups) results['group_names'] = sorted(groups)
vars.update(results) vars.update(results)
else: else:
vars.update(host.get_variables()) vars.update(host.get_variables())
return vars return vars

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

@ -99,10 +99,10 @@ class Task(object):
# delegate_to can use variables # delegate_to can use variables
if not (self.delegate_to is None): if not (self.delegate_to is None):
self.delegate_to = utils.template(None, self.delegate_to, self.module_vars) self.delegate_to = utils.template(None, self.delegate_to, self.module_vars)
# delegate_to: localhost should use local transport # delegate_to: localhost should use local transport
if self.delegate_to in ['127.0.0.1', 'localhost']: if self.delegate_to in ['127.0.0.1', 'localhost']:
self.transport = 'local' self.transport = 'local'
# notified by is used by Playbook code to flag which hosts # notified by is used by Playbook code to flag which hosts
# need to run a notifier # need to run a notifier
@ -195,37 +195,37 @@ class Task(object):
# when: str $x != $y # when: str $x != $y
if type(expression) not in [ str, unicode ]: 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() tokens = expression.split()
if len(tokens) < 2: 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 # when_set / when_unset
if tokens[0] in [ 'set', 'unset' ]: if tokens[0] in [ 'set', 'unset' ]:
if len(tokens) != 2: if len(tokens) != 2:
raise errors.AnsibleError("usage: when: <set|unset> <$variableName>") raise errors.AnsibleError("usage: when: <set|unset> <$variableName>")
return "is_%s('%s')" % (tokens[0], tokens[1]) return "is_%s('%s')" % (tokens[0], tokens[1])
# when_integer / when_float / when_string # when_integer / when_float / when_string
elif tokens[0] in [ 'integer', 'float', 'string' ]: elif tokens[0] in [ 'integer', 'float', 'string' ]:
cast = None cast = None
if tokens[0] == 'integer': if tokens[0] == 'integer':
cast = 'int' cast = 'int'
elif tokens[0] == 'string': elif tokens[0] == 'string':
cast = 'str' cast = 'str'
elif tokens[0] == 'float': elif tokens[0] == 'float':
cast = 'float' cast = 'float'
tcopy = tokens[1:] tcopy = tokens[1:]
for (i,t) in enumerate(tokens[1:]): for (i,t) in enumerate(tokens[1:]):
if t.find("$") != -1: if t.find("$") != -1:
# final variable substitution will happen in Runner code # final variable substitution will happen in Runner code
tcopy[i] = "%s('%s')" % (cast, t) tcopy[i] = "%s('%s')" % (cast, t)
else: else:
tcopy[i] = t tcopy[i] = t
return " ".join(tcopy) return " ".join(tcopy)
else: 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 conn = None
actual_host = inject.get('ansible_ssh_host', host) actual_host = inject.get('ansible_ssh_host', host)
actual_port = port actual_port = port
if self.transport in ['paramiko', 'ssh' ]: if self.transport in [ 'paramiko', 'ssh' ]:
actual_port = inject.get('ansible_ssh_port', port) actual_port = inject.get('ansible_ssh_port', port)
# the delegated host may have different SSH port configured, etc # 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'])) return ((result.get('rc', 0) != 0) or (result.get('failed', False) in [ True, 'True', 'true']))
def check_conditional(conditional): def check_conditional(conditional):
def is_set(var): def is_set(var):
return not var.startswith("$") return not var.startswith("$")
def is_unset(var): def is_unset(var):
return var.startswith("$") return var.startswith("$")
return eval(conditional.replace("\n", "\\n")) return eval(conditional.replace("\n", "\\n"))
def is_executable(path): def is_executable(path):

@ -154,7 +154,7 @@ def add_job(name,job,tmpfile):
def update_job(name,job,tmpfile): def update_job(name,job,tmpfile):
return _update_job(name,job,tmpfile,do_add_job) 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(comment)
lines.append(job) lines.append(job)

@ -77,7 +77,7 @@ syslog.openlog('ansible-%s' % os.path.basename(__file__))
PIDFILE = os.path.expanduser("~/.fireball.pid") PIDFILE = os.path.expanduser("~/.fireball.pid")
def log(msg): def log(msg):
syslog.syslog(syslog.LOG_NOTICE, msg) syslog.syslog(syslog.LOG_NOTICE, msg)
if os.path.exists(PIDFILE): if os.path.exists(PIDFILE):
try: try:
@ -92,17 +92,17 @@ if os.path.exists(PIDFILE):
HAS_ZMQ = False HAS_ZMQ = False
try: try:
import zmq import zmq
HAS_ZMQ = True HAS_ZMQ = True
except ImportError: except ImportError:
pass pass
HAS_KEYCZAR = False HAS_KEYCZAR = False
try: try:
from keyczar.keys import AesKey from keyczar.keys import AesKey
HAS_KEYCZAR = True HAS_KEYCZAR = True
except ImportError: 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 # 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 # this into utils.module_common and probably should anyway
@ -163,9 +163,9 @@ def command(data):
def fetch(data): def fetch(data):
if 'data' not in 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: 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']) fh = open(data['in_path'])
data = fh.read() data = fh.read()

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

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

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

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

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

Loading…
Cancel
Save