1 |
commit: 0c2b748b987d629ba7b9f75756db16758ed426bc |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Jul 8 15:20:15 2016 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Jul 8 15:35:38 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=0c2b748b |
7 |
|
8 |
enalyze: Add width and prepend options |
9 |
|
10 |
These options are useful for creating preformatted wiki list entries. |
11 |
Feature request from Fernando Reyes for the livedvd packages list. |
12 |
This adds a prepend and width setting for any of the analyze keys. |
13 |
|
14 |
pym/gentoolkit/enalyze/analyze.py | 32 ++++++++++++++++++++++++++------ |
15 |
pym/gentoolkit/enalyze/output.py | 28 ++++++++++++++-------------- |
16 |
2 files changed, 40 insertions(+), 20 deletions(-) |
17 |
|
18 |
diff --git a/pym/gentoolkit/enalyze/analyze.py b/pym/gentoolkit/enalyze/analyze.py |
19 |
index ce83ba6..86f0987 100644 |
20 |
--- a/pym/gentoolkit/enalyze/analyze.py |
21 |
+++ b/pym/gentoolkit/enalyze/analyze.py |
22 |
@@ -175,7 +175,9 @@ class Analyse(ModuleBase): |
23 |
"verbose": False, |
24 |
"quiet": False, |
25 |
'prefix': False, |
26 |
- 'portage': True |
27 |
+ 'portage': True, |
28 |
+ "width": 80, |
29 |
+ "prepend": "", |
30 |
} |
31 |
self.module_opts = { |
32 |
"-f": ("flags", "boolean", True), |
33 |
@@ -188,8 +190,12 @@ class Analyse(ModuleBase): |
34 |
"--verbose": ("verbose", "boolean", True), |
35 |
"-p": ("prefix", "boolean", True), |
36 |
"--prefix": ("prefix", "boolean", True), |
37 |
+ "-P": ("prepend", "char", None), |
38 |
+ "--prepend": ("prepend", "char", None), |
39 |
"-G": ("portage", "boolean", False), |
40 |
"--portage": ("portage", "boolean", False), |
41 |
+ "-W": ("width", "int", 80), |
42 |
+ "--width": ("width", "int", 80), |
43 |
} |
44 |
self.formatted_options = [ |
45 |
(" -h, --help", "Outputs this useage message"), |
46 |
@@ -201,9 +207,15 @@ class Analyse(ModuleBase): |
47 |
(" -p, --prefix", |
48 |
"Used for testing purposes only, runs report using " + |
49 |
"a prefix keyword and 'prefix' USE flag"), |
50 |
+ (" -P, --prepend", |
51 |
+ "Prepend the string to any list output. " + |
52 |
+ "ie: prepend '* ' to the ""front of each package being listed." |
53 |
+ "This is useful for generating preformatted wiki text."), |
54 |
#(" -G, --portage", |
55 |
#"Use portage directly instead of gentoolkit's Package " + |
56 |
#"object for some operations. Usually a little faster."), |
57 |
+ (" -W, --width", |
58 |
+ "Format the output to wrap at 'WIDTH' ie: long line output"), |
59 |
] |
60 |
self.formatted_args = [ |
61 |
(" use", |
62 |
@@ -223,8 +235,9 @@ class Analyse(ModuleBase): |
63 |
(" ", |
64 |
"for those that need to be unmasked") |
65 |
] |
66 |
- self.short_opts = "huvpG" |
67 |
- self.long_opts = ("help", "unset", "verbose", "prefix") #, "portage") |
68 |
+ self.short_opts = "huvpGP:W:" |
69 |
+ self.long_opts = ("help", "unset", "verbose", "prefix", "prepend=", |
70 |
+ "width=") #, "portage") |
71 |
self.need_queries = True |
72 |
self.arg_spec = "Target" |
73 |
self.arg_options = ['use', 'pkguse','keywords', 'packages', 'unmask'] |
74 |
@@ -262,10 +275,13 @@ class Analyse(ModuleBase): |
75 |
@param target: the target to be analyzed, one of ["use", "pkguse"] |
76 |
""" |
77 |
system_use = portage.settings["USE"].split() |
78 |
+ |
79 |
self.printer = AnalysisPrinter( |
80 |
"use", |
81 |
self.options["verbose"], |
82 |
- system_use) |
83 |
+ system_use, |
84 |
+ width=self.options["width"], |
85 |
+ prepend=self.options["prepend"]) |
86 |
if self.options["verbose"]: |
87 |
cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all() |
88 |
#cpvs = get_installed_cpvs() |
89 |
@@ -326,7 +342,9 @@ class Analyse(ModuleBase): |
90 |
self.printer = AnalysisPrinter( |
91 |
"keywords", |
92 |
self.options["verbose"], |
93 |
- system_keywords) |
94 |
+ system_keywords, |
95 |
+ width=self.options["width"], |
96 |
+ prepend=self.options["prepend"]) |
97 |
self.analyser = KeywordAnalyser( arch, system_keywords, portage.db[portage.root]["vartree"].dbapi) |
98 |
#self.analyser.set_order(portage.settings["USE"].split()) |
99 |
# only for testing |
100 |
@@ -410,7 +428,9 @@ class Analyse(ModuleBase): |
101 |
self.printer = AnalysisPrinter( |
102 |
"packages", |
103 |
self.options["verbose"], |
104 |
- key_width=key_width) |
105 |
+ key_width=key_width, |
106 |
+ width=self.options["width"], |
107 |
+ prepend=self.options["prepend"]) |
108 |
|
109 |
cpvs = sorted(cpvs) |
110 |
flags = FlagAnalyzer( |
111 |
|
112 |
diff --git a/pym/gentoolkit/enalyze/output.py b/pym/gentoolkit/enalyze/output.py |
113 |
index 326ebbc..01a9b98 100644 |
114 |
--- a/pym/gentoolkit/enalyze/output.py |
115 |
+++ b/pym/gentoolkit/enalyze/output.py |
116 |
@@ -28,13 +28,15 @@ def nl(lines=1): |
117 |
|
118 |
class AnalysisPrinter(CpvValueWrapper): |
119 |
"""Printing functions""" |
120 |
- def __init__(self, target, verbose=True, references=None, key_width=1, width=None): |
121 |
+ def __init__(self, target, verbose=True, references=None, key_width=1, |
122 |
+ width=None, prepend=''): |
123 |
"""@param references: list of accepted keywords or |
124 |
the system use flags |
125 |
""" |
126 |
self.references = references |
127 |
self.key_width = key_width |
128 |
self.width = width |
129 |
+ self.prepend = prepend |
130 |
CpvValueWrapper.__init__(self, cpv_width=key_width, width=width) |
131 |
self.set_target(target, verbose) |
132 |
|
133 |
@@ -78,8 +80,7 @@ class AnalysisPrinter(CpvValueWrapper): |
134 |
pkgs.sort() |
135 |
self.print_fn(key, active, default, count, pkgs) |
136 |
|
137 |
- @staticmethod |
138 |
- def print_use_verbose(key, active, default, count, pkgs): |
139 |
+ def print_use_verbose(self, key, active, default, count, pkgs): |
140 |
"""Verbosely prints a set of use flag info. including the pkgs |
141 |
using them. |
142 |
""" |
143 |
@@ -89,25 +90,24 @@ class AnalysisPrinter(CpvValueWrapper): |
144 |
else: |
145 |
_key = (" " + key) |
146 |
cpv = _pkgs.pop(0) |
147 |
- print(_key,'.'*(35-len(key)), default, pp.number(count), pp.cpv(cpv)) |
148 |
+ print(self.prepend + _key,'.'*(35-len(key)), default, pp.number(count), |
149 |
+ pp.cpv(cpv)) |
150 |
while _pkgs: |
151 |
cpv = _pkgs.pop(0) |
152 |
print(' '*52 + pp.cpv(cpv)) |
153 |
|
154 |
# W0613: *Unused argument %r* |
155 |
# pylint: disable-msg=W0613 |
156 |
- @staticmethod |
157 |
- def print_use_quiet(key, active, default, count, pkgs): |
158 |
+ def print_use_quiet(self, key, active, default, count, pkgs): |
159 |
"""Quietly prints a subset set of USE flag info.. |
160 |
""" |
161 |
if active in ["+", "-"]: |
162 |
_key = pp.useflag((active+key), active=="+") |
163 |
else: |
164 |
_key = (" " + key) |
165 |
- print(_key,'.'*(35-len(key)), default, pp.number(count)) |
166 |
+ print(self.prepend + _key,'.'*(35-len(key)), default, pp.number(count)) |
167 |
|
168 |
- @staticmethod |
169 |
- def print_keyword_verbose(key, stability, default, count, pkgs): |
170 |
+ def print_keyword_verbose(self, key, stability, default, count, pkgs): |
171 |
"""Verbosely prints a set of keywords info. including the pkgs |
172 |
using them. |
173 |
""" |
174 |
@@ -115,20 +115,20 @@ class AnalysisPrinter(CpvValueWrapper): |
175 |
_key = (pp.keyword((stability+key),stable=(stability==" "), |
176 |
hard_masked=stability=="-")) |
177 |
cpv = _pkgs.pop(0) |
178 |
- print(_key,'.'*(20-len(key)), default, pp.number(count), pp.cpv(cpv)) |
179 |
+ print(self.prepend + _key,'.'*(20-len(key)), default, pp.number(count), |
180 |
+ pp.cpv(cpv)) |
181 |
while _pkgs: |
182 |
cpv = _pkgs.pop(0) |
183 |
print(' '*37 + pp.cpv(cpv)) |
184 |
|
185 |
# W0613: *Unused argument %r* |
186 |
# pylint: disable-msg=W0613 |
187 |
- @staticmethod |
188 |
- def print_keyword_quiet(key, stability, default, count, pkgs): |
189 |
+ def print_keyword_quiet(self, key, stability, default, count, pkgs): |
190 |
"""Quietly prints a subset set of USE flag info.. |
191 |
""" |
192 |
_key = (pp.keyword((stability+key), stable=(stability==" "), |
193 |
hard_masked=stability=="-")) |
194 |
- print(_key,'.'*(20-len(key)), default, pp.number(count)) |
195 |
+ print(self.prepend + _key,'.'*(20-len(key)), default, pp.number(count)) |
196 |
|
197 |
# W0613: *Unused argument %r* |
198 |
# pylint: disable-msg=W0613 |
199 |
@@ -153,7 +153,7 @@ class AnalysisPrinter(CpvValueWrapper): |
200 |
if _flag: |
201 |
_cleaned.append(_flag) |
202 |
#print("cpv=", key, "_plus=", _plus, "_minus=", _minus) |
203 |
- self.print_fn(key, (plus, minus, cleaned)) |
204 |
+ self.print_fn(self.prepend + key, (plus, minus, cleaned)) |
205 |
|
206 |
def print_pkg_verbose(self, cpv, flags): |
207 |
"""Verbosely prints the pkg's use flag info. |