Skip to content

Commit

Permalink
Make pep8 tests run against the library directory as well, and associ…
Browse files Browse the repository at this point in the history
…ated tweaks (mostly to indentation) in the library

directory.
  • Loading branch information
mpdehaan committed Aug 11, 2012
1 parent 72faf8e commit 477ca2e
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 137 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ pep8:
@echo "#############################################"
@echo "# Running PEP8 Compliance Tests"
@echo "#############################################"
pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225,E261 lib/ bin/
-pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225,E261 lib/ bin/
-pep8 -r --ignore=E501,E221,W291,W391,E302,E251,E203,W293,E231,E303,E201,E225,E261 --filename "*" library/

pyflakes:
pyflakes lib/ansible/*.py bin/*
Expand Down
8 changes: 4 additions & 4 deletions library/apt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import traceback
# added to stave off future warnings about apt api
import warnings;
import warnings
warnings.filterwarnings('ignore', "apt API not stable yet", FutureWarning)

# APT related constants
Expand All @@ -30,8 +30,7 @@ APT = "DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical %s" % APT_PATH

def run_apt(command):
try:
cmd = subprocess.Popen(command, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmd = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
except (OSError, IOError), e:
rc = 1
Expand Down Expand Up @@ -131,7 +130,8 @@ def main():
)

try:
import apt, apt_pkg
import apt
import apt_pkg
except:
module.fail_json("Could not import python modules: apt, apt_pkg. Please install python-apt package.")

Expand Down
2 changes: 1 addition & 1 deletion library/async_status
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main():
module_fail_json(ansible_job_id=jid, results_file=log_path,
msg="Could not parse job output: %s" % data)

if not data.has_key("started"):
if not 'started' in data:
data['finished'] = 1
data['ansible_job_id'] = jid
module.exit_json(**data)
Expand Down
4 changes: 2 additions & 2 deletions library/command
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def main():
delta = endd - startd

if out is None:
out = ''
out = ''
if err is None:
err = ''
err = ''

module.exit_json(
cmd = args,
Expand Down
26 changes: 13 additions & 13 deletions library/facter
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
import subprocess

def get_facter_data():
p = subprocess.Popen(["/usr/bin/env", "facter", "--json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate()
rc = p.returncode
return rc, out, err
p = subprocess.Popen(["/usr/bin/env", "facter", "--json"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate()
rc = p.returncode
return rc, out, err


def main():
module = AnsibleModule(
argument_spec = dict()
)

rc, out, err = get_facter_data()
if rc != 0:
module.fail_json(msg=err)
else:
module.exit_json(**json.loads(out))
module = AnsibleModule(
argument_spec = dict()
)

rc, out, err = get_facter_data()
if rc != 0:
module.fail_json(msg=err)
else:
module.exit_json(**json.loads(out))

# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
Expand Down
113 changes: 54 additions & 59 deletions library/file
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ def selinux_context(path):
context = ret[1].split(':')
return context

# ===========================================






# ===========================================
# support functions

Expand Down Expand Up @@ -157,72 +150,74 @@ def set_context_if_different(path, context, changed):
return changed

def set_owner_if_different(path, owner, changed):
if owner is None:
return changed
user, group = user_and_group(path)
if owner != user:
try:
uid = pwd.getpwnam(owner).pw_uid
except KeyError:
module_fail_json(path=path, msg='chown failed: failed to look up user %s' % owner)
try:
os.chown(path, uid, -1)
except OSError:
module_fail_json(path=path, msg='chown failed')
return True

return changed
if owner is None:
return changed
user, group = user_and_group(path)
if owner != user:
try:
uid = pwd.getpwnam(owner).pw_uid
except KeyError:
module_fail_json(path=path, msg='chown failed: failed to look up user %s' % owner)
try:
os.chown(path, uid, -1)
except OSError:
module_fail_json(path=path, msg='chown failed')
return True

return changed

def set_group_if_different(path, group, changed):
if group is None:
return changed
old_user, old_group = user_and_group(path)
if old_group != group:
try:
gid = grp.getgrnam(group).gr_gid
except KeyError:
module_fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group)
try:
os.chown(path, -1, gid)
except OSError:
module_fail_json(path=path, msg='chgrp failed')
return True
return changed
if group is None:
return changed
old_user, old_group = user_and_group(path)
if old_group != group:
try:
gid = grp.getgrnam(group).gr_gid
except KeyError:
module_fail_json(path=path, msg='chgrp failed: failed to look up group %s' % group)
try:
os.chown(path, -1, gid)
except OSError:
module_fail_json(path=path, msg='chgrp failed')
return True
return changed

def set_mode_if_different(path, mode, changed):
if mode is None:
return changed
try:
# FIXME: support English modes
mode = int(mode, 8)
except Exception, e:
module_fail_json(path=path, msg='mode needs to be something octalish', details=str(e))

st = os.stat(path)
prev_mode = stat.S_IMODE(st[stat.ST_MODE])

if prev_mode != mode:
# FIXME: comparison against string above will cause this to be executed
# every time
try:
os.chmod(path, mode)
except Exception, e:
module_fail_json(path=path, msg='chmod failed', details=str(e))
if mode is None:
return changed
try:
# FIXME: support English modes
mode = int(mode, 8)
except Exception, e:
module_fail_json(path=path, msg='mode needs to be something octalish', details=str(e))

st = os.stat(path)
new_mode = stat.S_IMODE(st[stat.ST_MODE])
st = os.stat(path)
prev_mode = stat.S_IMODE(st[stat.ST_MODE])

if new_mode != prev_mode:
return True
return changed
if prev_mode != mode:
# FIXME: comparison against string above will cause this to be executed
# every time
try:
os.chmod(path, mode)
except Exception, e:
module_fail_json(path=path, msg='chmod failed', details=str(e))

st = os.stat(path)
new_mode = stat.S_IMODE(st[stat.ST_MODE])

if new_mode != prev_mode:
return True
return changed


def rmtree_error(func, path, exc_info):
module_fail_json(path=path, msg='failed to remove directory')

def main():

# FIXME: pass this around, should not use global
global module

module = AnsibleModule(
check_invalid_arguments = False,
argument_spec = dict(
Expand Down
16 changes: 8 additions & 8 deletions library/mount
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def set_mount(**kwargs):
changed = False
for line in open(args['fstab'], 'r').readlines():
if not line.strip():
to_write.append(line)
continue
to_write.append(line)
continue
if line.strip().startswith('#'):
to_write.append(line)
continue
Expand All @@ -85,9 +85,9 @@ def set_mount(**kwargs):
ld[t] = args[t]

if changed:
to_write.append(new_line % ld)
to_write.append(new_line % ld)
else:
to_write.append(line)
to_write.append(line)

if not exists:
to_write.append(new_line % args)
Expand Down Expand Up @@ -115,8 +115,8 @@ def unset_mount(**kwargs):
changed = False
for line in open(args['fstab'], 'r').readlines():
if not line.strip():
to_write.append(line)
continue
to_write.append(line)
continue
if line.strip().startswith('#'):
to_write.append(line)
continue
Expand Down Expand Up @@ -147,9 +147,9 @@ def mount(**kwargs):

name = kwargs['name']
if os.path.ismount(name):
cmd = ['/bin/mount', '-o', 'remount', name]
cmd = [ '/bin/mount', '-o', 'remount', name ]
else:
cmd = ['/bin/mount', name ]
cmd = [ '/bin/mount', name ]

call = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = call.communicate()
Expand Down
4 changes: 2 additions & 2 deletions library/ohai
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def main():
)
rc, out, err = get_ohai_data()
if rc != 0:
module.fail_json(msg=err)
module.fail_json(msg=err)
else:
module.exit_json(**json.loads(out))
module.exit_json(**json.loads(out))

# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
Expand Down
4 changes: 1 addition & 3 deletions library/service
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,9 @@ def main():
if state:
result['state'] = state
rc, stdout, stderr = _run("%s %s status" % (SERVICE, name))
module.exit_json(**result);

module.exit_json(**result)

# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>

main()

Loading

0 comments on commit 477ca2e

Please sign in to comment.