Misc. cleanup in file state/module

Single quotes, minor pep8 fixes ("x not in y", instead of "not x in y"),
and clarified a few comments.
This commit is contained in:
Erik Johnson 2014-05-29 23:59:01 -05:00
parent 796b709d96
commit 1c69a05f16
2 changed files with 28 additions and 42 deletions

View File

@ -1063,7 +1063,7 @@ def replace(path,
found = True found = True
# Identity check each potential change until one change is made # Identity check each potential change until one change is made
if has_changes is False and not result is line: if has_changes is False and result is not line:
has_changes = True has_changes = True
if show_changes: if show_changes:
@ -1225,8 +1225,8 @@ def blockreplace(path,
content = content[:-1] content = content[:-1]
# push new block content in file # push new block content in file
for cline in content.split("\n"): for cline in content.split('\n'):
new_file.append(cline + "\n") new_file.append(cline + '\n')
done = True done = True
@ -1550,7 +1550,7 @@ def prepend(path, *args):
preface = [] preface = []
for line in args: for line in args:
preface.append("{0}\n".format(line)) preface.append('{0}\n'.format(line))
with salt.utils.fopen(path, "w") as ofile: with salt.utils.fopen(path, "w") as ofile:
contents = preface + contents contents = preface + contents
@ -3159,10 +3159,8 @@ def mknod_chrdev(name,
'changes': {}, 'changes': {},
'comment': '', 'comment': '',
'result': False} 'result': False}
log.debug("Creating character device name:{0} major:{1} minor:{2} mode:{3}".format(name, log.debug('Creating character device name:{0} major:{1} minor:{2} mode:{3}'
major, .format(name, major, minor, mode))
minor,
mode))
try: try:
if __opts__['test']: if __opts__['test']:
ret['changes'] = {'new': 'Character device {0} created.'.format(name)} ret['changes'] = {'new': 'Character device {0} created.'.format(name)}
@ -3232,10 +3230,8 @@ def mknod_blkdev(name,
'changes': {}, 'changes': {},
'comment': '', 'comment': '',
'result': False} 'result': False}
log.debug("Creating block device name:{0} major:{1} minor:{2} mode:{3}".format(name, log.debug('Creating block device name:{0} major:{1} minor:{2} mode:{3}'
major, .format(name, major, minor, mode))
minor,
mode))
try: try:
if __opts__['test']: if __opts__['test']:
ret['changes'] = {'new': 'Block device {0} created.'.format(name)} ret['changes'] = {'new': 'Block device {0} created.'.format(name)}
@ -3303,7 +3299,7 @@ def mknod_fifo(name,
'changes': {}, 'changes': {},
'comment': '', 'comment': '',
'result': False} 'result': False}
log.debug("Creating FIFO name:{0}".format(name)) log.debug('Creating FIFO name: {0}'.format(name))
try: try:
if __opts__['test']: if __opts__['test']:
ret['changes'] = {'new': 'Fifo pipe {0} created.'.format(name)} ret['changes'] = {'new': 'Fifo pipe {0} created.'.format(name)}
@ -3351,26 +3347,16 @@ def mknod(name,
ret = False ret = False
makedirs_(name, user, group) makedirs_(name, user, group)
if ntype == 'c': if ntype == 'c':
ret = mknod_chrdev(name, ret = mknod_chrdev(name, major, minor, user, group, mode)
major,
minor,
user,
group,
mode)
elif ntype == 'b': elif ntype == 'b':
ret = mknod_blkdev(name, ret = mknod_blkdev(name, major, minor, user, group, mode)
major,
minor,
user,
group,
mode)
elif ntype == 'p': elif ntype == 'p':
ret = mknod_fifo(name, ret = mknod_fifo(name, user, group, mode)
user,
group,
mode)
else: else:
raise Exception("Node type unavailable: '{0}'. Available node types are character ('c'), block ('b'), and pipe ('p').".format(ntype)) raise SaltInvocationError(
'Node type unavailable: {0!r}. Available node types are '
'character (\'c\'), block (\'b\'), and pipe (\'p\').'.format(ntype)
)
return ret return ret
@ -3649,7 +3635,7 @@ def open_files(by_pid=False):
except OSError: except OSError:
continue continue
if not name in files: if name not in files:
files[name] = [pid] files[name] = [pid]
else: else:
# We still want to know which PIDs are using each file # We still want to know which PIDs are using each file

View File

@ -3719,14 +3719,14 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
'result': False} 'result': False}
if ntype == 'c': if ntype == 'c':
# check for file existence # Check for file existence
if __salt__['file.file_exists'](name): if __salt__['file.file_exists'](name):
ret['comment'] = ( ret['comment'] = (
'File exists and is not a character device {0}. Cowardly ' 'File exists and is not a character device {0}. Cowardly '
'refusing to continue'.format(name) 'refusing to continue'.format(name)
) )
#if it is a character device # Check if it is a character device
elif not __salt__['file.is_chrdev'](name): elif not __salt__['file.is_chrdev'](name):
if __opts__['test']: if __opts__['test']:
ret['comment'] = ( ret['comment'] = (
@ -3742,7 +3742,7 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
group, group,
mode) mode)
# check the major/minor # Check the major/minor
else: else:
devmaj, devmin = __salt__['file.get_devmm'](name) devmaj, devmin = __salt__['file.get_devmm'](name)
if (major, minor) != (devmaj, devmin): if (major, minor) != (devmaj, devmin):
@ -3751,7 +3751,7 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
'major/minor {1}/{2}. Cowardly refusing to continue' 'major/minor {1}/{2}. Cowardly refusing to continue'
.format(name, devmaj, devmin) .format(name, devmaj, devmin)
) )
#check the perms # Check the perms
else: else:
ret = __salt__['file.check_perms'](name, ret = __salt__['file.check_perms'](name,
None, None,
@ -3766,14 +3766,14 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
) )
elif ntype == 'b': elif ntype == 'b':
# check for file existence # Check for file existence
if __salt__['file.file_exists'](name): if __salt__['file.file_exists'](name):
ret['comment'] = ( ret['comment'] = (
'File exists and is not a block device {0}. Cowardly ' 'File exists and is not a block device {0}. Cowardly '
'refusing to continue'.format(name) 'refusing to continue'.format(name)
) )
# if it is a block device # Check if it is a block device
elif not __salt__['file.is_blkdev'](name): elif not __salt__['file.is_blkdev'](name):
if __opts__['test']: if __opts__['test']:
ret['comment'] = ( ret['comment'] = (
@ -3789,7 +3789,7 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
group, group,
mode) mode)
# check the major/minor # Check the major/minor
else: else:
devmaj, devmin = __salt__['file.get_devmm'](name) devmaj, devmin = __salt__['file.get_devmm'](name)
if (major, minor) != (devmaj, devmin): if (major, minor) != (devmaj, devmin):
@ -3799,7 +3799,7 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
name, devmaj, devmin name, devmaj, devmin
) )
) )
# check the perms # Check the perms
else: else:
ret = __salt__['file.check_perms'](name, ret = __salt__['file.check_perms'](name,
None, None,
@ -3812,14 +3812,14 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
) )
elif ntype == 'p': elif ntype == 'p':
# check for file existence, if it is a fifo, user, group, and mode # Check for file existence
if __salt__['file.file_exists'](name): if __salt__['file.file_exists'](name):
ret['comment'] = ( ret['comment'] = (
'File exists and is not a fifo pipe {0}. Cowardly refusing ' 'File exists and is not a fifo pipe {0}. Cowardly refusing '
'to continue'.format(name) 'to continue'.format(name)
) )
# if it is a fifo # Check if it is a fifo
elif not __salt__['file.is_fifo'](name): elif not __salt__['file.is_fifo'](name):
if __opts__['test']: if __opts__['test']:
ret['comment'] = 'Fifo pipe {0} is set to be created'.format( ret['comment'] = 'Fifo pipe {0} is set to be created'.format(
@ -3835,7 +3835,7 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
group, group,
mode) mode)
# check the perms # Check the perms
else: else:
ret = __salt__['file.check_perms'](name, ret = __salt__['file.check_perms'](name,
None, None,