Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/
Date: Mon, 09 Jul 2012 21:29:04
Message-Id: 1341866752.83b7af059a9b02c868238e829be2f0d18b631ded.zmedico@gentoo
1 commit: 83b7af059a9b02c868238e829be2f0d18b631ded
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Mon Jul 9 20:34:26 2012 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Mon Jul 9 20:45:52 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=83b7af05
7
8 apply Federico "fox" Scrinzi progressbar additions of title and label display. Fix a couple bugs and add max_desc_length param.
9
10 ---
11 pym/portage/output.py | 30 ++++++++++++++++++++++++++----
12 1 files changed, 26 insertions(+), 4 deletions(-)
13
14 diff --git a/pym/portage/output.py b/pym/portage/output.py
15 index 98bec81..fc6f6eb 100644
16 --- a/pym/portage/output.py
17 +++ b/pym/portage/output.py
18 @@ -631,11 +631,14 @@ class EOutput(object):
19 class ProgressBar(object):
20 """The interface is copied from the ProgressBar class from the EasyDialogs
21 module (which is Mac only)."""
22 - def __init__(self, title=None, maxval=0, label=None):
23 - self._title = title
24 + def __init__(self, title=None, maxval=0, label=None, max_desc_length=25):
25 + self._title = title or ""
26 self._maxval = maxval
27 - self._label = maxval
28 + self._label = label or ""
29 self._curval = 0
30 + self._desc = ""
31 + self._desc_max_length = max_desc_length
32 + self._set_desc()
33
34 @property
35 def curval(self):
36 @@ -659,10 +662,23 @@ class ProgressBar(object):
37 def title(self, newstr):
38 """Sets the text in the title bar of the progress dialog to newstr."""
39 self._title = newstr
40 + self._set_desc()
41
42 def label(self, newstr):
43 """Sets the text in the progress box of the progress dialog to newstr."""
44 self._label = newstr
45 + self._set_desc()
46 +
47 + def _set_desc(self):
48 + self._desc = "%s%s" % (
49 + "%s: " % self._title if self._title else "",
50 + "%s" % self._label if self._label else ""
51 + )
52 + if len(self._desc) > self._desc_max_length: # truncate if too long
53 + self._desc = "%s..." % self._desc[:self._desc_max_length - 3]
54 + if len(self._desc):
55 + self._desc = self._desc.ljust(self._desc_max_length)
56 +
57
58 def set(self, value, maxval=None):
59 """
60 @@ -722,6 +738,8 @@ class TermProgressBar(ProgressBar):
61 if cols < percentage_str_width:
62 return ""
63 bar_space = cols - percentage_str_width - square_brackets_width
64 + if self._desc:
65 + bar_space -= self._desc_max_length + 1
66 if maxval == 0:
67 max_bar_width = bar_space-3
68 image = " "
69 @@ -751,7 +769,11 @@ class TermProgressBar(ProgressBar):
70 percentage_str_width += 1
71 bar_space -= 1
72 max_bar_width = bar_space - 1
73 - image = ("%d%% " % percentage).rjust(percentage_str_width)
74 + image = "%s%s" % (
75 + self._desc,
76 + ("%d%%" % percentage).ljust(percentage_str_width),
77 + )
78 +
79 if cols < min_columns:
80 return image
81 offset = float(curval) / maxval