Skip to content

Commit

Permalink
Fix PyLint C0103 on salt.modules.win_file. Refs saltstack#1775.
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch committed Dec 28, 2012
1 parent e7e377c commit 276b6cb
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions salt/modules/win_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
try:
import win32security
import ntsecuritycon as con
has_windows_modules = True
HAS_WINDOWS_MODULES = True
except ImportError:
has_windows_modules = False
HAS_WINDOWS_MODULES = False

# Import salt libs
import salt.utils
Expand All @@ -36,7 +36,7 @@ def __virtual__():
Only works on Windows systems
'''
if salt.utils.is_windows():
if has_windows_modules:
if HAS_WINDOWS_MODULES:
return 'file'
log.warn(salt.utils.required_modules_error(__file__, __doc__))
return False
Expand Down Expand Up @@ -193,7 +193,7 @@ def chown(path, user, group):
salt '*' file.chown c:\\temp\\test.txt myusername administrators
'''
# I think this function isn't working correctly yet
sd = win32security.GetFileSecurity(
gsd = win32security.GetFileSecurity(
path, win32security.DACL_SECURITY_INFORMATION
)
uid = user_to_uid(user)
Expand All @@ -217,9 +217,9 @@ def chown(path, user, group):
win32security.ACL_REVISION, con.FILE_ALL_ACCESS,
win32security.GetBinarySid(gid)
)
sd.SetSecurityDescriptorDacl(1, dacl, 0)
gsd.SetSecurityDescriptorDacl(1, dacl, 0)
return win32security.SetFileSecurity(
path, win32security.DACL_SECURITY_INFORMATION, sd
path, win32security.DACL_SECURITY_INFORMATION, gsd
)


Expand Down Expand Up @@ -259,14 +259,14 @@ def get_sum(path, form='md5'):
return getattr(hashlib, form)(
salt.utils.fopen(path, 'rb').read()
).hexdigest()
except (IOError, OSError) as e:
return 'File Error: {0}'.format(e)
except (IOError, OSError) as err:
return 'File Error: {0}'.format(err)
except AttributeError:
return 'Hash {0} not supported'.format(form)
except NameError:
return 'Hashlib unavailable - please fix your python install'
except Exception as e:
return str(e)
except Exception as err:
return str(err)


def find(path, **kwargs):
Expand Down Expand Up @@ -361,20 +361,20 @@ def find(path, **kwargs):
salt '*' file.find /var/log name=\*.[0-9] mtime=+30d size=+10m delete
'''
try:
f = salt.utils.find.Finder(kwargs)
finder = salt.utils.find.Finder(kwargs)
except ValueError as ex:
return 'error: {0}'.format(ex)

ret = [p for p in f.find(path)]
ret = [p for p in finder.find(path)]
ret.sort()
return ret


def _sed_esc(s):
def _sed_esc(string):
'''
Escape single quotes and forward slashes
'''
return '{0}'.format(s).replace("'", "'\"'\"'").replace("/", "\/")
return '{0}'.format(string).replace("'", "'\"'\"'").replace("/", "\/")


def sed(path, before, after, limit='', backup='.bak', options='-r -e',
Expand Down Expand Up @@ -542,9 +542,9 @@ def append(path, *args):
'''
# Largely inspired by Fabric's contrib.files.append()

with salt.utils.fopen(path, "a") as f:
with salt.utils.fopen(path, "a") as ofile:
for line in args:
f.write('{0}\n'.format(line))
ofile.write('{0}\n'.format(line))

return "Wrote {0} lines to '{1}'".format(len(args), path)

Expand Down

0 comments on commit 276b6cb

Please sign in to comment.