[yum-commits] Branch 'yum-3_2_X' - 4 commits - output.py yum/i18n.py yum/update_md.py
James Antill
james at osuosl.org
Mon Dec 15 23:08:52 UTC 2008
output.py | 12 ++++----
yum/i18n.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
yum/update_md.py | 6 ++--
3 files changed, 86 insertions(+), 9 deletions(-)
New commits:
commit 3e22d0e653506aa058d1564a57a5a4d88862d404
Author: James Antill <james at and.org>
Date: Mon Dec 15 18:05:00 2008 -0500
Add o as list option, for FEDORA-2008-9779 among others
diff --git a/yum/i18n.py b/yum/i18n.py
index d8b56dc..fb7a5ac 100755
--- a/yum/i18n.py
+++ b/yum/i18n.py
@@ -293,7 +293,7 @@ def utf8_text_wrap(text, width=70, initial_indent='', subsequent_indent=''):
break
count += 1
list_chr = utf8_width_chop(line[count:], 1)[1]
- if list_chr in ("-", "*", ".",
+ if list_chr in ("-", "*", ".", "o",
"\xe2\x80\xa2", "\xe2\x80\xa3", "\xe2\x88\x98"):
nxt = _indent_at_beg(line[count+len(list_chr):])
nxt = nxt[1] or nxt[0]
commit f017b2dd25139bdd18b3b75c1b12eb8fab9f1cdc
Author: James Antill <james at and.org>
Date: Mon Dec 15 17:53:23 2008 -0500
Use our utf8/non-broken, textwrap, for yum info-security
diff --git a/yum/update_md.py b/yum/update_md.py
index 25613e9..a2b2008 100644
--- a/yum/update_md.py
+++ b/yum/update_md.py
@@ -24,7 +24,7 @@ Update metadata (updateinfo.xml) parsing.
import sys
import gzip
-from textwrap import wrap
+from yum.i18n import utf8_text_wrap
from yum.yumRepo import YumRepository
from yum.misc import to_xml
@@ -106,8 +106,8 @@ class UpdateNotice(object):
head += cvelist[: - 1].rstrip() + '\n'
if self._md['description'] is not None:
- desc = wrap(self._md['description'], width=64,
- subsequent_indent=' ' * 12 + ': ')
+ desc = utf8_text_wrap(self._md['description'], width=64,
+ subsequent_indent=' ' * 12 + ': ')
head += "Description : %s\n" % '\n'.join(desc)
# Get a list of arches we care about:
commit b24dfe9b51431de6b214561ba58ea2520372907e
Author: James Antill <james at and.org>
Date: Mon Dec 15 17:53:07 2008 -0500
Use our utf8/non-broken, textwrap, for yum info
diff --git a/output.py b/output.py
index 9cdac35..3416459 100755
--- a/output.py
+++ b/output.py
@@ -38,8 +38,7 @@ from yum import logginglevels, _
from yum.rpmtrans import RPMBaseCallback
from yum.packageSack import packagesNewestByNameArch
-from textwrap import fill
-from yum.i18n import utf8_width, utf8_width_fill
+from yum.i18n import utf8_width, utf8_width_fill, utf8_text_fill
def _term_width():
""" Simple terminal width, limit to 20 chars. and make 0 == 80. """
@@ -490,12 +489,13 @@ class YumOutput:
keylen = utf8_width(key)
cols = self.term.columns
nxt = ' ' * (keylen - 2) + ': '
- ret = fill(val, width=cols,
- initial_indent=key, subsequent_indent=nxt)
+ ret = utf8_text_fill(val, width=cols,
+ initial_indent=key, subsequent_indent=nxt)
if ret.count("\n") > 1 and keylen > (cols / 3):
# If it's big, redo it again with a smaller subsequent off
- ret = fill(val, width=cols,
- initial_indent=key, subsequent_indent=' ...: ')
+ ret = utf8_text_fill(val, width=cols,
+ initial_indent=key,
+ subsequent_indent=' ...: ')
return ret
def fmtSection(self, name, fill='='):
commit a179ff77280f2dbf86a03383d3fedb560b24db9f
Author: James Antill <james at and.org>
Date: Mon Dec 15 17:52:32 2008 -0500
Add textwrap.wrap/fill ... as the core versions are broken in various ways
diff --git a/yum/i18n.py b/yum/i18n.py
index bcc895e..d8b56dc 100755
--- a/yum/i18n.py
+++ b/yum/i18n.py
@@ -275,6 +275,83 @@ def utf8_valid(msg):
if ucs is None:
return False
return True
+
+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. """
+ # Tested with:
+ # yum info robodoc gpicview php-pear-Net-Socket wmctrl ustr moreutils
+ # mediawiki-HNP ocspd insight yum mousepad
+ # ...at 120, 80 and 40 chars.
+ passed_unicode = isinstance(text, unicode)
+
+ def _indent_at_beg(line):
+ count = 0
+ byte = 'X'
+ for byte in line:
+ if byte != ' ':
+ break
+ count += 1
+ list_chr = utf8_width_chop(line[count:], 1)[1]
+ if list_chr in ("-", "*", ".",
+ "\xe2\x80\xa2", "\xe2\x80\xa3", "\xe2\x88\x98"):
+ nxt = _indent_at_beg(line[count+len(list_chr):])
+ nxt = nxt[1] or nxt[0]
+ if nxt:
+ return count, count + 1 + nxt
+ return count, 0
+
+ initial_indent = to_utf8(initial_indent)
+ subsequent_indent = to_utf8(subsequent_indent)
+
+ text = to_utf8(text).rstrip('\n')
+ lines = to_utf8(text).replace('\t', ' ' * 8).split('\n')
+
+ ret = []
+ indent = initial_indent
+ wrap_last = False
+ csab = 0
+ cspc_indent = 0
+ for line in lines:
+ line = line.rstrip(' ')
+ (lsab, lspc_indent) = (csab, cspc_indent)
+ (csab, cspc_indent) = _indent_at_beg(line)
+ if wrap_last and cspc_indent:
+ ret.append(indent.rstrip(' '))
+ indent = subsequent_indent
+ wrap_last = False
+ if wrap_last:
+ line = line.lstrip(' ')
+ cspc_indent = lspc_indent
+
+ if (utf8_width(indent) + utf8_width(line)) <= width:
+ wrap_last = False
+ ret.append(indent + line)
+ indent = subsequent_indent
+ continue
+
+ wrap_last = True
+ words = line.split(' ')
+ line = indent
+ while words:
+ word = words.pop(0)
+ if (utf8_width(line) + utf8_width(word)) > width:
+ ret.append(line.rstrip(' '))
+ line = subsequent_indent + ' ' * cspc_indent
+ line += word
+ line += ' '
+ indent = line.rstrip(' ') + ' '
+ if wrap_last:
+ ret.append(indent.rstrip(' '))
+
+ if passed_unicode:
+ return map(to_unicode, ret)
+ return ret
+
+def utf8_text_fill(text, *args, **kwargs):
+ """ Works like we want textwrap.fill() to work, uses utf-8 data and
+ doesn't screw up lists/blocks/etc. """
+ return '\n'.join(utf8_text_wrap(text, *args, **kwargs))
# ----------------------------- END utf8 -----------------------------
try:
More information about the Yum-commits
mailing list