public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/enalyze/
Date: Fri,  8 Jul 2016 15:37:47 +0000 (UTC)	[thread overview]
Message-ID: <1467992138.0c2b748b987d629ba7b9f75756db16758ed426bc.dolsen@gentoo> (raw)

commit:     0c2b748b987d629ba7b9f75756db16758ed426bc
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Fri Jul  8 15:20:15 2016 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Jul  8 15:35:38 2016 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=0c2b748b

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.

 pym/gentoolkit/enalyze/analyze.py | 32 ++++++++++++++++++++++++++------
 pym/gentoolkit/enalyze/output.py  | 28 ++++++++++++++--------------
 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.


             reply	other threads:[~2016-07-08 15:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-08 15:37 Brian Dolbec [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-02-17  0:00 [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/enalyze/ Sam James
2023-06-04 19:01 Mike Gilbert
2022-07-09 23:55 Brian Dolbec
2016-02-25 21:26 Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467992138.0c2b748b987d629ba7b9f75756db16758ed426bc.dolsen@gentoo \
    --to=dolsen@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox