Some flake8 cleanup
parent
332ca927d9
commit
160e71e2cf
|
@ -66,7 +66,6 @@ import grp
|
||||||
import pwd
|
import pwd
|
||||||
import platform
|
import platform
|
||||||
import errno
|
import errno
|
||||||
import tempfile
|
|
||||||
from itertools import imap, repeat
|
from itertools import imap, repeat
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -113,7 +112,6 @@ try:
|
||||||
from systemd import journal
|
from systemd import journal
|
||||||
has_journal = True
|
has_journal = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import syslog
|
|
||||||
has_journal = False
|
has_journal = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -121,10 +119,10 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# a replacement for literal_eval that works with python 2.4. from:
|
# a replacement for literal_eval that works with python 2.4. from:
|
||||||
# https://mail.python.org/pipermail/python-list/2009-September/551880.html
|
# https://mail.python.org/pipermail/python-list/2009-September/551880.html
|
||||||
# which is essentially a cut/past from an earlier (2.6) version of python's
|
# which is essentially a cut/paste from an earlier (2.6) version of python's
|
||||||
# ast.py
|
# ast.py
|
||||||
from compiler import parse
|
from compiler import ast, parse
|
||||||
from compiler.ast import *
|
|
||||||
def _literal_eval(node_or_string):
|
def _literal_eval(node_or_string):
|
||||||
"""
|
"""
|
||||||
Safely evaluate an expression node or a string containing a Python
|
Safely evaluate an expression node or a string containing a Python
|
||||||
|
@ -135,21 +133,22 @@ except ImportError:
|
||||||
_safe_names = {'None': None, 'True': True, 'False': False}
|
_safe_names = {'None': None, 'True': True, 'False': False}
|
||||||
if isinstance(node_or_string, basestring):
|
if isinstance(node_or_string, basestring):
|
||||||
node_or_string = parse(node_or_string, mode='eval')
|
node_or_string = parse(node_or_string, mode='eval')
|
||||||
if isinstance(node_or_string, Expression):
|
if isinstance(node_or_string, ast.Expression):
|
||||||
node_or_string = node_or_string.node
|
node_or_string = node_or_string.node
|
||||||
|
|
||||||
def _convert(node):
|
def _convert(node):
|
||||||
if isinstance(node, Const) and isinstance(node.value, (basestring, int, float, long, complex)):
|
if isinstance(node, ast.Const) and isinstance(node.value, (basestring, int, float, long, complex)):
|
||||||
return node.value
|
return node.value
|
||||||
elif isinstance(node, Tuple):
|
elif isinstance(node, ast.Tuple):
|
||||||
return tuple(map(_convert, node.nodes))
|
return tuple(map(_convert, node.nodes))
|
||||||
elif isinstance(node, List):
|
elif isinstance(node, ast.List):
|
||||||
return list(map(_convert, node.nodes))
|
return list(map(_convert, node.nodes))
|
||||||
elif isinstance(node, Dict):
|
elif isinstance(node, ast.Dict):
|
||||||
return dict((_convert(k), _convert(v)) for k, v in node.items)
|
return dict((_convert(k), _convert(v)) for k, v in node.items)
|
||||||
elif isinstance(node, Name):
|
elif isinstance(node, ast.Name):
|
||||||
if node.name in _safe_names:
|
if node.name in _safe_names:
|
||||||
return _safe_names[node.name]
|
return _safe_names[node.name]
|
||||||
elif isinstance(node, UnarySub):
|
elif isinstance(node, ast.UnarySub):
|
||||||
return -_convert(node.expr)
|
return -_convert(node.expr)
|
||||||
raise ValueError('malformed string')
|
raise ValueError('malformed string')
|
||||||
return _convert(node_or_string)
|
return _convert(node_or_string)
|
||||||
|
@ -680,7 +679,6 @@ class AnsibleModule(object):
|
||||||
new_underlying_stat = os.stat(path)
|
new_underlying_stat = os.stat(path)
|
||||||
if underlying_stat.st_mode != new_underlying_stat.st_mode:
|
if underlying_stat.st_mode != new_underlying_stat.st_mode:
|
||||||
os.chmod(path, stat.S_IMODE(underlying_stat.st_mode))
|
os.chmod(path, stat.S_IMODE(underlying_stat.st_mode))
|
||||||
q_stat = os.stat(path)
|
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
if os.path.islink(path) and e.errno == errno.EPERM: # Can't set mode on symbolic links
|
if os.path.islink(path) and e.errno == errno.EPERM: # Can't set mode on symbolic links
|
||||||
pass
|
pass
|
||||||
|
@ -709,7 +707,8 @@ class AnsibleModule(object):
|
||||||
operator = match.group('operator')
|
operator = match.group('operator')
|
||||||
perms = match.group('perms')
|
perms = match.group('perms')
|
||||||
|
|
||||||
if users == 'a': users = 'ugo'
|
if users == 'a':
|
||||||
|
users = 'ugo'
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
mode_to_apply = self._get_octal_mode_from_symbolic_perms(path_stat, user, perms)
|
mode_to_apply = self._get_octal_mode_from_symbolic_perms(path_stat, user, perms)
|
||||||
|
@ -1086,7 +1085,7 @@ class AnsibleModule(object):
|
||||||
|
|
||||||
if is_invalid:
|
if is_invalid:
|
||||||
self.fail_json(msg="argument %s is of invalid type: %s, required: %s" % (k, type(value), wanted))
|
self.fail_json(msg="argument %s is of invalid type: %s, required: %s" % (k, type(value), wanted))
|
||||||
except ValueError, e:
|
except ValueError:
|
||||||
self.fail_json(msg="value of argument %s is not of type %s and we were unable to automatically convert" % (k, wanted))
|
self.fail_json(msg="value of argument %s is not of type %s and we were unable to automatically convert" % (k, wanted))
|
||||||
|
|
||||||
def _set_defaults(self, pre=True):
|
def _set_defaults(self, pre=True):
|
||||||
|
@ -1158,7 +1157,7 @@ class AnsibleModule(object):
|
||||||
journal_args.append((arg.upper(), str(log_args[arg])))
|
journal_args.append((arg.upper(), str(log_args[arg])))
|
||||||
try:
|
try:
|
||||||
journal.send("%s %s" % (module, msg), **dict(journal_args))
|
journal.send("%s %s" % (module, msg), **dict(journal_args))
|
||||||
except IOError, e:
|
except IOError:
|
||||||
# fall back to syslog since logging to journal failed
|
# fall back to syslog since logging to journal failed
|
||||||
syslog.openlog(str(module), 0, syslog.LOG_USER)
|
syslog.openlog(str(module), 0, syslog.LOG_USER)
|
||||||
syslog.syslog(syslog.LOG_INFO, msg) #1
|
syslog.syslog(syslog.LOG_INFO, msg) #1
|
||||||
|
|
Loading…
Reference in New Issue