summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2016-07-08 08:20:15 -0700
committerBrian Dolbec <dolsen@gentoo.org>2016-07-08 08:35:38 -0700
commit0c2b748b987d629ba7b9f75756db16758ed426bc (patch)
tree38eecd7bc42ba58d0a292d16099c3bb10ee496d1
parentmodule_base.py: Add a char type cli option capability (diff)
downloadgentoolkit-0c2b748b987d629ba7b9f75756db16758ed426bc.tar.gz
gentoolkit-0c2b748b987d629ba7b9f75756db16758ed426bc.tar.bz2
gentoolkit-0c2b748b987d629ba7b9f75756db16758ed426bc.zip
enalyze: Add width and prepend options
These options are useful for creating preformatted wiki list entries. Feature request from Fernando Reyes for the livedvd packages list. This adds a prepend and width setting for any of the analyze keys.
-rw-r--r--pym/gentoolkit/enalyze/analyze.py32
-rw-r--r--pym/gentoolkit/enalyze/output.py28
2 files changed, 40 insertions, 20 deletions
diff --git a/pym/gentoolkit/enalyze/analyze.py b/pym/gentoolkit/enalyze/analyze.py
index ce83ba6..86f0987 100644
--- a/pym/gentoolkit/enalyze/analyze.py
+++ b/pym/gentoolkit/enalyze/analyze.py
@@ -175,7 +175,9 @@ class Analyse(ModuleBase):
"verbose": False,
"quiet": False,
'prefix': False,
- 'portage': True
+ 'portage': True,
+ "width": 80,
+ "prepend": "",
}
self.module_opts = {
"-f": ("flags", "boolean", True),
@@ -188,8 +190,12 @@ class Analyse(ModuleBase):
"--verbose": ("verbose", "boolean", True),
"-p": ("prefix", "boolean", True),
"--prefix": ("prefix", "boolean", True),
+ "-P": ("prepend", "char", None),
+ "--prepend": ("prepend", "char", None),
"-G": ("portage", "boolean", False),
"--portage": ("portage", "boolean", False),
+ "-W": ("width", "int", 80),
+ "--width": ("width", "int", 80),
}
self.formatted_options = [
(" -h, --help", "Outputs this useage message"),
@@ -201,9 +207,15 @@ class Analyse(ModuleBase):
(" -p, --prefix",
"Used for testing purposes only, runs report using " +
"a prefix keyword and 'prefix' USE flag"),
+ (" -P, --prepend",
+ "Prepend the string to any list output. " +
+ "ie: prepend '* ' to the ""front of each package being listed."
+ "This is useful for generating preformatted wiki text."),
#(" -G, --portage",
#"Use portage directly instead of gentoolkit's Package " +
#"object for some operations. Usually a little faster."),
+ (" -W, --width",
+ "Format the output to wrap at 'WIDTH' ie: long line output"),
]
self.formatted_args = [
(" use",
@@ -223,8 +235,9 @@ class Analyse(ModuleBase):
(" ",
"for those that need to be unmasked")
]
- self.short_opts = "huvpG"
- self.long_opts = ("help", "unset", "verbose", "prefix") #, "portage")
+ self.short_opts = "huvpGP:W:"
+ self.long_opts = ("help", "unset", "verbose", "prefix", "prepend=",
+ "width=") #, "portage")
self.need_queries = True
self.arg_spec = "Target"
self.arg_options = ['use', 'pkguse','keywords', 'packages', 'unmask']
@@ -262,10 +275,13 @@ class Analyse(ModuleBase):
@param target: the target to be analyzed, one of ["use", "pkguse"]
"""
system_use = portage.settings["USE"].split()
+
self.printer = AnalysisPrinter(
"use",
self.options["verbose"],
- system_use)
+ system_use,
+ width=self.options["width"],
+ prepend=self.options["prepend"])
if self.options["verbose"]:
cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
#cpvs = get_installed_cpvs()
@@ -326,7 +342,9 @@ class Analyse(ModuleBase):
self.printer = AnalysisPrinter(
"keywords",
self.options["verbose"],
- system_keywords)
+ system_keywords,
+ width=self.options["width"],
+ prepend=self.options["prepend"])
self.analyser = KeywordAnalyser( arch, system_keywords, portage.db[portage.root]["vartree"].dbapi)
#self.analyser.set_order(portage.settings["USE"].split())
# only for testing
@@ -410,7 +428,9 @@ class Analyse(ModuleBase):
self.printer = AnalysisPrinter(
"packages",
self.options["verbose"],
- key_width=key_width)
+ key_width=key_width,
+ width=self.options["width"],
+ prepend=self.options["prepend"])
cpvs = sorted(cpvs)
flags = FlagAnalyzer(
diff --git a/pym/gentoolkit/enalyze/output.py b/pym/gentoolkit/enalyze/output.py
index 326ebbc..01a9b98 100644
--- a/pym/gentoolkit/enalyze/output.py
+++ b/pym/gentoolkit/enalyze/output.py
@@ -28,13 +28,15 @@ def nl(lines=1):
class AnalysisPrinter(CpvValueWrapper):
"""Printing functions"""
- def __init__(self, target, verbose=True, references=None, key_width=1, width=None):
+ def __init__(self, target, verbose=True, references=None, key_width=1,
+ width=None, prepend=''):
"""@param references: list of accepted keywords or
the system use flags
"""
self.references = references
self.key_width = key_width
self.width = width
+ self.prepend = prepend
CpvValueWrapper.__init__(self, cpv_width=key_width, width=width)
self.set_target(target, verbose)
@@ -78,8 +80,7 @@ class AnalysisPrinter(CpvValueWrapper):
pkgs.sort()
self.print_fn(key, active, default, count, pkgs)
- @staticmethod
- def print_use_verbose(key, active, default, count, pkgs):
+ def print_use_verbose(self, key, active, default, count, pkgs):
"""Verbosely prints a set of use flag info. including the pkgs
using them.
"""
@@ -89,25 +90,24 @@ class AnalysisPrinter(CpvValueWrapper):
else:
_key = (" " + key)
cpv = _pkgs.pop(0)
- print(_key,'.'*(35-len(key)), default, pp.number(count), pp.cpv(cpv))
+ print(self.prepend + _key,'.'*(35-len(key)), default, pp.number(count),
+ pp.cpv(cpv))
while _pkgs:
cpv = _pkgs.pop(0)
print(' '*52 + pp.cpv(cpv))
# W0613: *Unused argument %r*
# pylint: disable-msg=W0613
- @staticmethod
- def print_use_quiet(key, active, default, count, pkgs):
+ def print_use_quiet(self, key, active, default, count, pkgs):
"""Quietly prints a subset set of USE flag info..
"""
if active in ["+", "-"]:
_key = pp.useflag((active+key), active=="+")
else:
_key = (" " + key)
- print(_key,'.'*(35-len(key)), default, pp.number(count))
+ print(self.prepend + _key,'.'*(35-len(key)), default, pp.number(count))
- @staticmethod
- def print_keyword_verbose(key, stability, default, count, pkgs):
+ def print_keyword_verbose(self, key, stability, default, count, pkgs):
"""Verbosely prints a set of keywords info. including the pkgs
using them.
"""
@@ -115,20 +115,20 @@ class AnalysisPrinter(CpvValueWrapper):
_key = (pp.keyword((stability+key),stable=(stability==" "),
hard_masked=stability=="-"))
cpv = _pkgs.pop(0)
- print(_key,'.'*(20-len(key)), default, pp.number(count), pp.cpv(cpv))
+ print(self.prepend + _key,'.'*(20-len(key)), default, pp.number(count),
+ pp.cpv(cpv))
while _pkgs:
cpv = _pkgs.pop(0)
print(' '*37 + pp.cpv(cpv))
# W0613: *Unused argument %r*
# pylint: disable-msg=W0613
- @staticmethod
- def print_keyword_quiet(key, stability, default, count, pkgs):
+ def print_keyword_quiet(self, key, stability, default, count, pkgs):
"""Quietly prints a subset set of USE flag info..
"""
_key = (pp.keyword((stability+key), stable=(stability==" "),
hard_masked=stability=="-"))
- print(_key,'.'*(20-len(key)), default, pp.number(count))
+ print(self.prepend + _key,'.'*(20-len(key)), default, pp.number(count))
# W0613: *Unused argument %r*
# pylint: disable-msg=W0613
@@ -153,7 +153,7 @@ class AnalysisPrinter(CpvValueWrapper):
if _flag:
_cleaned.append(_flag)
#print("cpv=", key, "_plus=", _plus, "_minus=", _minus)
- self.print_fn(key, (plus, minus, cleaned))
+ self.print_fn(self.prepend + key, (plus, minus, cleaned))
def print_pkg_verbose(self, cpv, flags):
"""Verbosely prints the pkg's use flag info.