diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/msec/config.py | 22 | ||||
-rwxr-xr-x | src/msec/libmsec.py | 48 | ||||
-rwxr-xr-x | src/msec/msecgui.py | 15 | ||||
-rwxr-xr-x | src/msec/tools.py | 8 |
4 files changed, 34 insertions, 59 deletions
diff --git a/src/msec/config.py b/src/msec/config.py index 8bbcf86..906f434 100755 --- a/src/msec/config.py +++ b/src/msec/config.py @@ -179,10 +179,6 @@ def to_utf8(s): except: return str(s).decode("utf-8") -def Narg(s): - """ Returns string after decoding if needed. It seems to be no more need in Python 3 """ - return s - # {{{ MsecConfig class MsecConfig: """Msec configuration parser""" @@ -223,7 +219,7 @@ class MsecConfig: try: fd = open(self.config) except: - self.log.error(_("Unable to load configuration file %s: %s") % (self.config, Narg(sys.exc_info()[1]))) + self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_info()[1])) return False for line in fd.readlines(): line = line.strip() @@ -237,7 +233,7 @@ class MsecConfig: option, val = line.split("=", 1) self.options[option] = val except: - self.log.warn(_("Bad config option: %s") % Narg(line)) + self.log.warn(_("Bad config option: %s") % line) continue fd.close() return True @@ -272,7 +268,7 @@ class MsecConfig: try: fd = open(self.config, "w") except: - self.log.error(_("Unable to save %s: %s") % (self.config, Narg(sys.exc_info()[1]))) + self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_info()[1])) return False for comment in self.comments: print(comment, file=fd) @@ -331,7 +327,7 @@ class ExceptionConfig: fd = open(self.config) except: # this file is optional, so if it is not found that's not fatal - self.log.info(_("loading exceptions file %s: %s") % (self.config, Narg(sys.exc_info()[1]))) + self.log.info(_("loading exceptions file %s: %s") % (self.config, sys.exc_info()[1])) self.log.info(_("No exceptions loaded")) return False for line in fd.readlines(): @@ -346,7 +342,7 @@ class ExceptionConfig: option, val = line.split(" ", 1) self.options.append((option, val)) except: - self.log.warn(_("Bad config option: %s") % Narg(line)) + self.log.warn(_("Bad config option: %s") % line) continue fd.close() return True @@ -385,7 +381,7 @@ class ExceptionConfig: try: fd = open(self.config, "w") except: - self.log.error(_("Unable to save %s: %s") % (self.config, Narg(sys.exc_info()[1]))) + self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_info()[1])) return False for comment in self.comments: print(comment, file=fd) @@ -435,7 +431,7 @@ class PermConfig(MsecConfig): try: fd = open(self.config) except: - self.log.error(_("Unable to load configuration file %s: %s") % (self.config, Narg(sys.exc_info()[1]))) + self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_info()[1])) return False for line in fd.readlines(): line = line.strip() @@ -454,7 +450,7 @@ class PermConfig(MsecConfig): self.options_order.append(file) except: traceback.print_exc() - self.log.warn(_("Bad config option: %s") % Narg(line)) + self.log.warn(_("Bad config option: %s") % line) continue fd.close() return True @@ -480,7 +476,7 @@ class PermConfig(MsecConfig): try: fd = open(self.config, "w") except: - self.log.error(_("Unable to save %s: %s") % (self.config, Narg(sys.exc_info()[1]))) + self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_info()[1])) return False for comment in self.comments: print(comment, file=fd) diff --git a/src/msec/libmsec.py b/src/msec/libmsec.py index 95b5060..00eda9c 100755 --- a/src/msec/libmsec.py +++ b/src/msec/libmsec.py @@ -53,7 +53,6 @@ from logging.handlers import SysLogHandler # configuration import config -from config import Narg # localization try: @@ -263,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') % (Narg(f), Narg(s))) + self.log.info(_('%s modified so launched command: %s') % (f, s)) cmd = subprocess.getstatusoutput(s) cmd = [0, ''] if cmd[0] == 0: @@ -368,24 +367,19 @@ class ConfigFile: return link def write(self): - if not (type(self.path) == str): - self.pathN = Narg(self.path) - else: - self.pathN = self.path - if self.is_deleted: if self.exists(): try: os.unlink(self.path) except: - os.error('unlink %s: %s' % (self.pathN, str(sys.exc_info()[1]))) - self.log.info(_('deleted %s') % (self.pathN,)) + os.error('unlink %s: %s' % (self.path, str(sys.exc_info()[1]))) + self.log.info(_('deleted %s') % (self.path,)) elif self.is_touched: if os.path.exists(self.path): try: os.utime(self.path, None) except: - self.log.error('utime %s: %s' % (self.pathN, str(sys.exc_info()[1]))) + self.log.error('utime %s: %s' % (self.path, str(sys.exc_info()[1]))) elif self.suffix and os.path.exists(self.path + self.suffix): move(self.path + self.suffix, self.path) try: @@ -397,12 +391,8 @@ class ConfigFile: self.is_modified = 1 file = open(self.path, 'w') file.close() - self.log.info(_('touched file %s') % (self.pathN,)) + self.log.info(_('touched file %s') % (self.path,)) elif self.sym_link: - if not (type(self.sym_link) == str): - self.sym_linkN = Narg(self.sym_link) - else: - self.sym_linkN = self.sym_link done = 0 if self.exists(): full = os.lstat(self.path) @@ -414,21 +404,17 @@ class ConfigFile: try: os.unlink(self.path) except: - self.log.error('unlink %s: %s' % (self.pathN, str(sys.exc_info()[1]))) - self.log.info(_('deleted %s') % (self.pathN,)) + self.log.error('unlink %s: %s' % (self.path, str(sys.exc_info()[1]))) + self.log.info(_('deleted %s') % (self.path,)) if not done: try: os.symlink(self.sym_link, self.path) except: - self.log.error('symlink %s %s: %s' % (self.sym_linkN, self.path, str(sys.exc_info()[1]))) - self.log.info(_('made symbolic link from %s to %s') % (self.sym_linkN, self.path)) + self.log.error('symlink %s %s: %s' % (self.sym_link, self.path, str(sys.exc_info()[1]))) + self.log.info(_('made symbolic link from %s to %s') % (self.sym_link, self.path)) elif self.is_moved: - if not (type(self.suffix) == str): - 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.suffixN)) + self.log.info(_('moved file %s to %s') % (self.path, self.path + self.suffix)) self.meta.modified(self.path) elif self.is_modified: content = "\n".join(self.lines) @@ -696,7 +682,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, Narg(sys.exc_info()[1]))) + self.log.error(_("Error loading plugin '%s' from %s: %s") % (plugin_f, file, sys.exc_info()[1])) def reset(self): """Resets the configuration""" @@ -713,7 +699,7 @@ class MSEC: plugin_, callback = name.split(".", 1) except: # bad format? - self.log.error(_("Invalid callback: %s") % (Narg(name))) + self.log.error(_("Invalid callback: %s") % (name)) return None # is it a main function or a plugin? if plugin_ == config.MAIN_LIB: @@ -729,7 +715,7 @@ class MSEC: func = getattr(plugin, callback) return func except: - self.log.info(_("Not supported function '%s' in '%s'") % (Narg(callback), Narg(plugin))) + self.log.info(_("Not supported function '%s' in '%s'") % (callback, plugin)) traceback.print_exc() return None @@ -885,7 +871,7 @@ class PERMS: try: os.chown(file, newuser, -1) except: - self.log.error(_("Error changing user on %s: %s") % (file, Narg(sys.exc_info()[1]))) + self.log.error(_("Error changing user on %s: %s") % (file, sys.exc_info()[1])) else: self.log.warn(_("Wrong owner of %s: should be %s") % (file, self.get_user_name(newuser))) if newgroup != None: @@ -894,7 +880,7 @@ class PERMS: try: os.chown(file, -1, newgroup) except: - self.log.error(_("Error changing group on %s: %s") % (file, Narg(sys.exc_info()[1]))) + self.log.error(_("Error changing group on %s: %s") % (file, sys.exc_info()[1])) 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 @@ -905,7 +891,7 @@ class PERMS: try: os.chmod(file, newperm) except: - self.log.error(_("Error changing permissions on %s: %s") % (file, Narg(sys.exc_info()[1]))) + self.log.error(_("Error changing permissions on %s: %s") % (file, sys.exc_info()[1])) else: self.log.warn(_("Wrong permissions of %s: should be %o") % (file, newperm)) @@ -927,7 +913,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, Narg(str(sys.exc_info()[1])))) + self.log.error(_("Error changing acl on %s: %s") % (file, sys.exc_info()[1])) else: self.log.warn(_("Wrong acl of %s") % (file)) diff --git a/src/msec/msecgui.py b/src/msec/msecgui.py index 209b0f8..d6b4203 100755 --- a/src/msec/msecgui.py +++ b/src/msec/msecgui.py @@ -14,8 +14,6 @@ from textwrap import wrap from threading import Thread import time -from config import Narg - # PyGTK import warnings warnings.filterwarnings('error', module='gtk') @@ -381,14 +379,14 @@ class MsecGui: # TODO: FIX for name, changes in allchanges: - label = Gtk.Label(label=_('<b>%s:</b> <i>%s</i>\n') % (Narg(name), Narg(changes))) + label = Gtk.Label(label=_('<b>%s:</b> <i>%s</i>\n') % (name, changes)) label.set_use_markup(True) label.set_property("xalign", 0.0) vbox.pack_start(label, False, False, padding=DEFAULT_SPACING) # see if there were any changes to system files for msg in messages['info']: if msg.find(config.MODIFICATIONS_FOUND) != -1 or msg.find(config.MODIFICATIONS_NOT_FOUND) != -1: - label = Gtk.Label(label=_("<b>MSEC test run results:</b> <i>%s</i>") % Narg(msg)) + label = Gtk.Label(label=_("<b>MSEC test run results:</b> <i>%s</i>") % msg) label.set_line_wrap(True) label.set_use_markup(True) label.set_property("xalign", 0.0) @@ -661,7 +659,7 @@ class MsecGui: for check, logfile, updated_n, updated in tools.periodic_check_status(log): if not updated: updated = _("Never") - label = Gtk.Label(label=_("Check: %s. Last run: %s") % (Narg(check), Narg(updated))) + label = Gtk.Label(label=_("Check: %s. Last run: %s") % (check, updated)) label.set_property("xalign", 0.0) table.attach(label, 2, 3, row, row + 1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, 0, 0, 0) @@ -693,7 +691,7 @@ class MsecGui: with open(logfile, "r") as fd: data = fd.readlines() except: - data = [_("Unable to read log file: %s") % Narg(sys.exc_info()[1])] + data = [_("Unable to read log file: %s") % sys.exc_info()[1]] dialog = Gtk.Dialog(_("Periodic check results"), self.window, 0, @@ -726,7 +724,7 @@ class MsecGui: flags=0, type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.YES_NO) - dialog.set_markup(_("Do you want to run the <b>%s</b> periodic check? Please note that it could take a considerable time to finish.") % Narg(check)) + dialog.set_markup(_("Do you want to run the <b>%s</b> periodic check? Please note that it could take a considerable time to finish.") % check) dialog.show_all() ret = dialog.run() dialog.destroy() @@ -1645,9 +1643,6 @@ class MsecGui: val_def = conf_def.get(param) - for i in [param, descr, value]: - i = Narg(i) - # asks for new parameter value dialog = Gtk.Dialog(_("Select new value for %s") % (param), self.window, 0, diff --git a/src/msec/tools.py b/src/msec/tools.py index baaeca2..044a299 100755 --- a/src/msec/tools.py +++ b/src/msec/tools.py @@ -9,8 +9,6 @@ import sys import time import locale -from config import Narg, SYS_ENC - # localization import gettext try: @@ -32,7 +30,7 @@ def find_firewall_info(log): if l[:3] == "-A ": firewall_entries.append(l.strip()) except: - log.error(_("Unable to parse firewall configuration: %s") % Narg(sys.exc_info()[1])) + log.error(_("Unable to parse firewall configuration: %s") % sys.exc_info()[1]) # not find out if the firewall is enabled if len(firewall_entries) == 0: firewall_status = _("Disabled") @@ -46,9 +44,9 @@ def get_updates_status(log, updatedir="/var/lib/urpmi"): try: ret = os.stat(updatedir) updated = time.localtime(ret[stat.ST_MTIME]) - status = _("Last updated: %s") % Narg(updated_s) + status = _("Last updated: %s") % updated_s except: - log.error(_("Unable to access %s: %s") % (updatedir, Narg(sys.exc_info()[1]))) + log.error(_("Unable to access %s: %s") % (updatedir, sys.exc_info()[1])) status = _("Unable to determine update status") return status |