Mageia Bugzilla – Attachment 5829 Details for
Bug 13837
msec-gui: error message and does not work (UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128))
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
[patch]
decode.path for MSEC (fix bug with locales which use non-english letters)
decode.patch (text/plain), 17.57 KB, created by
Oleg Kozlov
on 2015-01-20 20:32:45 CET
(
hide
)
Description:
decode.path for MSEC (fix bug with locales which use non-english letters)
Filename:
MIME Type:
Creator:
Oleg Kozlov
Created:
2015-01-20 20:32:45 CET
Size:
17.57 KB
patch
obsolete
>diff -ur msec-1.5_orig/src/msec/config.py msec-1.5/src/msec/config.py >--- msec-1.5_orig/src/msec/config.py 2015-01-02 04:40:25.000000000 +0300 >+++ msec-1.5/src/msec/config.py 2015-01-20 21:05:05.585938801 +0300 >@@ -81,6 +81,9 @@ > # checks that support exceptions - defined by 'audit' plugin > CHECKS_WITH_EXCEPTIONS = [] > >+# system encoding >+SYS_ENC = sys.getfilesystemencoding() >+ > # localized help > try: > from help import HELP >@@ -167,6 +170,14 @@ > levelconf = load_func(log, base_level, root=root) > config.merge(levelconf) > >+def try_decode(s): >+ """ Try to decode string without encoding enter """ >+ >+ try: >+ s.decode() >+ return True >+ except: >+ return False > > # {{{ MsecConfig > class MsecConfig: >@@ -208,7 +219,10 @@ > try: > fd = open(self.config) > except: >- self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_value[1])) >+ if try_decode(sys.exc_value[1]): >+ self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_value[1])) >+ else: >+ self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_value[1].decode(SYS_ENC))) > return False > for line in fd.readlines(): > line = line.strip() >@@ -222,7 +236,10 @@ > option, val = line.split("=", 1) > self.options[option] = val > except: >- self.log.warn(_("Bad config option: %s") % line) >+ if (type(line) == unicode) or try_decode(line): >+ self.log.warn(_("Bad config option: %s") % line) >+ else: >+ self.log.warn(_("Bad config option: %s") % line.decode(SYS_ENC)) > continue > fd.close() > return True >@@ -257,7 +274,10 @@ > try: > fd = open(self.config, "w") > except: >- self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) >+ if try_decode(str(sys.exc_value)): >+ self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) >+ else: >+ self.log.error(_("Unable to save %s: %s") % (self.config, str(sys.exc_value).decode(SYS_ENC))) > return False > for comment in self.comments: > print >>fd, comment >@@ -316,7 +336,10 @@ > 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, sys.exc_value[1])) >+ if try_decode(sys.exc_value[1]): >+ self.log.info(_("loading exceptions file %s: %s") % (self.config, sys.exc_value[1])) >+ else: >+ self.log.info(_("loading exceptions file %s: %s") % (self.config, sys.exc_value[1].decode(SYS_ENC))) > self.log.info(_("No exceptions loaded")) > return False > for line in fd.readlines(): >@@ -331,7 +354,10 @@ > option, val = line.split(" ", 1) > self.options.append((option, val)) > except: >- self.log.warn(_("Bad config option: %s") % line) >+ if (type(line) == unicode) or try_decode(line): >+ self.log.warn(_("Bad config option: %s") % line) >+ else: >+ self.log.warn(_("Bad config option: %s") % line.decode(SYS_ENC)) > continue > fd.close() > return True >@@ -370,7 +396,10 @@ > try: > fd = open(self.config, "w") > except: >- self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) >+ if try_decode(str(sys.exc_value)): >+ self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) >+ else: >+ self.log.error(_("Unable to save %s: %s") % (self.config, str(sys.exc_value).decode(SYS_ENC))) > return False > for comment in self.comments: > print >>fd, comment >@@ -420,7 +449,10 @@ > try: > fd = open(self.config) > except: >- self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_value)) >+ if try_decode(str(sys.exc_value)): >+ self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_value)) >+ else: >+ self.log.error(_("Unable to load configuration file %s: %s") % (self.config, str(sys.exc_value).decode(SYS_ENC))) > return False > for line in fd.readlines(): > line = line.strip() >@@ -439,7 +471,10 @@ > self.options_order.append(file) > except: > traceback.print_exc() >- self.log.warn(_("Bad config option: %s") % line) >+ if (type(line) == unicode) or try_decode(line): >+ self.log.warn(_("Bad config option: %s") % line) >+ else: >+ self.log.warn(_("Bad config option: %s") % line.decode(SYS_ENC)) > continue > fd.close() > return True >@@ -465,7 +500,10 @@ > try: > fd = open(self.config, "w") > except: >- self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) >+ if try_decode(line): >+ self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) >+ else: >+ self.log.error(_("Unable to save %s: %s") % (self.config, str(sys.exc_value).decode(SYS_ENC))) > return False > for comment in self.comments: > print >>fd, comment >diff -ur msec-1.5_orig/src/msec/libmsec.py msec-1.5/src/msec/libmsec.py >--- msec-1.5_orig/src/msec/libmsec.py 2015-01-02 04:40:25.000000000 +0300 >+++ msec-1.5/src/msec/libmsec.py 2015-01-20 21:04:47.125930928 +0300 >@@ -261,6 +261,12 @@ > res = a[0].search(f) > if res: > s = substitute_re_result(res, a[1]) >+ >+ if not (type(f) == unicode) and not config.try_decode(f): >+ f = f.decode(config.SYS_ENC) >+ if not (type(s) == unicode) and not config.try_decode(s): >+ s = s.decode(config.SYS_ENC) >+ > if commit: > self.log.info(_('%s modified so launched command: %s') % (f, s)) > cmd = commands.getstatusoutput(s) >@@ -367,6 +373,9 @@ > return link > > def write(self): >+ if not (type(self.path) == unicode) and not config.try_decode(self.path): >+ self.path = self.path.decode(config.SYS_ENC) >+ > if self.is_deleted: > if self.exists(): > try: >@@ -393,6 +402,8 @@ > file.close() > self.log.info(_('touched file %s') % (self.path,)) > elif self.sym_link: >+ if not (type(self.sym_link) == unicode) and not config.try_decode(self.sym_link): >+ self.sym_link = self.sym_link.decode(config.SYS_ENC) > done = 0 > if self.exists(): > full = os.lstat(self.path) >@@ -413,6 +424,8 @@ > 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)) > elif self.is_moved: >+ if not (type(self.suffix) == unicode) and not config.try_decode(self.suffix): >+ self.suffix = self.suffix.decode(config.SYS_ENC) > move(self.path, self.path + self.suffix) > self.log.info(_('moved file %s to %s') % (self.path, self.path + self.suffix)) > self.meta.modified(self.path) >@@ -682,7 +695,10 @@ > 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)) >+ if config.try_decode(str(sys.exc_value)): >+ self.log.error(_("Error loading plugin '%s' from %s: %s") % (plugin_f, file, sys.exc_value)) >+ else: >+ self.log.error(_("Error loading plugin '%s' from %s: %s") % (plugin_f, file, str(sys.exc_value).decode(config.SYS_ENC))) > > def reset(self): > """Resets the configuration""" >@@ -699,7 +715,10 @@ > plugin_, callback = name.split(".", 1) > except: > # bad format? >- self.log.error(_("Invalid callback: %s") % (name)) >+ if (type(name) == unicode) or config.try_decode(name): >+ self.log.error(_("Invalid callback: %s") % (name)) >+ else: >+ self.log.error(_("Invalid callback: %s") % (name.decode(config.SYS_ENC))) > return None > # is it a main function or a plugin? > if plugin_ == config.MAIN_LIB: >@@ -708,13 +727,20 @@ > if plugin_ in self.plugins: > plugin = self.plugins[plugin_] > else: >- self.log.info(_("Plugin %s not found") % plugin_) >+ if (type(plugin_) == unicode) or config.try_decode(plugin_): >+ self.log.info(_("Plugin %s not found") % plugin_) >+ else: >+ self.log.info(_("Plugin %s not found") % plugin_.decode("utf-8")) > return self.log.info > return None > try: > func = getattr(plugin, callback) > return func > except: >+ if not (type(callback) == unicode) and not config.try_decode(callback): >+ callback = callback.decode(config.SYS_ENC) >+ if not (type(plugin) == unicode) and not config.try_decode(plugin): >+ plugin = plugin.decode(SYS_ENC) > self.log.info(_("Not supported function '%s' in '%s'") % (callback, plugin)) > traceback.print_exc() > return None >@@ -871,7 +897,10 @@ > try: > os.chown(file, newuser, -1) > except: >- self.log.error(_("Error changing user on %s: %s") % (file, sys.exc_value)) >+ if config.try_decode(str(sys.exc_value)): >+ self.log.error(_("Error changing user on %s: %s") % (file, sys.exc_value)) >+ else: >+ self.log.error(_("Error changing user on %s: %s") % (file, str(sys.exc_value).decode(config.SYS_ENC))) > else: > self.log.warn(_("Wrong owner of %s: should be %s") % (file, self.get_user_name(newuser))) > if newgroup != None: >@@ -880,7 +909,10 @@ > try: > os.chown(file, -1, newgroup) > except: >- self.log.error(_("Error changing group on %s: %s") % (file, sys.exc_value)) >+ if config.try_decode(str(sys.exc_value)): >+ self.log.error(_("Error changing group on %s: %s") % (file, sys.exc_value)) >+ else: >+ self.log.error(_("Error changing group on %s: %s") % (file, str(sys.exc_value).decode(config.SYS_ENC))) > 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 +923,10 @@ > try: > os.chmod(file, newperm) > except: >- self.log.error(_("Error changing permissions on %s: %s") % (file, sys.exc_value)) >+ if config.try_decode(str(sys.exc_value)): >+ self.log.error(_("Error changing permissions on %s: %s") % (file, sys.exc_value)) >+ else: >+ self.log.error(_("Error changing permissions on %s: %s") % (file, str(sys.exc_value).decode(config.SYS_ENC))) > else: > self.log.warn(_("Wrong permissions of %s: should be %o") % (file, newperm)) > >@@ -913,7 +948,10 @@ > # 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)) >+ if config.try_decode(str(sys.exc_value)): >+ self.log.error(_("Error changing acl on %s: %s") % (file, sys.exc_value)) >+ else: >+ self.log.error(_("Error changing acl on %s: %s") % (file, str(sys.exc_value).decode(config.SYS_ENC))) > else: > self.log.warn(_("Wrong acl of %s") % (file)) > >diff -ur msec-1.5_orig/src/msec/msecgui.py msec-1.5/src/msec/msecgui.py >--- msec-1.5_orig/src/msec/msecgui.py 2015-01-02 04:40:25.000000000 +0300 >+++ msec-1.5/src/msec/msecgui.py 2015-01-20 21:05:38.765952954 +0300 >@@ -379,6 +379,10 @@ > > # TODO: FIX > for name, changes in allchanges: >+ if not config.try_decode(name): >+ name = name.decode(config.SYS_ENC) >+ if not config.try_decode(changes): >+ changes = changes.decode(config.SYS_ENC) > label = Gtk.Label(label=_('<b>%s:</b> <i>%s</i>\n') % (name, changes)) > label.set_use_markup(True) > label.set_property("xalign", 0.0) >@@ -386,6 +390,8 @@ > # 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: >+ if not config.try_decode(msg): >+ msg = msg.decode(config.SYS_ENC) > label = Gtk.Label(label=_("<b>MSEC test run results:</b> <i>%s</i>") % msg) > label.set_line_wrap(True) > label.set_use_markup(True) >@@ -659,6 +665,10 @@ > for check, logfile, updated_n, updated in tools.periodic_check_status(log): > if not updated: > updated = _("Never") >+ elif not config.try_decode(updated): >+ updated = updated.decode(config.SYS_ENC) >+ if not config.try_decode(check): >+ check = check.decode(config.SYS_ENC) > 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) >@@ -691,7 +701,10 @@ > with open(logfile, "r") as fd: > data = fd.readlines() > except: >- data = [_("Unable to read log file: %s") % sys.exc_value] >+ if config.try_decode(str(sys.exc_value)): >+ data = [_("Unable to read log file: %s") % sys.exc_value] >+ else: >+ data = [_("Unable to read log file: %s") % str(sys.exc_value).decode(config.SYS_ENC)] > dialog = Gtk.Dialog(_("Periodic check results"), > self.window, > 0, >@@ -724,6 +737,8 @@ > flags=0, > type=Gtk.MessageType.INFO, > buttons=Gtk.ButtonsType.YES_NO) >+ if not config.try_decode(check): >+ check = check.decode(config.SYS_ENC) > 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() >@@ -1642,6 +1657,10 @@ > sec_end="</b>" > > val_def = conf_def.get(param) >+ >+ for i in [param, descr, value]: >+ if not (type(i) == unicode) and not config.try_decode(i): >+ i = i.decode(config.SYS_ENC) > > # asks for new parameter value > dialog = Gtk.Dialog(_("Select new value for %s") % (param), >diff -ur msec-1.5_orig/src/msec/tools.py msec-1.5/src/msec/tools.py >--- msec-1.5_orig/src/msec/tools.py 2015-01-02 04:40:25.000000000 +0300 >+++ msec-1.5/src/msec/tools.py 2015-01-20 21:07:59.656012714 +0300 >@@ -9,6 +9,8 @@ > import time > import locale > >+from config import try_decode, SYS_ENC >+ > # localization > import gettext > try: >@@ -30,7 +32,10 @@ > if l[:3] == "-A ": > firewall_entries.append(l.strip()) > except: >- log.error(_("Unable to parse firewall configuration: %s") % sys.exc_value) >+ if try_decode(str(sys.exc_value)): >+ log.error(_("Unable to parse firewall configuration: %s") % sys.exc_value) >+ else: >+ log.error(_("Unable to parse firewall configuration: %s") % str(sys.exc_value).decode(SYS_ENC)) > # not find out if the firewall is enabled > if len(firewall_entries) == 0: > firewall_status = _("Disabled") >@@ -45,9 +50,14 @@ > ret = os.stat(updatedir) > updated = time.localtime(ret[stat.ST_MTIME]) > updated_s = time.strftime(locale.nl_langinfo(locale.D_T_FMT), updated) >+ if not try_decode(updated): >+ updated_s = update_s.decode(SYS_ENC) > status = _("Last updated: %s") % updated_s > except: >- log.error(_("Unable to access %s: %s") % (updatedir, sys.exc_value)) >+ if try_decode(str(sys.exc_value)): >+ log.error(_("Unable to access %s: %s") % (updatedir, sys.exc_value)) >+ else: >+ log.error(_("Unable to access %s: %s") % (updatedir, str(sys.exc_value).decode(SYS_ENC))) > status = _("Unable to determine update status") > return status >
diff -ur msec-1.5_orig/src/msec/config.py msec-1.5/src/msec/config.py --- msec-1.5_orig/src/msec/config.py 2015-01-02 04:40:25.000000000 +0300 +++ msec-1.5/src/msec/config.py 2015-01-20 21:05:05.585938801 +0300 @@ -81,6 +81,9 @@ # checks that support exceptions - defined by 'audit' plugin CHECKS_WITH_EXCEPTIONS = [] +# system encoding +SYS_ENC = sys.getfilesystemencoding() + # localized help try: from help import HELP @@ -167,6 +170,14 @@ levelconf = load_func(log, base_level, root=root) config.merge(levelconf) +def try_decode(s): + """ Try to decode string without encoding enter """ + + try: + s.decode() + return True + except: + return False # {{{ MsecConfig class MsecConfig: @@ -208,7 +219,10 @@ try: fd = open(self.config) except: - self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_value[1])) + if try_decode(sys.exc_value[1]): + self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_value[1])) + else: + self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_value[1].decode(SYS_ENC))) return False for line in fd.readlines(): line = line.strip() @@ -222,7 +236,10 @@ option, val = line.split("=", 1) self.options[option] = val except: - self.log.warn(_("Bad config option: %s") % line) + if (type(line) == unicode) or try_decode(line): + self.log.warn(_("Bad config option: %s") % line) + else: + self.log.warn(_("Bad config option: %s") % line.decode(SYS_ENC)) continue fd.close() return True @@ -257,7 +274,10 @@ try: fd = open(self.config, "w") except: - self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) + if try_decode(str(sys.exc_value)): + self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) + else: + self.log.error(_("Unable to save %s: %s") % (self.config, str(sys.exc_value).decode(SYS_ENC))) return False for comment in self.comments: print >>fd, comment @@ -316,7 +336,10 @@ 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, sys.exc_value[1])) + if try_decode(sys.exc_value[1]): + self.log.info(_("loading exceptions file %s: %s") % (self.config, sys.exc_value[1])) + else: + self.log.info(_("loading exceptions file %s: %s") % (self.config, sys.exc_value[1].decode(SYS_ENC))) self.log.info(_("No exceptions loaded")) return False for line in fd.readlines(): @@ -331,7 +354,10 @@ option, val = line.split(" ", 1) self.options.append((option, val)) except: - self.log.warn(_("Bad config option: %s") % line) + if (type(line) == unicode) or try_decode(line): + self.log.warn(_("Bad config option: %s") % line) + else: + self.log.warn(_("Bad config option: %s") % line.decode(SYS_ENC)) continue fd.close() return True @@ -370,7 +396,10 @@ try: fd = open(self.config, "w") except: - self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) + if try_decode(str(sys.exc_value)): + self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) + else: + self.log.error(_("Unable to save %s: %s") % (self.config, str(sys.exc_value).decode(SYS_ENC))) return False for comment in self.comments: print >>fd, comment @@ -420,7 +449,10 @@ try: fd = open(self.config) except: - self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_value)) + if try_decode(str(sys.exc_value)): + self.log.error(_("Unable to load configuration file %s: %s") % (self.config, sys.exc_value)) + else: + self.log.error(_("Unable to load configuration file %s: %s") % (self.config, str(sys.exc_value).decode(SYS_ENC))) return False for line in fd.readlines(): line = line.strip() @@ -439,7 +471,10 @@ self.options_order.append(file) except: traceback.print_exc() - self.log.warn(_("Bad config option: %s") % line) + if (type(line) == unicode) or try_decode(line): + self.log.warn(_("Bad config option: %s") % line) + else: + self.log.warn(_("Bad config option: %s") % line.decode(SYS_ENC)) continue fd.close() return True @@ -465,7 +500,10 @@ try: fd = open(self.config, "w") except: - self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) + if try_decode(line): + self.log.error(_("Unable to save %s: %s") % (self.config, sys.exc_value)) + else: + self.log.error(_("Unable to save %s: %s") % (self.config, str(sys.exc_value).decode(SYS_ENC))) return False for comment in self.comments: print >>fd, comment diff -ur msec-1.5_orig/src/msec/libmsec.py msec-1.5/src/msec/libmsec.py --- msec-1.5_orig/src/msec/libmsec.py 2015-01-02 04:40:25.000000000 +0300 +++ msec-1.5/src/msec/libmsec.py 2015-01-20 21:04:47.125930928 +0300 @@ -261,6 +261,12 @@ res = a[0].search(f) if res: s = substitute_re_result(res, a[1]) + + if not (type(f) == unicode) and not config.try_decode(f): + f = f.decode(config.SYS_ENC) + if not (type(s) == unicode) and not config.try_decode(s): + s = s.decode(config.SYS_ENC) + if commit: self.log.info(_('%s modified so launched command: %s') % (f, s)) cmd = commands.getstatusoutput(s) @@ -367,6 +373,9 @@ return link def write(self): + if not (type(self.path) == unicode) and not config.try_decode(self.path): + self.path = self.path.decode(config.SYS_ENC) + if self.is_deleted: if self.exists(): try: @@ -393,6 +402,8 @@ file.close() self.log.info(_('touched file %s') % (self.path,)) elif self.sym_link: + if not (type(self.sym_link) == unicode) and not config.try_decode(self.sym_link): + self.sym_link = self.sym_link.decode(config.SYS_ENC) done = 0 if self.exists(): full = os.lstat(self.path) @@ -413,6 +424,8 @@ 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)) elif self.is_moved: + if not (type(self.suffix) == unicode) and not config.try_decode(self.suffix): + self.suffix = self.suffix.decode(config.SYS_ENC) move(self.path, self.path + self.suffix) self.log.info(_('moved file %s to %s') % (self.path, self.path + self.suffix)) self.meta.modified(self.path) @@ -682,7 +695,10 @@ 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)) + if config.try_decode(str(sys.exc_value)): + self.log.error(_("Error loading plugin '%s' from %s: %s") % (plugin_f, file, sys.exc_value)) + else: + self.log.error(_("Error loading plugin '%s' from %s: %s") % (plugin_f, file, str(sys.exc_value).decode(config.SYS_ENC))) def reset(self): """Resets the configuration""" @@ -699,7 +715,10 @@ plugin_, callback = name.split(".", 1) except: # bad format? - self.log.error(_("Invalid callback: %s") % (name)) + if (type(name) == unicode) or config.try_decode(name): + self.log.error(_("Invalid callback: %s") % (name)) + else: + self.log.error(_("Invalid callback: %s") % (name.decode(config.SYS_ENC))) return None # is it a main function or a plugin? if plugin_ == config.MAIN_LIB: @@ -708,13 +727,20 @@ if plugin_ in self.plugins: plugin = self.plugins[plugin_] else: - self.log.info(_("Plugin %s not found") % plugin_) + if (type(plugin_) == unicode) or config.try_decode(plugin_): + self.log.info(_("Plugin %s not found") % plugin_) + else: + self.log.info(_("Plugin %s not found") % plugin_.decode("utf-8")) return self.log.info return None try: func = getattr(plugin, callback) return func except: + if not (type(callback) == unicode) and not config.try_decode(callback): + callback = callback.decode(config.SYS_ENC) + if not (type(plugin) == unicode) and not config.try_decode(plugin): + plugin = plugin.decode(SYS_ENC) self.log.info(_("Not supported function '%s' in '%s'") % (callback, plugin)) traceback.print_exc() return None @@ -871,7 +897,10 @@ try: os.chown(file, newuser, -1) except: - self.log.error(_("Error changing user on %s: %s") % (file, sys.exc_value)) + if config.try_decode(str(sys.exc_value)): + self.log.error(_("Error changing user on %s: %s") % (file, sys.exc_value)) + else: + self.log.error(_("Error changing user on %s: %s") % (file, str(sys.exc_value).decode(config.SYS_ENC))) else: self.log.warn(_("Wrong owner of %s: should be %s") % (file, self.get_user_name(newuser))) if newgroup != None: @@ -880,7 +909,10 @@ try: os.chown(file, -1, newgroup) except: - self.log.error(_("Error changing group on %s: %s") % (file, sys.exc_value)) + if config.try_decode(str(sys.exc_value)): + self.log.error(_("Error changing group on %s: %s") % (file, sys.exc_value)) + else: + self.log.error(_("Error changing group on %s: %s") % (file, str(sys.exc_value).decode(config.SYS_ENC))) 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 +923,10 @@ try: os.chmod(file, newperm) except: - self.log.error(_("Error changing permissions on %s: %s") % (file, sys.exc_value)) + if config.try_decode(str(sys.exc_value)): + self.log.error(_("Error changing permissions on %s: %s") % (file, sys.exc_value)) + else: + self.log.error(_("Error changing permissions on %s: %s") % (file, str(sys.exc_value).decode(config.SYS_ENC))) else: self.log.warn(_("Wrong permissions of %s: should be %o") % (file, newperm)) @@ -913,7 +948,10 @@ # 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)) + if config.try_decode(str(sys.exc_value)): + self.log.error(_("Error changing acl on %s: %s") % (file, sys.exc_value)) + else: + self.log.error(_("Error changing acl on %s: %s") % (file, str(sys.exc_value).decode(config.SYS_ENC))) else: self.log.warn(_("Wrong acl of %s") % (file)) diff -ur msec-1.5_orig/src/msec/msecgui.py msec-1.5/src/msec/msecgui.py --- msec-1.5_orig/src/msec/msecgui.py 2015-01-02 04:40:25.000000000 +0300 +++ msec-1.5/src/msec/msecgui.py 2015-01-20 21:05:38.765952954 +0300 @@ -379,6 +379,10 @@ # TODO: FIX for name, changes in allchanges: + if not config.try_decode(name): + name = name.decode(config.SYS_ENC) + if not config.try_decode(changes): + changes = changes.decode(config.SYS_ENC) label = Gtk.Label(label=_('<b>%s:</b> <i>%s</i>\n') % (name, changes)) label.set_use_markup(True) label.set_property("xalign", 0.0) @@ -386,6 +390,8 @@ # 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: + if not config.try_decode(msg): + msg = msg.decode(config.SYS_ENC) label = Gtk.Label(label=_("<b>MSEC test run results:</b> <i>%s</i>") % msg) label.set_line_wrap(True) label.set_use_markup(True) @@ -659,6 +665,10 @@ for check, logfile, updated_n, updated in tools.periodic_check_status(log): if not updated: updated = _("Never") + elif not config.try_decode(updated): + updated = updated.decode(config.SYS_ENC) + if not config.try_decode(check): + check = check.decode(config.SYS_ENC) 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) @@ -691,7 +701,10 @@ with open(logfile, "r") as fd: data = fd.readlines() except: - data = [_("Unable to read log file: %s") % sys.exc_value] + if config.try_decode(str(sys.exc_value)): + data = [_("Unable to read log file: %s") % sys.exc_value] + else: + data = [_("Unable to read log file: %s") % str(sys.exc_value).decode(config.SYS_ENC)] dialog = Gtk.Dialog(_("Periodic check results"), self.window, 0, @@ -724,6 +737,8 @@ flags=0, type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.YES_NO) + if not config.try_decode(check): + check = check.decode(config.SYS_ENC) 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() @@ -1642,6 +1657,10 @@ sec_end="</b>" val_def = conf_def.get(param) + + for i in [param, descr, value]: + if not (type(i) == unicode) and not config.try_decode(i): + i = i.decode(config.SYS_ENC) # asks for new parameter value dialog = Gtk.Dialog(_("Select new value for %s") % (param), diff -ur msec-1.5_orig/src/msec/tools.py msec-1.5/src/msec/tools.py --- msec-1.5_orig/src/msec/tools.py 2015-01-02 04:40:25.000000000 +0300 +++ msec-1.5/src/msec/tools.py 2015-01-20 21:07:59.656012714 +0300 @@ -9,6 +9,8 @@ import time import locale +from config import try_decode, SYS_ENC + # localization import gettext try: @@ -30,7 +32,10 @@ if l[:3] == "-A ": firewall_entries.append(l.strip()) except: - log.error(_("Unable to parse firewall configuration: %s") % sys.exc_value) + if try_decode(str(sys.exc_value)): + log.error(_("Unable to parse firewall configuration: %s") % sys.exc_value) + else: + log.error(_("Unable to parse firewall configuration: %s") % str(sys.exc_value).decode(SYS_ENC)) # not find out if the firewall is enabled if len(firewall_entries) == 0: firewall_status = _("Disabled") @@ -45,9 +50,14 @@ ret = os.stat(updatedir) updated = time.localtime(ret[stat.ST_MTIME]) updated_s = time.strftime(locale.nl_langinfo(locale.D_T_FMT), updated) + if not try_decode(updated): + updated_s = update_s.decode(SYS_ENC) status = _("Last updated: %s") % updated_s except: - log.error(_("Unable to access %s: %s") % (updatedir, sys.exc_value)) + if try_decode(str(sys.exc_value)): + log.error(_("Unable to access %s: %s") % (updatedir, sys.exc_value)) + else: + log.error(_("Unable to access %s: %s") % (updatedir, str(sys.exc_value).decode(SYS_ENC))) status = _("Unable to determine update status") return status
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 13837
: 5829 |
6514
|
6815
|
6869