aboutsummaryrefslogtreecommitdiffstats
path: root/src/msec/libmsec.py
diff options
context:
space:
mode:
authorPapoteur <papoteur@mageialinux-online.org>2015-07-05 11:54:47 +0200
committerThierry Vignaud <thierry.vignaud@gmail.com>2015-07-25 17:24:10 +0200
commit4fac47893db3ede8b27c2d682b1f6d9165f180a8 (patch)
treeb60fcca71959fc6599c2464ae39cf95c43292d91 /src/msec/libmsec.py
parent5134f51bbc3bcc9834cf8a92e1e9b3ab08d04782 (diff)
downloadmsec-4fac47893db3ede8b27c2d682b1f6d9165f180a8.tar
msec-4fac47893db3ede8b27c2d682b1f6d9165f180a8.tar.gz
msec-4fac47893db3ede8b27c2d682b1f6d9165f180a8.tar.bz2
msec-4fac47893db3ede8b27c2d682b1f6d9165f180a8.tar.xz
msec-4fac47893db3ede8b27c2d682b1f6d9165f180a8.zip
Add a Narg function to deal the encoding strings. #mga13837
v1: Thierry Vignaud v2: improved by patpoteur
Diffstat (limited to 'src/msec/libmsec.py')
-rwxr-xr-xsrc/msec/libmsec.py51
1 files changed, 32 insertions, 19 deletions
diff --git a/src/msec/libmsec.py b/src/msec/libmsec.py
index d456eab..4b7e20d 100755
--- a/src/msec/libmsec.py
+++ b/src/msec/libmsec.py
@@ -262,7 +262,7 @@ class ConfigFiles:
if res:
s = substitute_re_result(res, a[1])
if commit:
- self.log.info(_('%s modified so launched command: %s') % (f, s))
+ self.log.info(_('%s modified so launched command: %s') % (Narg(f), Narg(s)))
cmd = commands.getstatusoutput(s)
cmd = [0, '']
if cmd[0] == 0:
@@ -367,32 +367,41 @@ class ConfigFile:
return link
def write(self):
+ if not (type(self.path) == unicode):
+ self.pathN = Narg(self.path)
+ else:
+ self.pathN = self.path
+
if self.is_deleted:
if self.exists():
try:
os.unlink(self.path)
except:
- error('unlink %s: %s' % (self.path, str(sys.exc_value)))
- self.log.info(_('deleted %s') % (self.path,))
+ error('unlink %s: %s' % (self.pathN, str(sys.exc_value)))
+ self.log.info(_('deleted %s') % (self.pathN,))
elif self.is_touched:
if os.path.exists(self.path):
try:
os.utime(self.path, None)
except:
- self.log.error('utime %s: %s' % (self.path, str(sys.exc_value)))
+ self.log.error('utime %s: %s' % (self.pathN, str(sys.exc_value)))
elif self.suffix and os.path.exists(self.path + self.suffix):
move(self.path + self.suffix, self.path)
try:
os.utime(self.path, None)
except:
- self.log.error('utime %s: %s' % (self.path, str(sys.exc_value)))
+ self.log.error('utime %s: %s' % (self.pathN, str(sys.exc_value)))
else:
self.lines = []
self.is_modified = 1
file = open(self.path, 'w')
file.close()
- self.log.info(_('touched file %s') % (self.path,))
+ self.log.info(_('touched file %s') % (self.pathN,))
elif self.sym_link:
+ if not (type(self.sym_link) == unicode):
+ self.sym_linkN = Narg(self.sym_link)
+ else:
+ self.sym_linkN = self.sym_link
done = 0
if self.exists():
full = os.lstat(self.path)
@@ -404,17 +413,21 @@ class ConfigFile:
try:
os.unlink(self.path)
except:
- self.log.error('unlink %s: %s' % (self.path, str(sys.exc_value)))
- self.log.info(_('deleted %s') % (self.path,))
+ self.log.error('unlink %s: %s' % (self.pathN, str(sys.exc_value)))
+ self.log.info(_('deleted %s') % (self.pathN,))
if not done:
try:
os.symlink(self.sym_link, self.path)
except:
- self.log.error('symlink %s %s: %s' % (self.sym_link, self.path, str(sys.exc_value)))
- self.log.info(_('made symbolic link from %s to %s') % (self.sym_link, self.path))
+ self.log.error('symlink %s %s: %s' % (self.sym_linkN, self.path, str(sys.exc_value)))
+ self.log.info(_('made symbolic link from %s to %s') % (self.sym_linkN, self.path))
elif self.is_moved:
+ if not (type(self.suffix) == unicode):
+ self.suffixN = Narg(self.suffix)
+ else:
+ self.suffixN = self.suffix
move(self.path, self.path + self.suffix)
- self.log.info(_('moved file %s to %s') % (self.path, self.path + self.suffix))
+ self.log.info(_('moved file %s to %s') % (self.path, self.path + self.suffixN))
self.meta.modified(self.path)
elif self.is_modified:
content = string.join(self.lines, "\n")
@@ -682,7 +695,7 @@ class MSEC:
self.plugins[plugin_name] = plugin
self.log.debug("Loaded plugin '%s'" % plugin_f)
except:
- self.log.error(_("Error loading plugin '%s' from %s: %s") % (plugin_f, file, sys.exc_value))
+ self.log.error(_("Error loading plugin '%s' from %s: %s") % (plugin_f, file, Narg(sys.exc_value)))
def reset(self):
"""Resets the configuration"""
@@ -699,7 +712,7 @@ class MSEC:
plugin_, callback = name.split(".", 1)
except:
# bad format?
- self.log.error(_("Invalid callback: %s") % (name))
+ self.log.error(_("Invalid callback: %s") % (Narg(name)))
return None
# is it a main function or a plugin?
if plugin_ == config.MAIN_LIB:
@@ -708,14 +721,14 @@ class MSEC:
if plugin_ in self.plugins:
plugin = self.plugins[plugin_]
else:
- self.log.info(_("Plugin %s not found") % plugin_)
+ self.log.info(_("Plugin %s not found") % to_utf8(plugin_))
return self.log.info
return None
try:
func = getattr(plugin, callback)
return func
except:
- self.log.info(_("Not supported function '%s' in '%s'") % (callback, plugin))
+ self.log.info(_("Not supported function '%s' in '%s'") % (Narg(callback), Narg(plugin)))
traceback.print_exc()
return None
@@ -871,7 +884,7 @@ class PERMS:
try:
os.chown(file, newuser, -1)
except:
- self.log.error(_("Error changing user on %s: %s") % (file, sys.exc_value))
+ self.log.error(_("Error changing user on %s: %s") % (file, Narg(sys.exc_value)))
else:
self.log.warn(_("Wrong owner of %s: should be %s") % (file, self.get_user_name(newuser)))
if newgroup != None:
@@ -880,7 +893,7 @@ class PERMS:
try:
os.chown(file, -1, newgroup)
except:
- self.log.error(_("Error changing group on %s: %s") % (file, sys.exc_value))
+ self.log.error(_("Error changing group on %s: %s") % (file, Narg(sys.exc_value)))
else:
self.log.warn(_("Wrong group of %s: should be %s") % (file, self.get_group_name(newgroup)))
# permissions should be last, as chown resets them
@@ -891,7 +904,7 @@ class PERMS:
try:
os.chmod(file, newperm)
except:
- self.log.error(_("Error changing permissions on %s: %s") % (file, sys.exc_value))
+ self.log.error(_("Error changing permissions on %s: %s") % (file, Narg(sys.exc_value)))
else:
self.log.warn(_("Wrong permissions of %s: should be %o") % (file, newperm))
@@ -913,7 +926,7 @@ class PERMS:
# problem setting setfacl
self.log.error(_("Unable to add filesystem-specific ACL %s to %s") % (acluser, file))
except:
- self.log.error(_("Error changing acl on %s: %s") % (file, sys.exc_value))
+ self.log.error(_("Error changing acl on %s: %s") % (file, Narg(str(sys.exc_value))))
else:
self.log.warn(_("Wrong acl of %s") % (file))