[yum-commits] Branch 'yum-3_2_X' - 3 commits - yum/i18n.py yumcommands.py

James Antill james at osuosl.org
Fri Mar 27 20:56:08 UTC 2009


 yum/i18n.py    |   34 ++++++++++++++++++++++++++++++----
 yumcommands.py |    4 ++++
 2 files changed, 34 insertions(+), 4 deletions(-)

New commits:
commit 9cf0a5cdcb48b68e477a81ba69fe3f630b5f8317
Author: James Antill <james at and.org>
Date:   Fri Mar 27 03:20:51 2009 -0400

     Speed up text wrapping, by not doing utf8_width() calls when we don't
    need to.

diff --git a/yum/i18n.py b/yum/i18n.py
index d8d4397..51df81f 100755
--- a/yum/i18n.py
+++ b/yum/i18n.py
@@ -294,6 +294,30 @@ def utf8_valid(msg):
             return False
     return True
 
+def _utf8_width_le(width, *args):
+    """ Minor speed hack, we often want to know "does X fit in Y". It takes
+        "a while" to work out a utf8_width() (see above), and we know that a
+        utf8 character is always <= byte. So given:
+
+        assert bytes >= characters
+        characters <= width?
+
+        ...we can change to:
+
+        bytes <= width or characters <= width
+
+        ...and bytes are much faster. """
+    # This assumes that all args. are utf8.
+    ret = 0
+    for arg in args:
+        ret += len(arg)
+    if ret <= width:
+        return True
+    ret = 0
+    for arg in args:
+        ret += utf8_width(arg)
+    return ret <= width
+
 def utf8_text_wrap(text, width=70, initial_indent='', subsequent_indent=''):
     """ Works like we want textwrap.wrap() to work, uses utf-8 data and
         doesn't screw up lists/blocks/etc. """
@@ -320,6 +344,8 @@ def utf8_text_wrap(text, width=70, initial_indent='', subsequent_indent=''):
             if byte != ' ':
                 break
             count += 1
+        if byte not in ("-", "*", ".", "o", '\xe2'):
+            return count, 0
         list_chr = utf8_width_chop(line[count:], 1)[1]
         if list_chr in ("-", "*", ".", "o",
                         "\xe2\x80\xa2", "\xe2\x80\xa3", "\xe2\x88\x98"):
@@ -362,7 +388,7 @@ def utf8_text_wrap(text, width=70, initial_indent='', subsequent_indent=''):
             line = line.lstrip(' ')
             cspc_indent = lspc_indent
 
-        if (utf8_width(indent) + utf8_width(line)) <= width:
+        if _utf8_width_le(width, indent, line):
             wrap_last = False
             ret.append(indent + line)
             indent = subsequent_indent
@@ -375,7 +401,7 @@ def utf8_text_wrap(text, width=70, initial_indent='', subsequent_indent=''):
         if not spcs and csab >= 4:
             spcs = csab
         for word in words:
-            if ((utf8_width(line) + utf8_width(word)) > width and
+            if (not _utf8_width_le(width, line, word) and
                 utf8_width(line) > utf8_width(subsequent_indent)):
                 ret.append(line.rstrip(' '))
                 line = subsequent_indent + ' ' * spcs
commit 4b220f5c3ebe30ca77cd7351b74c072c8f0f3c93
Author: James Antill <james at and.org>
Date:   Fri Mar 27 03:00:34 2009 -0400

    Fix utf8_text_wrap() to deal with "long" URLs, Eg. repolist/metalink

diff --git a/yum/i18n.py b/yum/i18n.py
index 1a3d204..d8d4397 100755
--- a/yum/i18n.py
+++ b/yum/i18n.py
@@ -374,9 +374,9 @@ def utf8_text_wrap(text, width=70, initial_indent='', subsequent_indent=''):
         spcs = cspc_indent
         if not spcs and csab >= 4:
             spcs = csab
-        while words:
-            word = words.pop(0)
-            if (utf8_width(line) + utf8_width(word)) > width:
+        for word in words:
+            if ((utf8_width(line) + utf8_width(word)) > width and
+                utf8_width(line) > utf8_width(subsequent_indent)):
                 ret.append(line.rstrip(' '))
                 line = subsequent_indent + ' ' * spcs
             line += word
commit 08825247e6e34f7efece5b272e67a4a87dca22b9
Author: James Antill <james at and.org>
Date:   Fri Mar 27 02:17:01 2009 -0400

    Add metalink updated time to verbose repolist

diff --git a/yumcommands.py b/yumcommands.py
index c387e4f..b9fe434 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -859,6 +859,10 @@ class RepoListCommand(YumCommand):
                     if repo.metalink:
                         out += [base.fmtKeyValFill(_("Repo-metalink: "),
                                                    repo.metalink)]
+                        if enabled:
+                            ts = repo.metalink_data.repomd.timestamp
+                            out += [base.fmtKeyValFill(_("  Updated    : "),
+                                                       time.ctime(ts))]
                     elif repo.mirrorlist:
                         out += [base.fmtKeyValFill(_("Repo-mirrors: "),
                                                    repo.mirrorlist)]


More information about the Yum-commits mailing list