mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
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:
parent
796b709d96
commit
1c69a05f16
@ -1063,7 +1063,7 @@ def replace(path,
|
||||
found = True
|
||||
|
||||
# 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
|
||||
|
||||
if show_changes:
|
||||
@ -1225,8 +1225,8 @@ def blockreplace(path,
|
||||
content = content[:-1]
|
||||
|
||||
# push new block content in file
|
||||
for cline in content.split("\n"):
|
||||
new_file.append(cline + "\n")
|
||||
for cline in content.split('\n'):
|
||||
new_file.append(cline + '\n')
|
||||
|
||||
done = True
|
||||
|
||||
@ -1550,7 +1550,7 @@ def prepend(path, *args):
|
||||
|
||||
preface = []
|
||||
for line in args:
|
||||
preface.append("{0}\n".format(line))
|
||||
preface.append('{0}\n'.format(line))
|
||||
|
||||
with salt.utils.fopen(path, "w") as ofile:
|
||||
contents = preface + contents
|
||||
@ -3159,10 +3159,8 @@ def mknod_chrdev(name,
|
||||
'changes': {},
|
||||
'comment': '',
|
||||
'result': False}
|
||||
log.debug("Creating character device name:{0} major:{1} minor:{2} mode:{3}".format(name,
|
||||
major,
|
||||
minor,
|
||||
mode))
|
||||
log.debug('Creating character device name:{0} major:{1} minor:{2} mode:{3}'
|
||||
.format(name, major, minor, mode))
|
||||
try:
|
||||
if __opts__['test']:
|
||||
ret['changes'] = {'new': 'Character device {0} created.'.format(name)}
|
||||
@ -3232,10 +3230,8 @@ def mknod_blkdev(name,
|
||||
'changes': {},
|
||||
'comment': '',
|
||||
'result': False}
|
||||
log.debug("Creating block device name:{0} major:{1} minor:{2} mode:{3}".format(name,
|
||||
major,
|
||||
minor,
|
||||
mode))
|
||||
log.debug('Creating block device name:{0} major:{1} minor:{2} mode:{3}'
|
||||
.format(name, major, minor, mode))
|
||||
try:
|
||||
if __opts__['test']:
|
||||
ret['changes'] = {'new': 'Block device {0} created.'.format(name)}
|
||||
@ -3303,7 +3299,7 @@ def mknod_fifo(name,
|
||||
'changes': {},
|
||||
'comment': '',
|
||||
'result': False}
|
||||
log.debug("Creating FIFO name:{0}".format(name))
|
||||
log.debug('Creating FIFO name: {0}'.format(name))
|
||||
try:
|
||||
if __opts__['test']:
|
||||
ret['changes'] = {'new': 'Fifo pipe {0} created.'.format(name)}
|
||||
@ -3351,26 +3347,16 @@ def mknod(name,
|
||||
ret = False
|
||||
makedirs_(name, user, group)
|
||||
if ntype == 'c':
|
||||
ret = mknod_chrdev(name,
|
||||
major,
|
||||
minor,
|
||||
user,
|
||||
group,
|
||||
mode)
|
||||
ret = mknod_chrdev(name, major, minor, user, group, mode)
|
||||
elif ntype == 'b':
|
||||
ret = mknod_blkdev(name,
|
||||
major,
|
||||
minor,
|
||||
user,
|
||||
group,
|
||||
mode)
|
||||
ret = mknod_blkdev(name, major, minor, user, group, mode)
|
||||
elif ntype == 'p':
|
||||
ret = mknod_fifo(name,
|
||||
user,
|
||||
group,
|
||||
mode)
|
||||
ret = mknod_fifo(name, user, group, mode)
|
||||
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
|
||||
|
||||
|
||||
@ -3649,7 +3635,7 @@ def open_files(by_pid=False):
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
if not name in files:
|
||||
if name not in files:
|
||||
files[name] = [pid]
|
||||
else:
|
||||
# We still want to know which PIDs are using each file
|
||||
|
@ -3719,14 +3719,14 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
|
||||
'result': False}
|
||||
|
||||
if ntype == 'c':
|
||||
# check for file existence
|
||||
# Check for file existence
|
||||
if __salt__['file.file_exists'](name):
|
||||
ret['comment'] = (
|
||||
'File exists and is not a character device {0}. Cowardly '
|
||||
'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):
|
||||
if __opts__['test']:
|
||||
ret['comment'] = (
|
||||
@ -3742,7 +3742,7 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
|
||||
group,
|
||||
mode)
|
||||
|
||||
# check the major/minor
|
||||
# Check the major/minor
|
||||
else:
|
||||
devmaj, devmin = __salt__['file.get_devmm'](name)
|
||||
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'
|
||||
.format(name, devmaj, devmin)
|
||||
)
|
||||
#check the perms
|
||||
# Check the perms
|
||||
else:
|
||||
ret = __salt__['file.check_perms'](name,
|
||||
None,
|
||||
@ -3766,14 +3766,14 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
|
||||
)
|
||||
|
||||
elif ntype == 'b':
|
||||
# check for file existence
|
||||
# Check for file existence
|
||||
if __salt__['file.file_exists'](name):
|
||||
ret['comment'] = (
|
||||
'File exists and is not a block device {0}. Cowardly '
|
||||
'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):
|
||||
if __opts__['test']:
|
||||
ret['comment'] = (
|
||||
@ -3789,7 +3789,7 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
|
||||
group,
|
||||
mode)
|
||||
|
||||
# check the major/minor
|
||||
# Check the major/minor
|
||||
else:
|
||||
devmaj, devmin = __salt__['file.get_devmm'](name)
|
||||
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
|
||||
)
|
||||
)
|
||||
# check the perms
|
||||
# Check the perms
|
||||
else:
|
||||
ret = __salt__['file.check_perms'](name,
|
||||
None,
|
||||
@ -3812,14 +3812,14 @@ def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
|
||||
)
|
||||
|
||||
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):
|
||||
ret['comment'] = (
|
||||
'File exists and is not a fifo pipe {0}. Cowardly refusing '
|
||||
'to continue'.format(name)
|
||||
)
|
||||
|
||||
# if it is a fifo
|
||||
# Check if it is a fifo
|
||||
elif not __salt__['file.is_fifo'](name):
|
||||
if __opts__['test']:
|
||||
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,
|
||||
mode)
|
||||
|
||||
# check the perms
|
||||
# Check the perms
|
||||
else:
|
||||
ret = __salt__['file.check_perms'](name,
|
||||
None,
|
||||
|
Loading…
Reference in New Issue
Block a user