aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <brian.dolbec@gmail.com>2011-01-25 00:30:15 -0800
committerBrian Dolbec <brian.dolbec@gmail.com>2011-01-25 00:30:15 -0800
commite382437ad6f15408659b3b945f3cb3d8441f91ab (patch)
tree8e26c84bab55f9d88a129e094c042d3c78a26918
parentAdd a new cpv and values textwrapping class (diff)
downloadgentoolkit-e382437ad6f15408659b3b945f3cb3d8441f91ab.tar.gz
gentoolkit-e382437ad6f15408659b3b945f3cb3d8441f91ab.tar.bz2
gentoolkit-e382437ad6f15408659b3b945f3cb3d8441f91ab.zip
Modify printers to use the newly split out CpvValuesWrapper and add a print_pkg_quiet()
-rw-r--r--pym/gentoolkit/analyse/analyse.py22
-rw-r--r--pym/gentoolkit/analyse/output.py67
2 files changed, 51 insertions, 38 deletions
diff --git a/pym/gentoolkit/analyse/analyse.py b/pym/gentoolkit/analyse/analyse.py
index bc2f131..7e47724 100644
--- a/pym/gentoolkit/analyse/analyse.py
+++ b/pym/gentoolkit/analyse/analyse.py
@@ -396,15 +396,19 @@ class Analyse(ModuleBase):
@param target: the target to be analysed, one of ["use", "pkguse"]
"""
system_use = portage.settings["USE"].split()
- self.printer = AnalysisPrinter(
- "packages",
- self.options["verbose"],
- system_use)
if self.options["verbose"]:
cpvs = VARDB.cpv_all()
+ key_width = 45
else:
cpvs = get_installed_cpvs()
+ key_width = 1
+ self.printer = AnalysisPrinter(
+ "packages",
+ self.options["verbose"],
+ key_width=key_width)
+
+ cpvs = sorted(cpvs)
flags = FlagAnalyzer(
system=system_use,
filter_defaults=False,
@@ -412,14 +416,18 @@ class Analyse(ModuleBase):
)
if self.options["verbose"]:
- print(" cat/pkg-ver USE Flags")
+ print(" cat/pkg-ver USE Flags")
+ # "app-emulation/emul-linux-x86-sdl-20100915 ...."
blankline = nl
elif not self.options['quiet']:
- print(" cat/pkg-ver USE Flags")
+ print(" cat/pkg-ver USE Flags")
blankline = lambda: None
for cpv in cpvs:
(flag_plus, flag_neg, cleaned) = flags.analyse_cpv(cpv)
- self.printer(cpv, "", (flag_plus, flag_neg, cleaned))
+ if self.options["unset"]:
+ self.printer(cpv, "", (flag_plus, flag_neg, cleaned))
+ else:
+ self.printer(cpv, "", (flag_plus, [], cleaned))
if not self.options['quiet']:
print("===================================================")
print("Total number of installed ebuilds =",
diff --git a/pym/gentoolkit/analyse/output.py b/pym/gentoolkit/analyse/output.py
index 8c8d740..832e6b1 100644
--- a/pym/gentoolkit/analyse/output.py
+++ b/pym/gentoolkit/analyse/output.py
@@ -12,7 +12,7 @@ from __future__ import print_function
import gentoolkit
from gentoolkit import pprinter as pp
-from gentoolkit.textwrap_ import TextWrapper
+from gentoolkit.formatters import CpvValueWrapper
from gentoolkit.cpv import split_cpv
@@ -25,13 +25,16 @@ def nl(lines=1):
"""
print(('\n' * lines))
-class AnalysisPrinter(object):
+class AnalysisPrinter(CpvValueWrapper):
"""Printing functions"""
- def __init__(self, target, verbose=True, references=None):
+ def __init__(self, target, verbose=True, references=None, key_width=1, width=None):
"""@param references: list of accepted keywords or
the system use flags
"""
self.references = references
+ self.key_width = key_width
+ self.width = width
+ CpvValueWrapper.__init__(self, cpv_width=key_width, width=width)
self.set_target(target, verbose)
def set_target(self, target, verbose=True):
@@ -132,10 +135,21 @@ class AnalysisPrinter(object):
"""Determines the stats for key, formats it and
calls the pre-determined print function
"""
- self.print_fn(key, flags)
+ (plus, minus, cleaned) = flags
+ _plus = []
+ _minus = []
+ for flag in plus:
+ _flag = flag.strip()
+ if _flag:
+ _plus.append(_flag)
+ for flag in minus:
+ _flag = flag.strip()
+ if _flag:
+ _minus.append(_flag)
+ #print("cpv=", key, "_plus=", _plus, "_minus=", _minus)
+ self.print_fn(key, (plus, minus, cleaned))
- @staticmethod
- def print_pkg_verbose(cpv, flags):
+ def print_pkg_verbose(self, cpv, flags):
"""Verbosely prints the pkg's use flag info.
"""
(plus, minus, cleaned) = flags
@@ -144,25 +158,33 @@ class AnalysisPrinter(object):
_flags.append(pp.useflag((flag), True))
for flag in minus:
_flags.append(pp.useflag((flag), False))
- #cpv = _pkgs.pop(0)
- print(pp.cpv(cpv),'.'*(45-len(cpv)), ", ".join(_flags))
- #while _pkgs:
- # cpv = _pkgs.pop(0)
- # print(' '*52 + pp.cpv(cpv))
+
+ print(self._format_values(cpv, ", ".join(_flags)))
+ def print_pkg_quiet(self, cpv, flags):
+ """Verbosely prints the pkg's use flag info.
+ """
+ (plus, minus, cleaned) = flags
+ _flags = []
+ for flag in plus:
+ _flags.append(pp.useflag((flag), True))
+ for flag in minus:
+ _flags.append(pp.useflag((flag), False))
+
+ print(self._format_values(cpv, ", ".join(_flags)))
-class RebuildPrinter(object):
+class RebuildPrinter(CpvValueWrapper):
"""Output functions"""
- def __init__(self, target, pretend=True, exact=False):
+ def __init__(self, target, pretend=True, exact=False, key_width=1, width=None):
"""@param references: list of accepted keywords or
the system use flags
"""
self.target = target
self.set_target(target)
self.pretend = pretend
+ CpvValueWrapper.__init__(self, cpv_width=key_width, width=width)
if pretend:
- self.twrap = TextWrapper(width=gentoolkit.CONFIG['termWidth'])
self.spacer = ' '
self.init_indent = len(self.spacer)
else:
@@ -198,23 +220,6 @@ class RebuildPrinter(object):
self.data[_key] = values
self.print_fn( _key, values)
- def _format_values(self, key, values):
- """Format entry values ie. USE flags, keywords,...
-
- @type key: str
- @param key: a pre-formatted cpv
- @type values: list of pre-formatted strings
- @param values: ['flag1', 'flag2',...]
- @rtype: str
- @return: formatted options string
- """
-
- result = []
- self.twrap.initial_indent = pp.cpv(key+" ")
- self.twrap.subsequent_indent = " " * (len(key)+1)
- result.append(self.twrap.fill(values))
- return '\n'.join(result)
-
def print_use(self, key, values):
"""Prints a USE flag string.
"""