Here's the latest in our continuing war against UnicodeDecodeError. I don't want to claim victory yet, but I think this patch gets us closer. The real problem is in assembling the string in AnacondaCallback, as usual. All the rest of the patch is just me converting our typical unicode() call into a function so we can be more lazy in the future. - Chris diff --git a/yuminstall.py b/yuminstall.py index a962639..53f6327 100644 --- a/yuminstall.py +++ b/yuminstall.py @@ -67,21 +67,31 @@ urlgrabber.grabber.default_grabber.opts.user_agent = "%s (anaconda)/%s" %(produc import iutil import isys +def toUTF8(str): + if type(str) != unicode: + return unicode(str, encoding='utf-8') + else: + return str + def size_string (size): def number_format(s): return locale.format("%s", s, 1) + retval = None + if size > 1024 * 1024: size = size / (1024*1024) - return _("%s MB") %(number_format(size),) + retval = _("%s MB") %(number_format(size),) elif size > 1024: size = size / 1024 - return _("%s KB") %(number_format(size),) + retval = _("%s KB") %(number_format(size),) else: if size == 1: - return _("%s Byte") %(number_format(size),) + retval = _("%s Byte") %(number_format(size),) else: - return _("%s Bytes") %(number_format(size),) + retval = _("%s Bytes") %(number_format(size),) + + return toUTF8(retval) class AnacondaCallback: @@ -155,14 +165,12 @@ class AnacondaCallback: repo = self.repos.getRepo(po.repoid) pkgStr = "%s-%s-%s.%s" % (po.name, po.version, po.release, po.arch) - s = _("<b>Installing %s</b> (%s)\n") %(pkgStr, size_string(hdr['size'])) - summary = gettext.ldgettext("redhat-dist", hdr['summary'] or "") - if type(summary) != unicode: - summary = unicode(summary, encoding='utf-8') + s = toUTF8(_("<b>Installing %s</b> (%s)\n")) %(pkgStr, size_string(hdr['size'])) + summary = toUTF8(gettext.ldgettext("redhat-dist", hdr['summary'] or "")) s += summary.strip() self.progress.set_label(s) - self.instLog.write(self.modeText % pkgStr) + self.instLog.write(self.modeText % str(pkgStr)) self.instLog.flush() self.openfile = None @@ -645,9 +653,7 @@ class AnacondaYum(YumSorter): else: buttons = [_("Re_boot"), _("_Retry")] - pkgFile = os.path.basename(package.returnSimple('relativepath')) - if type(pkgFile) != unicode: - pkgFile = unicode(pkgFile, encoding='utf-8') + pkgFile = toUTF8(os.path.basename(package.returnSimple('relativepath'))) rc = self.anaconda.intf.messageWindow(_("Error"), _("The file %s cannot be opened. This is due to a missing " @@ -839,11 +845,8 @@ class AnacondaYum(YumSorter): msg = _("There was an error running your transaction for " "the following reason(s): %s.\n") % ', '.join(uniqueProbs.values()) - if type(spaceprob) != unicode: - spaceprob = unicode(spaceprob, encoding='utf-8') - - if type(fileprob) != unicode: - fileprob = unicode(fileprob, encoding='utf-8') + spaceprob = toUTF8(spaceprob) + fileprob = toUTF8(fileprob) if len(self.anaconda.backend.getRequiredMedia()) > 1: intf.detailedMessageWindow(_("Error Running Transaction"), _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list