Gentoo Archives: gentoo-commits

From: Brian Dolbec <brian.dolbec@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoolkit:gentoolkit commit in: pym/gentoolkit/enalyze/
Date: Fri, 29 Jun 2012 03:44:04
Message-Id: 1340941409.a880f62d652ae59de80d430ce0331b6b71af11c4.dol-sen@gentoo
1 commit: a880f62d652ae59de80d430ce0331b6b71af11c4
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Fri Jun 29 03:43:29 2012 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Fri Jun 29 03:43:29 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=a880f62d
7
8 reverse an accidental indentation change from tabs to spaces.
9
10 ---
11 pym/gentoolkit/enalyze/analyze.py | 784 ++++++++++++++++++------------------
12 pym/gentoolkit/enalyze/rebuild.py | 648 +++++++++++++++---------------
13 2 files changed, 716 insertions(+), 716 deletions(-)
14
15 diff --git a/pym/gentoolkit/enalyze/analyze.py b/pym/gentoolkit/enalyze/analyze.py
16 index 33d1651..2ba028f 100644
17 --- a/pym/gentoolkit/enalyze/analyze.py
18 +++ b/pym/gentoolkit/enalyze/analyze.py
19 @@ -26,423 +26,423 @@ import portage
20
21
22 def gather_flags_info(
23 - cpvs=None,
24 - system_flags=None,
25 - include_unset=False,
26 - target="USE",
27 - use_portage=False,
28 - # override-able for testing
29 - _get_flags=get_flags,
30 - _get_used=get_installed_use
31 - ):
32 - """Analyze the installed pkgs USE flags for frequency of use
33 + cpvs=None,
34 + system_flags=None,
35 + include_unset=False,
36 + target="USE",
37 + use_portage=False,
38 + # override-able for testing
39 + _get_flags=get_flags,
40 + _get_used=get_installed_use
41 + ):
42 + """Analyze the installed pkgs USE flags for frequency of use
43
44 - @type cpvs: list
45 - @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
46 - defaults to entire installed pkg db
47 - @type: system_flags: list
48 - @param system_flags: the current default USE flags as defined
49 - by portage.settings["USE"].split()
50 - @type include_unset: bool
51 - @param include_unset: controls the inclusion of unset USE flags in the report.
52 - @type target: string
53 - @param target: the environment variable being analyzed
54 - one of ["USE", "PKGUSE"]
55 - @type _get_flags: function
56 - @param _get_flags: ovride-able for testing,
57 - defaults to gentoolkit.enalyze.lib.get_flags
58 - @param _get_used: ovride-able for testing,
59 - defaults to gentoolkit.enalyze.lib.get_installed_use
60 - @rtype dict. {flag:{"+":[cat/pkg-ver,...], "-":[cat/pkg-ver,...], "unset":[]}
61 - """
62 - if cpvs is None:
63 - cpvs = VARDB.cpv_all()
64 - # pass them in to override for tests
65 - flags = FlagAnalyzer(system_flags,
66 - filter_defaults=False,
67 - target=target,
68 - _get_flags=_get_flags,
69 - _get_used=get_installed_use
70 - )
71 - flag_users = {}
72 - for cpv in cpvs:
73 - if cpv.startswith("virtual"):
74 - continue
75 - if use_portage:
76 - plus, minus, unset = flags.analyse_cpv(cpv)
77 - else:
78 - pkg = Package(cpv)
79 - plus, minus, unset = flags.analyse_pkg(pkg)
80 - for flag in plus:
81 - if flag in flag_users:
82 - flag_users[flag]["+"].append(cpv)
83 - else:
84 - flag_users[flag] = {"+": [cpv], "-": []}
85 - for flag in minus:
86 - if flag in flag_users:
87 - flag_users[flag]["-"].append(cpv)
88 - else:
89 - flag_users[flag] = {"+":[], "-": [cpv]}
90 - if include_unset:
91 - for flag in unset:
92 - if flag in flag_users:
93 - if "unset" in flag_users[flag]:
94 - flag_users[flag]["unset"].append(cpv)
95 - else:
96 - flag_users[flag]["unset"] = [cpv]
97 - else:
98 - flag_users[flag] = {"+": [], "-": [], "unset": [cpv]}
99 - return flag_users
100 + @type cpvs: list
101 + @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
102 + defaults to entire installed pkg db
103 + @type: system_flags: list
104 + @param system_flags: the current default USE flags as defined
105 + by portage.settings["USE"].split()
106 + @type include_unset: bool
107 + @param include_unset: controls the inclusion of unset USE flags in the report.
108 + @type target: string
109 + @param target: the environment variable being analyzed
110 + one of ["USE", "PKGUSE"]
111 + @type _get_flags: function
112 + @param _get_flags: ovride-able for testing,
113 + defaults to gentoolkit.enalyze.lib.get_flags
114 + @param _get_used: ovride-able for testing,
115 + defaults to gentoolkit.enalyze.lib.get_installed_use
116 + @rtype dict. {flag:{"+":[cat/pkg-ver,...], "-":[cat/pkg-ver,...], "unset":[]}
117 + """
118 + if cpvs is None:
119 + cpvs = VARDB.cpv_all()
120 + # pass them in to override for tests
121 + flags = FlagAnalyzer(system_flags,
122 + filter_defaults=False,
123 + target=target,
124 + _get_flags=_get_flags,
125 + _get_used=get_installed_use
126 + )
127 + flag_users = {}
128 + for cpv in cpvs:
129 + if cpv.startswith("virtual"):
130 + continue
131 + if use_portage:
132 + plus, minus, unset = flags.analyse_cpv(cpv)
133 + else:
134 + pkg = Package(cpv)
135 + plus, minus, unset = flags.analyse_pkg(pkg)
136 + for flag in plus:
137 + if flag in flag_users:
138 + flag_users[flag]["+"].append(cpv)
139 + else:
140 + flag_users[flag] = {"+": [cpv], "-": []}
141 + for flag in minus:
142 + if flag in flag_users:
143 + flag_users[flag]["-"].append(cpv)
144 + else:
145 + flag_users[flag] = {"+":[], "-": [cpv]}
146 + if include_unset:
147 + for flag in unset:
148 + if flag in flag_users:
149 + if "unset" in flag_users[flag]:
150 + flag_users[flag]["unset"].append(cpv)
151 + else:
152 + flag_users[flag]["unset"] = [cpv]
153 + else:
154 + flag_users[flag] = {"+": [], "-": [], "unset": [cpv]}
155 + return flag_users
156
157
158 def gather_keywords_info(
159 - cpvs=None,
160 - system_keywords=None,
161 - use_portage=False,
162 - # override-able for testing
163 - keywords=portage.settings["ACCEPT_KEYWORDS"],
164 - analyser = None
165 - ):
166 - """Analyze the installed pkgs 'keywords' for frequency of use
167 + cpvs=None,
168 + system_keywords=None,
169 + use_portage=False,
170 + # override-able for testing
171 + keywords=portage.settings["ACCEPT_KEYWORDS"],
172 + analyser = None
173 + ):
174 + """Analyze the installed pkgs 'keywords' for frequency of use
175
176 - @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
177 - defaults to entire installed pkg db
178 - @param system_keywords: list of the system keywords
179 - @param keywords: user defined list of keywords to check and report on
180 - or reports on all relevant keywords found to have been used.
181 - @param _get_kwds: overridable function for testing
182 - @param _get_used: overridable function for testing
183 - @rtype dict. {keyword:{"stable":[cat/pkg-ver,...], "testing":[cat/pkg-ver,...]}
184 - """
185 - if cpvs is None:
186 - cpvs = VARDB.cpv_all()
187 - keyword_users = {}
188 - for cpv in cpvs:
189 - if cpv.startswith("virtual"):
190 - continue
191 - if use_portage:
192 - keyword = analyser.get_inst_keyword_cpv(cpv)
193 - else:
194 - pkg = Package(cpv)
195 - keyword = analyser.get_inst_keyword_pkg(pkg)
196 - #print "returned keyword =", cpv, keyword, keyword[0]
197 - key = keyword[0]
198 - if key in ["~", "-"]:
199 - _kwd = keyword[1:]
200 - if _kwd in keyword_users:
201 - if key in ["~"]:
202 - keyword_users[_kwd]["testing"].append(cpv)
203 - elif key in ["-"]:
204 - #print "adding cpv to missing:", cpv
205 - keyword_users[_kwd]["missing"].append(cpv)
206 - else:
207 - if key in ["~"]:
208 - keyword_users[_kwd] = {"stable": [],
209 - "testing": [cpv], "missing": []}
210 - elif key in ["-"]:
211 - keyword_users[_kwd] = {"stable": [],
212 - "testing": [], "missing": [cpv]}
213 - else:
214 - keyword_users[_kwd] = {"stable": [cpv],
215 - "testing": [], "missing": []}
216 - elif keyword in keyword_users:
217 - keyword_users[keyword]["stable"].append(cpv)
218 - else:
219 - keyword_users[keyword] = {
220 - "stable": [cpv],
221 - "testing": [],
222 - "missing": []
223 - }
224 - return keyword_users
225 + @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
226 + defaults to entire installed pkg db
227 + @param system_keywords: list of the system keywords
228 + @param keywords: user defined list of keywords to check and report on
229 + or reports on all relevant keywords found to have been used.
230 + @param _get_kwds: overridable function for testing
231 + @param _get_used: overridable function for testing
232 + @rtype dict. {keyword:{"stable":[cat/pkg-ver,...], "testing":[cat/pkg-ver,...]}
233 + """
234 + if cpvs is None:
235 + cpvs = VARDB.cpv_all()
236 + keyword_users = {}
237 + for cpv in cpvs:
238 + if cpv.startswith("virtual"):
239 + continue
240 + if use_portage:
241 + keyword = analyser.get_inst_keyword_cpv(cpv)
242 + else:
243 + pkg = Package(cpv)
244 + keyword = analyser.get_inst_keyword_pkg(pkg)
245 + #print "returned keyword =", cpv, keyword, keyword[0]
246 + key = keyword[0]
247 + if key in ["~", "-"]:
248 + _kwd = keyword[1:]
249 + if _kwd in keyword_users:
250 + if key in ["~"]:
251 + keyword_users[_kwd]["testing"].append(cpv)
252 + elif key in ["-"]:
253 + #print "adding cpv to missing:", cpv
254 + keyword_users[_kwd]["missing"].append(cpv)
255 + else:
256 + if key in ["~"]:
257 + keyword_users[_kwd] = {"stable": [],
258 + "testing": [cpv], "missing": []}
259 + elif key in ["-"]:
260 + keyword_users[_kwd] = {"stable": [],
261 + "testing": [], "missing": [cpv]}
262 + else:
263 + keyword_users[_kwd] = {"stable": [cpv],
264 + "testing": [], "missing": []}
265 + elif keyword in keyword_users:
266 + keyword_users[keyword]["stable"].append(cpv)
267 + else:
268 + keyword_users[keyword] = {
269 + "stable": [cpv],
270 + "testing": [],
271 + "missing": []
272 + }
273 + return keyword_users
274
275
276 class Analyse(ModuleBase):
277 - """Installed db analysis tool to query the installed databse
278 - and produce/output stats for USE flags or keywords/mask.
279 - The 'rebuild' action output is in the form suitable for file type output
280 - to create a new package.use, package.keywords, package.unmask
281 - type files in the event of needing to rebuild the
282 - /etc/portage/* user configs
283 - """
284 - def __init__(self):
285 - ModuleBase.__init__(self)
286 - self.module_name = "enalyze"
287 - self.options = {
288 - "flags": False,
289 - "keywords": False,
290 - "packages": False,
291 - "unset": False,
292 - "verbose": False,
293 - "quiet": False,
294 - 'prefix': False,
295 - 'portage': True
296 - }
297 - self.module_opts = {
298 - "-f": ("flags", "boolean", True),
299 - "--flags": ("flags", "boolean", True),
300 - "-k": ("keywords", "boolean", True),
301 - "--keywords": ("keywords", "boolean", True),
302 - "-u": ("unset", "boolean", True),
303 - "--unset": ("unset", "boolean", True),
304 - "-v": ("verbose", "boolean", True),
305 - "--verbose": ("verbose", "boolean", True),
306 - "-p": ("prefix", "boolean", True),
307 - "--prefix": ("prefix", "boolean", True),
308 - "-G": ("portage", "boolean", False),
309 - "--portage": ("portage", "boolean", False),
310 - }
311 - self.formatted_options = [
312 - (" -h, --help", "Outputs this useage message"),
313 - (" -a, --analyze",
314 - "Action, sets the module to gather data and output the"),
315 - ("", "formatted stats/information to the screen"),
316 - (" -u, --unset",
317 - "Additionally include any unset USE flags and the packages"),
318 - ("", "that could use them"),
319 - (" -v, --verbose",
320 - "Used in the analyze action to output more detailed information"),
321 - (" -p, --prefix",
322 - "Used for testing purposes only, runs report using " +
323 - "a prefix keyword and 'prefix' USE flag"),
324 - #(" -G, --portage",
325 - #"Use portage directly instead of gentoolkit's Package " +
326 - #"object for some operations. Usually a little faster."),
327 - ]
328 - self.formatted_args = [
329 - (" use",
330 - "Causes the action to analyze the installed packages USE flags"),
331 - (" pkguse",
332 - "Causes the action to analyze the installed packages PKGUSE flags"),
333 - (" ",
334 - "These are flags that have been set in /etc/portage/package.use"),
335 - (" keywords",
336 - "Causes the action to analyze the installed packages keywords"),
337 - (" packages",
338 - "Causes the action to analyze the installed packages and the"),
339 - (" ",
340 - "USE flags they were installed with"),
341 - ]
342 - self.short_opts = "huvpG"
343 - self.long_opts = ("help", "unset", "verbose", "prefix") #, "portage")
344 - self.need_queries = True
345 - self.arg_spec = "Target"
346 - self.arg_options = ['use', 'pkguse','keywords', 'packages']
347 - self.arg_option = False
348 - self.warning = (
349 - " CAUTION",
350 - "This is beta software and some features/options are incomplete,",
351 - "some features may change in future releases includig its name.",
352 - "Feedback will be appreciated, http://bugs.gentoo.org")
353 + """Installed db analysis tool to query the installed databse
354 + and produce/output stats for USE flags or keywords/mask.
355 + The 'rebuild' action output is in the form suitable for file type output
356 + to create a new package.use, package.keywords, package.unmask
357 + type files in the event of needing to rebuild the
358 + /etc/portage/* user configs
359 + """
360 + def __init__(self):
361 + ModuleBase.__init__(self)
362 + self.module_name = "enalyze"
363 + self.options = {
364 + "flags": False,
365 + "keywords": False,
366 + "packages": False,
367 + "unset": False,
368 + "verbose": False,
369 + "quiet": False,
370 + 'prefix': False,
371 + 'portage': True
372 + }
373 + self.module_opts = {
374 + "-f": ("flags", "boolean", True),
375 + "--flags": ("flags", "boolean", True),
376 + "-k": ("keywords", "boolean", True),
377 + "--keywords": ("keywords", "boolean", True),
378 + "-u": ("unset", "boolean", True),
379 + "--unset": ("unset", "boolean", True),
380 + "-v": ("verbose", "boolean", True),
381 + "--verbose": ("verbose", "boolean", True),
382 + "-p": ("prefix", "boolean", True),
383 + "--prefix": ("prefix", "boolean", True),
384 + "-G": ("portage", "boolean", False),
385 + "--portage": ("portage", "boolean", False),
386 + }
387 + self.formatted_options = [
388 + (" -h, --help", "Outputs this useage message"),
389 + (" -a, --analyze",
390 + "Action, sets the module to gather data and output the"),
391 + ("", "formatted stats/information to the screen"),
392 + (" -u, --unset",
393 + "Additionally include any unset USE flags and the packages"),
394 + ("", "that could use them"),
395 + (" -v, --verbose",
396 + "Used in the analyze action to output more detailed information"),
397 + (" -p, --prefix",
398 + "Used for testing purposes only, runs report using " +
399 + "a prefix keyword and 'prefix' USE flag"),
400 + #(" -G, --portage",
401 + #"Use portage directly instead of gentoolkit's Package " +
402 + #"object for some operations. Usually a little faster."),
403 + ]
404 + self.formatted_args = [
405 + (" use",
406 + "Causes the action to analyze the installed packages USE flags"),
407 + (" pkguse",
408 + "Causes the action to analyze the installed packages PKGUSE flags"),
409 + (" ",
410 + "These are flags that have been set in /etc/portage/package.use"),
411 + (" keywords",
412 + "Causes the action to analyze the installed packages keywords"),
413 + (" packages",
414 + "Causes the action to analyze the installed packages and the"),
415 + (" ",
416 + "USE flags they were installed with"),
417 + ]
418 + self.short_opts = "huvpG"
419 + self.long_opts = ("help", "unset", "verbose", "prefix") #, "portage")
420 + self.need_queries = True
421 + self.arg_spec = "Target"
422 + self.arg_options = ['use', 'pkguse','keywords', 'packages']
423 + self.arg_option = False
424 + self.warning = (
425 + " CAUTION",
426 + "This is beta software and some features/options are incomplete,",
427 + "some features may change in future releases includig its name.",
428 + "Feedback will be appreciated, http://bugs.gentoo.org")
429
430
431 - def run(self, input_args, quiet=False):
432 - """runs the module
433 + def run(self, input_args, quiet=False):
434 + """runs the module
435
436 - @param input_args: input arguments to be parsed
437 - """
438 - query = self.main_setup(input_args)
439 - query = self.validate_query(query)
440 - self.set_quiet(quiet)
441 - if query in ["use", "pkguse"]:
442 - self.analyse_flags(query)
443 - elif query in ["keywords"]:
444 - self.analyse_keywords()
445 - elif query in ["packages"]:
446 - self.analyse_packages()
447 + @param input_args: input arguments to be parsed
448 + """
449 + query = self.main_setup(input_args)
450 + query = self.validate_query(query)
451 + self.set_quiet(quiet)
452 + if query in ["use", "pkguse"]:
453 + self.analyse_flags(query)
454 + elif query in ["keywords"]:
455 + self.analyse_keywords()
456 + elif query in ["packages"]:
457 + self.analyse_packages()
458
459 - def analyse_flags(self, target):
460 - """This will scan the installed packages db and analyze the
461 - USE flags used for installation and produce a report on how
462 - they were used.
463 + def analyse_flags(self, target):
464 + """This will scan the installed packages db and analyze the
465 + USE flags used for installation and produce a report on how
466 + they were used.
467
468 - @type target: string
469 - @param target: the target to be analyzed, one of ["use", "pkguse"]
470 - """
471 - system_use = portage.settings["USE"].split()
472 - self.printer = AnalysisPrinter(
473 - "use",
474 - self.options["verbose"],
475 - system_use)
476 - if self.options["verbose"]:
477 - cpvs = VARDB.cpv_all()
478 - #cpvs = get_installed_cpvs()
479 - #print "Total number of installed ebuilds =", len(cpvs)
480 - flag_users = gather_flags_info(cpvs, system_use,
481 - self.options["unset"], target=target.upper(),
482 - use_portage=self.options['portage'])
483 - else:
484 - cpvs = get_installed_cpvs()
485 - flag_users = gather_flags_info(cpvs, system_flags=system_use,
486 - include_unset=self.options["unset"], target=target.upper(),
487 - use_portage=self.options['portage'])
488 - #print flag_users
489 - flag_keys = sorted(flag_users)
490 - if self.options["verbose"]:
491 - print(" Flag System #pkgs cat/pkg-ver")
492 - blankline = nl
493 - elif not self.options['quiet']:
494 - print(" Flag System #pkgs")
495 - blankline = lambda: None
496 - for flag in flag_keys:
497 - flag_pos = flag_users[flag]["+"]
498 - if len(flag_pos):
499 - self.printer(flag, "+", flag_pos)
500 - #blankline()
501 - flag_neg = flag_users[flag]["-"]
502 - if len(flag_neg):
503 - self.printer(flag, "-", flag_neg)
504 - #blankline()
505 - if "unset" in flag_users[flag] and flag_users[flag]["unset"]:
506 - flag_unset = flag_users[flag]["unset"]
507 - self.printer(flag, "unset", flag_unset)
508 - #blankline()
509 - if not self.options['quiet']:
510 - print("===================================================")
511 - print("Total number of flags in report =",
512 - pp.output.red(str(len(flag_keys))))
513 - if self.options["verbose"]:
514 - print("Total number of installed ebuilds =",
515 - pp.output.red(str(len([x for x in cpvs]))))
516 - print()
517 + @type target: string
518 + @param target: the target to be analyzed, one of ["use", "pkguse"]
519 + """
520 + system_use = portage.settings["USE"].split()
521 + self.printer = AnalysisPrinter(
522 + "use",
523 + self.options["verbose"],
524 + system_use)
525 + if self.options["verbose"]:
526 + cpvs = VARDB.cpv_all()
527 + #cpvs = get_installed_cpvs()
528 + #print "Total number of installed ebuilds =", len(cpvs)
529 + flag_users = gather_flags_info(cpvs, system_use,
530 + self.options["unset"], target=target.upper(),
531 + use_portage=self.options['portage'])
532 + else:
533 + cpvs = get_installed_cpvs()
534 + flag_users = gather_flags_info(cpvs, system_flags=system_use,
535 + include_unset=self.options["unset"], target=target.upper(),
536 + use_portage=self.options['portage'])
537 + #print flag_users
538 + flag_keys = sorted(flag_users)
539 + if self.options["verbose"]:
540 + print(" Flag System #pkgs cat/pkg-ver")
541 + blankline = nl
542 + elif not self.options['quiet']:
543 + print(" Flag System #pkgs")
544 + blankline = lambda: None
545 + for flag in flag_keys:
546 + flag_pos = flag_users[flag]["+"]
547 + if len(flag_pos):
548 + self.printer(flag, "+", flag_pos)
549 + #blankline()
550 + flag_neg = flag_users[flag]["-"]
551 + if len(flag_neg):
552 + self.printer(flag, "-", flag_neg)
553 + #blankline()
554 + if "unset" in flag_users[flag] and flag_users[flag]["unset"]:
555 + flag_unset = flag_users[flag]["unset"]
556 + self.printer(flag, "unset", flag_unset)
557 + #blankline()
558 + if not self.options['quiet']:
559 + print("===================================================")
560 + print("Total number of flags in report =",
561 + pp.output.red(str(len(flag_keys))))
562 + if self.options["verbose"]:
563 + print("Total number of installed ebuilds =",
564 + pp.output.red(str(len([x for x in cpvs]))))
565 + print()
566
567
568 - def analyse_keywords(self, keywords=None):
569 - """This will scan the installed packages db and analyze the
570 - keywords used for installation and produce a report on them.
571 - """
572 - print()
573 - system_keywords = portage.settings["ACCEPT_KEYWORDS"]
574 - arch = portage.settings["ARCH"]
575 - if self.options["prefix"]:
576 - # build a new keyword for testing
577 - system_keywords = "~" + arch + "-linux"
578 - if self.options["verbose"] or self.options["prefix"]:
579 - print("Current system ARCH =", arch)
580 - print("Current system ACCEPT_KEYWORDS =", system_keywords)
581 - system_keywords = system_keywords.split()
582 - self.printer = AnalysisPrinter(
583 - "keywords",
584 - self.options["verbose"],
585 - system_keywords)
586 - self.analyser = KeywordAnalyser( arch, system_keywords, VARDB)
587 - #self.analyser.set_order(portage.settings["USE"].split())
588 - # only for testing
589 - test_use = portage.settings["USE"].split()
590 - if self.options['prefix'] and 'prefix' not in test_use:
591 - print("ANALYSE_KEYWORDS() 'prefix' flag not found in system",
592 - "USE flags!!! appending for testing")
593 - print()
594 - test_use.append('prefix')
595 - self.analyser.set_order(test_use)
596 - # /end testing
597 + def analyse_keywords(self, keywords=None):
598 + """This will scan the installed packages db and analyze the
599 + keywords used for installation and produce a report on them.
600 + """
601 + print()
602 + system_keywords = portage.settings["ACCEPT_KEYWORDS"]
603 + arch = portage.settings["ARCH"]
604 + if self.options["prefix"]:
605 + # build a new keyword for testing
606 + system_keywords = "~" + arch + "-linux"
607 + if self.options["verbose"] or self.options["prefix"]:
608 + print("Current system ARCH =", arch)
609 + print("Current system ACCEPT_KEYWORDS =", system_keywords)
610 + system_keywords = system_keywords.split()
611 + self.printer = AnalysisPrinter(
612 + "keywords",
613 + self.options["verbose"],
614 + system_keywords)
615 + self.analyser = KeywordAnalyser( arch, system_keywords, VARDB)
616 + #self.analyser.set_order(portage.settings["USE"].split())
617 + # only for testing
618 + test_use = portage.settings["USE"].split()
619 + if self.options['prefix'] and 'prefix' not in test_use:
620 + print("ANALYSE_KEYWORDS() 'prefix' flag not found in system",
621 + "USE flags!!! appending for testing")
622 + print()
623 + test_use.append('prefix')
624 + self.analyser.set_order(test_use)
625 + # /end testing
626
627 - if self.options["verbose"]:
628 - cpvs = VARDB.cpv_all()
629 - #print "Total number of installed ebuilds =", len(cpvs)
630 - keyword_users = gather_keywords_info(
631 - cpvs=cpvs,
632 - system_keywords=system_keywords,
633 - use_portage=self.options['portage'],
634 - keywords=keywords, analyser = self.analyser
635 - )
636 - blankline = nl
637 - else:
638 - keyword_users = gather_keywords_info(
639 - system_keywords=system_keywords,
640 - use_portage=self.options['portage'],
641 - keywords=keywords,
642 - analyser = self.analyser
643 - )
644 - blankline = lambda: None
645 - #print keyword_users
646 - keyword_keys = sorted(keyword_users)
647 - if self.options["verbose"]:
648 - print(" Keyword System #pkgs cat/pkg-ver")
649 - elif not self.options['quiet']:
650 - print(" Keyword System #pkgs")
651 - for keyword in keyword_keys:
652 - kwd_stable = keyword_users[keyword]["stable"]
653 - if len(kwd_stable):
654 - self.printer(keyword, " ", kwd_stable)
655 - blankline()
656 - kwd_testing = keyword_users[keyword]["testing"]
657 - if len(kwd_testing):
658 - self.printer(keyword, "~", kwd_testing)
659 - blankline()
660 - kwd_missing = keyword_users[keyword]["missing"]
661 - if len(kwd_missing):
662 - self.printer(keyword, "-", kwd_missing)
663 - blankline
664 - if not self.options['quiet']:
665 - if self.analyser.mismatched:
666 - print("_________________________________________________")
667 - print(("The following packages were found to have a \n" +
668 - "different recorded ARCH than the current system ARCH"))
669 - for cpv in self.analyser.mismatched:
670 - print("\t", pp.cpv(cpv))
671 - print("===================================================")
672 - print("Total number of keywords in report =",
673 - pp.output.red(str(len(keyword_keys))))
674 - if self.options["verbose"]:
675 - print("Total number of installed ebuilds =",
676 - pp.output.red(str(len(cpvs))))
677 - print()
678 + if self.options["verbose"]:
679 + cpvs = VARDB.cpv_all()
680 + #print "Total number of installed ebuilds =", len(cpvs)
681 + keyword_users = gather_keywords_info(
682 + cpvs=cpvs,
683 + system_keywords=system_keywords,
684 + use_portage=self.options['portage'],
685 + keywords=keywords, analyser = self.analyser
686 + )
687 + blankline = nl
688 + else:
689 + keyword_users = gather_keywords_info(
690 + system_keywords=system_keywords,
691 + use_portage=self.options['portage'],
692 + keywords=keywords,
693 + analyser = self.analyser
694 + )
695 + blankline = lambda: None
696 + #print keyword_users
697 + keyword_keys = sorted(keyword_users)
698 + if self.options["verbose"]:
699 + print(" Keyword System #pkgs cat/pkg-ver")
700 + elif not self.options['quiet']:
701 + print(" Keyword System #pkgs")
702 + for keyword in keyword_keys:
703 + kwd_stable = keyword_users[keyword]["stable"]
704 + if len(kwd_stable):
705 + self.printer(keyword, " ", kwd_stable)
706 + blankline()
707 + kwd_testing = keyword_users[keyword]["testing"]
708 + if len(kwd_testing):
709 + self.printer(keyword, "~", kwd_testing)
710 + blankline()
711 + kwd_missing = keyword_users[keyword]["missing"]
712 + if len(kwd_missing):
713 + self.printer(keyword, "-", kwd_missing)
714 + blankline
715 + if not self.options['quiet']:
716 + if self.analyser.mismatched:
717 + print("_________________________________________________")
718 + print(("The following packages were found to have a \n" +
719 + "different recorded ARCH than the current system ARCH"))
720 + for cpv in self.analyser.mismatched:
721 + print("\t", pp.cpv(cpv))
722 + print("===================================================")
723 + print("Total number of keywords in report =",
724 + pp.output.red(str(len(keyword_keys))))
725 + if self.options["verbose"]:
726 + print("Total number of installed ebuilds =",
727 + pp.output.red(str(len(cpvs))))
728 + print()
729
730
731 - def analyse_packages(self):
732 - """This will scan the installed packages db and analyze the
733 - USE flags used for installation and produce a report.
734 + def analyse_packages(self):
735 + """This will scan the installed packages db and analyze the
736 + USE flags used for installation and produce a report.
737
738 - @type target: string
739 - @param target: the target to be analyzed, one of ["use", "pkguse"]
740 - """
741 - system_use = portage.settings["USE"].split()
742 - if self.options["verbose"]:
743 - cpvs = VARDB.cpv_all()
744 - key_width = 45
745 - else:
746 - cpvs = get_installed_cpvs()
747 - key_width = 1
748 + @type target: string
749 + @param target: the target to be analyzed, one of ["use", "pkguse"]
750 + """
751 + system_use = portage.settings["USE"].split()
752 + if self.options["verbose"]:
753 + cpvs = VARDB.cpv_all()
754 + key_width = 45
755 + else:
756 + cpvs = get_installed_cpvs()
757 + key_width = 1
758
759 - self.printer = AnalysisPrinter(
760 - "packages",
761 - self.options["verbose"],
762 - key_width=key_width)
763 + self.printer = AnalysisPrinter(
764 + "packages",
765 + self.options["verbose"],
766 + key_width=key_width)
767
768 - cpvs = sorted(cpvs)
769 - flags = FlagAnalyzer(
770 - system=system_use,
771 - filter_defaults=False,
772 - target="USE"
773 - )
774 + cpvs = sorted(cpvs)
775 + flags = FlagAnalyzer(
776 + system=system_use,
777 + filter_defaults=False,
778 + target="USE"
779 + )
780
781 - if self.options["verbose"]:
782 - print(" cat/pkg-ver USE Flags")
783 - # "app-emulation/emul-linux-x86-sdl-20100915 ...."
784 - blankline = nl
785 - elif not self.options['quiet']:
786 - print(" cat/pkg-ver USE Flags")
787 - blankline = lambda: None
788 - for cpv in cpvs:
789 - (flag_plus, flag_neg, unset) = flags.analyse_cpv(cpv)
790 - if self.options["unset"]:
791 - self.printer(cpv, "", (flag_plus, flag_neg, unset))
792 - else:
793 - self.printer(cpv, "", (flag_plus, flag_neg, []))
794 - if not self.options['quiet']:
795 - print("===================================================")
796 - print("Total number of installed ebuilds =",
797 - pp.output.red(str(len([x for x in cpvs]))))
798 - print()
799 + if self.options["verbose"]:
800 + print(" cat/pkg-ver USE Flags")
801 + # "app-emulation/emul-linux-x86-sdl-20100915 ...."
802 + blankline = nl
803 + elif not self.options['quiet']:
804 + print(" cat/pkg-ver USE Flags")
805 + blankline = lambda: None
806 + for cpv in cpvs:
807 + (flag_plus, flag_neg, unset) = flags.analyse_cpv(cpv)
808 + if self.options["unset"]:
809 + self.printer(cpv, "", (flag_plus, flag_neg, unset))
810 + else:
811 + self.printer(cpv, "", (flag_plus, flag_neg, []))
812 + if not self.options['quiet']:
813 + print("===================================================")
814 + print("Total number of installed ebuilds =",
815 + pp.output.red(str(len([x for x in cpvs]))))
816 + print()
817
818
819 def main(input_args):
820 - """Common starting method by the analyze master
821 - unless all modules are converted to this class method.
822 + """Common starting method by the analyze master
823 + unless all modules are converted to this class method.
824
825 - @param input_args: input args as supplied by equery master module.
826 - """
827 - query_module = Analyse()
828 - query_module.run(input_args, gentoolkit.CONFIG['quiet'])
829 + @param input_args: input args as supplied by equery master module.
830 + """
831 + query_module = Analyse()
832 + query_module.run(input_args, gentoolkit.CONFIG['quiet'])
833
834 # vim: set ts=4 sw=4 tw=79:
835
836 diff --git a/pym/gentoolkit/enalyze/rebuild.py b/pym/gentoolkit/enalyze/rebuild.py
837 index 0db001e..d0e1813 100644
838 --- a/pym/gentoolkit/enalyze/rebuild.py
839 +++ b/pym/gentoolkit/enalyze/rebuild.py
840 @@ -21,7 +21,7 @@ from gentoolkit.dbapi import PORTDB, VARDB
841 from gentoolkit.module_base import ModuleBase
842 from gentoolkit import pprinter as pp
843 from gentoolkit.enalyze.lib import (get_installed_use, get_flags, FlagAnalyzer,
844 - KeywordAnalyser)
845 + KeywordAnalyser)
846 from gentoolkit.flag import reduce_flags
847 from gentoolkit.enalyze.output import RebuildPrinter
848 from gentoolkit.atom import Atom
849 @@ -31,339 +31,339 @@ import portage
850
851
852 def cpv_all_diff_use(
853 - cpvs=None,
854 - system_flags=None,
855 - # override-able for testing
856 - _get_flags=get_flags,
857 - _get_used=get_installed_use
858 - ):
859 - """Data gathering and analysis function determines
860 - the difference between the current default USE flag settings
861 - and the currently installed pkgs recorded USE flag settings
862 -
863 - @type cpvs: list
864 - @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
865 - defaults to entire installed pkg db
866 - @type: system_flags: list
867 - @param system_flags: the current default USE flags as defined
868 - by portage.settings["USE"].split()
869 - @type _get_flags: function
870 - @param _get_flags: ovride-able for testing,
871 - defaults to gentoolkit.enalyze.lib.get_flags
872 - @param _get_used: ovride-able for testing,
873 - defaults to gentoolkit.enalyze.lib.get_installed_use
874 - @rtype dict. {cpv:['flag1', '-flag2',...]}
875 - """
876 - if cpvs is None:
877 - cpvs = VARDB.cpv_all()
878 - cpvs.sort()
879 - data = {}
880 - cp_counts = {}
881 - # pass them in to override for tests
882 - flags = FlagAnalyzer(system_flags,
883 - filter_defaults=True,
884 - target="USE",
885 - _get_flags=_get_flags,
886 - _get_used=get_installed_use
887 - )
888 - for cpv in cpvs:
889 - plus, minus, unset = flags.analyse_cpv(cpv)
890 - atom = Atom("="+cpv)
891 - atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
892 - for flag in minus:
893 - plus.add("-"+flag)
894 - if len(plus):
895 - if atom.cp not in data:
896 - data[atom.cp] = []
897 - if atom.cp not in cp_counts:
898 - cp_counts[atom.cp] = 0
899 - atom.use = list(plus)
900 - data[atom.cp].append(atom)
901 - cp_counts[atom.cp] += 1
902 - return data, cp_counts
903 + cpvs=None,
904 + system_flags=None,
905 + # override-able for testing
906 + _get_flags=get_flags,
907 + _get_used=get_installed_use
908 + ):
909 + """Data gathering and analysis function determines
910 + the difference between the current default USE flag settings
911 + and the currently installed pkgs recorded USE flag settings
912 +
913 + @type cpvs: list
914 + @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
915 + defaults to entire installed pkg db
916 + @type: system_flags: list
917 + @param system_flags: the current default USE flags as defined
918 + by portage.settings["USE"].split()
919 + @type _get_flags: function
920 + @param _get_flags: ovride-able for testing,
921 + defaults to gentoolkit.enalyze.lib.get_flags
922 + @param _get_used: ovride-able for testing,
923 + defaults to gentoolkit.enalyze.lib.get_installed_use
924 + @rtype dict. {cpv:['flag1', '-flag2',...]}
925 + """
926 + if cpvs is None:
927 + cpvs = VARDB.cpv_all()
928 + cpvs.sort()
929 + data = {}
930 + cp_counts = {}
931 + # pass them in to override for tests
932 + flags = FlagAnalyzer(system_flags,
933 + filter_defaults=True,
934 + target="USE",
935 + _get_flags=_get_flags,
936 + _get_used=get_installed_use
937 + )
938 + for cpv in cpvs:
939 + plus, minus, unset = flags.analyse_cpv(cpv)
940 + atom = Atom("="+cpv)
941 + atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
942 + for flag in minus:
943 + plus.add("-"+flag)
944 + if len(plus):
945 + if atom.cp not in data:
946 + data[atom.cp] = []
947 + if atom.cp not in cp_counts:
948 + cp_counts[atom.cp] = 0
949 + atom.use = list(plus)
950 + data[atom.cp].append(atom)
951 + cp_counts[atom.cp] += 1
952 + return data, cp_counts
953
954
955 def cpv_all_diff_keywords(
956 - cpvs=None,
957 - system_keywords=None,
958 - use_portage=False,
959 - # override-able for testing
960 - keywords=portage.settings["ACCEPT_KEYWORDS"],
961 - analyser = None
962 - ):
963 - """Analyze the installed pkgs 'keywords' for difference from ACCEPT_KEYWORDS
964 -
965 - @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
966 - defaults to entire installed pkg db
967 - @param system_keywords: list of the system keywords
968 - @param keywords: user defined list of keywords to check and report on
969 - or reports on all relevant keywords found to have been used.
970 - @param _get_kwds: overridable function for testing
971 - @param _get_used: overridable function for testing
972 - @rtype dict. {keyword:{"stable":[cat/pkg-ver,...],
973 - "testing":[cat/pkg-ver,...]}
974 - """
975 - if cpvs is None:
976 - cpvs = VARDB.cpv_all()
977 - keyword_users = {}
978 - cp_counts = {}
979 - for cpv in cpvs:
980 - if cpv.startswith("virtual"):
981 - continue
982 - if use_portage:
983 - keyword = analyser.get_inst_keyword_cpv(cpv)
984 - else:
985 - pkg = Package(cpv)
986 - keyword = analyser.get_inst_keyword_pkg(pkg)
987 - #print "returned keyword =", cpv, keyword, keyword[0]
988 - key = keyword[0]
989 - if key in ["~", "-"] and keyword not in system_keywords:
990 - atom = Atom("="+cpv)
991 - if atom.cp not in keyword_users:
992 - keyword_users[atom.cp] = []
993 - if atom.cp not in cp_counts:
994 - cp_counts[atom.cp] = 0
995 - if key in ["~"]:
996 - atom.keyword = keyword
997 - atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
998 - keyword_users[atom.cp].append(atom)
999 - cp_counts[atom.cp] += 1
1000 - elif key in ["-"]:
1001 - #print "adding cpv to missing:", cpv
1002 - atom.keyword = "**"
1003 - atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
1004 - keyword_users[atom.cp].append(atom)
1005 - cp_counts[atom.cp] += 1
1006 - return keyword_users, cp_counts
1007 + cpvs=None,
1008 + system_keywords=None,
1009 + use_portage=False,
1010 + # override-able for testing
1011 + keywords=portage.settings["ACCEPT_KEYWORDS"],
1012 + analyser = None
1013 + ):
1014 + """Analyze the installed pkgs 'keywords' for difference from ACCEPT_KEYWORDS
1015 +
1016 + @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
1017 + defaults to entire installed pkg db
1018 + @param system_keywords: list of the system keywords
1019 + @param keywords: user defined list of keywords to check and report on
1020 + or reports on all relevant keywords found to have been used.
1021 + @param _get_kwds: overridable function for testing
1022 + @param _get_used: overridable function for testing
1023 + @rtype dict. {keyword:{"stable":[cat/pkg-ver,...],
1024 + "testing":[cat/pkg-ver,...]}
1025 + """
1026 + if cpvs is None:
1027 + cpvs = VARDB.cpv_all()
1028 + keyword_users = {}
1029 + cp_counts = {}
1030 + for cpv in cpvs:
1031 + if cpv.startswith("virtual"):
1032 + continue
1033 + if use_portage:
1034 + keyword = analyser.get_inst_keyword_cpv(cpv)
1035 + else:
1036 + pkg = Package(cpv)
1037 + keyword = analyser.get_inst_keyword_pkg(pkg)
1038 + #print "returned keyword =", cpv, keyword, keyword[0]
1039 + key = keyword[0]
1040 + if key in ["~", "-"] and keyword not in system_keywords:
1041 + atom = Atom("="+cpv)
1042 + if atom.cp not in keyword_users:
1043 + keyword_users[atom.cp] = []
1044 + if atom.cp not in cp_counts:
1045 + cp_counts[atom.cp] = 0
1046 + if key in ["~"]:
1047 + atom.keyword = keyword
1048 + atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
1049 + keyword_users[atom.cp].append(atom)
1050 + cp_counts[atom.cp] += 1
1051 + elif key in ["-"]:
1052 + #print "adding cpv to missing:", cpv
1053 + atom.keyword = "**"
1054 + atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
1055 + keyword_users[atom.cp].append(atom)
1056 + cp_counts[atom.cp] += 1
1057 + return keyword_users, cp_counts
1058
1059
1060 class Rebuild(ModuleBase):
1061 - """Installed db analysis tool to query the installed databse
1062 - and produce/output stats for USE flags or keywords/mask.
1063 - The 'rebuild' action output is in the form suitable for file type output
1064 - to create a new package.use, package.keywords, package.unmask
1065 - type files in the event of needing to rebuild the
1066 - /etc/portage/* user configs
1067 - """
1068 - def __init__(self):
1069 - ModuleBase.__init__(self)
1070 - self.module_name = "rebuild"
1071 - self.options = {
1072 - "use": False,
1073 - "keywords": False,
1074 - "unmask": False,
1075 - "verbose": False,
1076 - "quiet": False,
1077 - "exact": False,
1078 - "pretend": False,
1079 - "prefix": False,
1080 - "portage": True,
1081 - "slot": False
1082 - #"unset": False
1083 - }
1084 - self.module_opts = {
1085 - "-p": ("pretend", "boolean", True),
1086 - "--pretend": ("pretend", "boolean", True),
1087 - "-e": ("exact", "boolean", True),
1088 - "--exact": ("exact", "boolean", True),
1089 - "-s": ("slot", "boolean", True),
1090 - "--slot": ("slot", "boolean", True),
1091 - "-v": ("verbose", "boolean", True),
1092 - "--verbose": ("verbose", "boolean", True),
1093 - }
1094 - self.formatted_options = [
1095 - (" -h, --help", "Outputs this useage message"),
1096 - (" -p, --pretend", "Does not actually create the files."),
1097 - (" ", "It directs the outputs to the screen"),
1098 - (" -e, --exact", "will atomize the package with a"),
1099 - (" ", "leading '=' and include the version"),
1100 - (" -s, --slot", "will atomize the package with a"),
1101 - (" ", "leading '=' and include the slot")
1102 - ]
1103 - self.formatted_args = [
1104 - (" use",
1105 - "causes the action to analyze the installed packages USE flags"),
1106 - (" keywords",
1107 - "causes the action to analyze the installed packages keywords"),
1108 - (" unmask",
1109 - "causes the action to analyze the installed packages " + \
1110 - "current mask status")
1111 - ]
1112 - self.short_opts = "hepsv"
1113 - self.long_opts = ("help", "exact", "pretend", "slot", "verbose")
1114 - self.need_queries = True
1115 - self.arg_spec = "TargetSpec"
1116 - self.arg_options = ['use', 'keywords', 'unmask']
1117 - self.arg_option = False
1118 - self.warning = (
1119 - " CAUTION",
1120 - "This is beta software and some features/options are incomplete,",
1121 - "some features may change in future releases includig its name.",
1122 - "The file generated is saved in your home directory",
1123 - "Feedback will be appreciated, http://bugs.gentoo.org")
1124 -
1125 -
1126 -
1127 - def run(self, input_args, quiet=False):
1128 - """runs the module
1129 -
1130 - @param input_args: input arguments to be parsed
1131 - """
1132 - self.options['quiet'] = quiet
1133 - query = self.main_setup(input_args)
1134 - query = self.validate_query(query)
1135 - if query in ["use"]:
1136 - self.rebuild_use()
1137 - elif query in ["keywords"]:
1138 - self.rebuild_keywords()
1139 - elif query in ["unmask"]:
1140 - self.rebuild_unmask()
1141 -
1142 -
1143 - def rebuild_use(self):
1144 - if not self.options["quiet"]:
1145 - print()
1146 - print(" -- Scanning installed packages for USE flag settings that")
1147 - print(" do not match the default settings")
1148 - system_use = portage.settings["USE"].split()
1149 - output = RebuildPrinter(
1150 - "use", self.options["pretend"], self.options["exact"],
1151 - self.options['slot'])
1152 - pkgs, cp_counts = cpv_all_diff_use(system_flags=system_use)
1153 - pkg_count = len(pkgs)
1154 - if self.options["verbose"]:
1155 - print()
1156 - print((pp.emph(" -- Found ") + pp.number(str(pkg_count)) +
1157 - pp.emph(" packages that need entries")))
1158 - #print pp.emph(" package.use to maintain their current setting")
1159 - if pkgs:
1160 - pkg_keys = sorted(pkgs)
1161 - #print len(pkgs)
1162 - if self.options["pretend"] and not self.options["quiet"]:
1163 - print()
1164 - print(pp.globaloption(
1165 - " -- These are the installed packages & use flags " +
1166 - "that were detected"))
1167 - print(pp.globaloption(" to need use flag settings other " +
1168 - "than the defaults."))
1169 - print()
1170 - elif not self.options["quiet"]:
1171 - print(" -- preparing pkgs for file entries")
1172 - for pkg in pkg_keys:
1173 - output(pkg, pkgs[pkg], cp_counts[pkg])
1174 - if self.options['verbose']:
1175 - message = (pp.emph(" ") +
1176 - pp.number(str(pkg_count)) +
1177 - pp.emph(" different packages"))
1178 - print()
1179 - print(pp.globaloption(" -- Totals"))
1180 - print(message)
1181 - #print
1182 - #unique = list(unique_flags)
1183 - #unique.sort()
1184 - #print unique
1185 - if not self.options["pretend"]:
1186 - filepath = os.path.expanduser('~/package.use.test')
1187 - self.save_file(filepath, output.lines)
1188 -
1189 - def rebuild_keywords(self):
1190 - print("Module action not yet available")
1191 - print()
1192 - """This will scan the installed packages db and analyze the
1193 - keywords used for installation and produce a report on them.
1194 - """
1195 - system_keywords = portage.settings["ACCEPT_KEYWORDS"].split()
1196 - output = RebuildPrinter(
1197 - "keywords", self.options["pretend"], self.options["exact"],
1198 - self.options['slot'])
1199 - arch = portage.settings["ARCH"]
1200 - if self.options["prefix"]:
1201 - # build a new keyword for testing
1202 - system_keywords = "~" + arch + "-linux"
1203 - if self.options["verbose"] or self.options["prefix"]:
1204 - print("Current system ARCH =", arch)
1205 - print("Current system ACCEPT_KEYWORDS =", system_keywords)
1206 - self.analyser = KeywordAnalyser( arch, system_keywords, VARDB)
1207 - #self.analyser.set_order(portage.settings["USE"].split())
1208 - # only for testing
1209 - test_use = portage.settings["USE"].split()
1210 - if self.options['prefix'] and 'prefix' not in test_use:
1211 - print("REBUILD_KEYWORDS() 'prefix' flag not found in system",
1212 - "USE flags!!! appending for testing")
1213 - print()
1214 - test_use.append('prefix')
1215 - self.analyser.set_order(test_use)
1216 - # /end testing
1217 -
1218 - cpvs = VARDB.cpv_all()
1219 - #print "Total number of installed ebuilds =", len(cpvs)
1220 - pkgs, cp_counts = cpv_all_diff_keywords(
1221 - cpvs=cpvs,
1222 - system_keywords=system_keywords,
1223 - use_portage=self.options['portage'],
1224 - analyser = self.analyser
1225 - )
1226 - #print([pkgs[p][0].cpv for p in pkgs])
1227 - if pkgs:
1228 - pkg_keys = sorted(pkgs)
1229 - #print(len(pkgs))
1230 - if self.options["pretend"] and not self.options["quiet"]:
1231 - print()
1232 - print(pp.globaloption(
1233 - " -- These are the installed packages & keywords " +
1234 - "that were detected"))
1235 - print(pp.globaloption(" to need keyword settings other " +
1236 - "than the defaults."))
1237 - print()
1238 - elif not self.options["quiet"]:
1239 - print(" -- preparing pkgs for file entries")
1240 - for pkg in pkg_keys:
1241 - output(pkg, pkgs[pkg], cp_counts[pkg])
1242 - if not self.options['quiet']:
1243 - if self.analyser.mismatched:
1244 - print("_________________________________________________")
1245 - print(("The following packages were found to have a \n" +
1246 - "different recorded ARCH than the current system ARCH"))
1247 - for cpv in self.analyser.mismatched:
1248 - print("\t", pp.cpv(cpv))
1249 - print("===================================================")
1250 - print("Total number of entries in report =",
1251 - pp.output.red(str(len(pkg_keys))))
1252 - if self.options["verbose"]:
1253 - print("Total number of installed ebuilds =",
1254 - pp.output.red(str(len(cpvs))))
1255 - print()
1256 - if not self.options["pretend"]:
1257 - filepath = os.path.expanduser('~/package.keywords.test')
1258 - self.save_file(filepath, output.lines)
1259 -
1260 -
1261 - def rebuild_unmask(self):
1262 - print("Module action not yet available")
1263 - print()
1264 -
1265 -
1266 - def save_file(self, filepath, data):
1267 - """Writes the data to the file determined by filepath
1268 -
1269 - @param filepath: string. eg. '/path/to/filename'
1270 - @param data: list of lines to write to filepath
1271 - """
1272 - if not self.options["quiet"]:
1273 - print(' - Saving file: %s' %filepath)
1274 - with open(filepath, "w") as output:
1275 - output.write('\n'.join(data))
1276 - print(" - Done")
1277 + """Installed db analysis tool to query the installed databse
1278 + and produce/output stats for USE flags or keywords/mask.
1279 + The 'rebuild' action output is in the form suitable for file type output
1280 + to create a new package.use, package.keywords, package.unmask
1281 + type files in the event of needing to rebuild the
1282 + /etc/portage/* user configs
1283 + """
1284 + def __init__(self):
1285 + ModuleBase.__init__(self)
1286 + self.module_name = "rebuild"
1287 + self.options = {
1288 + "use": False,
1289 + "keywords": False,
1290 + "unmask": False,
1291 + "verbose": False,
1292 + "quiet": False,
1293 + "exact": False,
1294 + "pretend": False,
1295 + "prefix": False,
1296 + "portage": True,
1297 + "slot": False
1298 + #"unset": False
1299 + }
1300 + self.module_opts = {
1301 + "-p": ("pretend", "boolean", True),
1302 + "--pretend": ("pretend", "boolean", True),
1303 + "-e": ("exact", "boolean", True),
1304 + "--exact": ("exact", "boolean", True),
1305 + "-s": ("slot", "boolean", True),
1306 + "--slot": ("slot", "boolean", True),
1307 + "-v": ("verbose", "boolean", True),
1308 + "--verbose": ("verbose", "boolean", True),
1309 + }
1310 + self.formatted_options = [
1311 + (" -h, --help", "Outputs this useage message"),
1312 + (" -p, --pretend", "Does not actually create the files."),
1313 + (" ", "It directs the outputs to the screen"),
1314 + (" -e, --exact", "will atomize the package with a"),
1315 + (" ", "leading '=' and include the version"),
1316 + (" -s, --slot", "will atomize the package with a"),
1317 + (" ", "leading '=' and include the slot")
1318 + ]
1319 + self.formatted_args = [
1320 + (" use",
1321 + "causes the action to analyze the installed packages USE flags"),
1322 + (" keywords",
1323 + "causes the action to analyze the installed packages keywords"),
1324 + (" unmask",
1325 + "causes the action to analyze the installed packages " + \
1326 + "current mask status")
1327 + ]
1328 + self.short_opts = "hepsv"
1329 + self.long_opts = ("help", "exact", "pretend", "slot", "verbose")
1330 + self.need_queries = True
1331 + self.arg_spec = "TargetSpec"
1332 + self.arg_options = ['use', 'keywords', 'unmask']
1333 + self.arg_option = False
1334 + self.warning = (
1335 + " CAUTION",
1336 + "This is beta software and some features/options are incomplete,",
1337 + "some features may change in future releases includig its name.",
1338 + "The file generated is saved in your home directory",
1339 + "Feedback will be appreciated, http://bugs.gentoo.org")
1340 +
1341 +
1342 +
1343 + def run(self, input_args, quiet=False):
1344 + """runs the module
1345 +
1346 + @param input_args: input arguments to be parsed
1347 + """
1348 + self.options['quiet'] = quiet
1349 + query = self.main_setup(input_args)
1350 + query = self.validate_query(query)
1351 + if query in ["use"]:
1352 + self.rebuild_use()
1353 + elif query in ["keywords"]:
1354 + self.rebuild_keywords()
1355 + elif query in ["unmask"]:
1356 + self.rebuild_unmask()
1357 +
1358 +
1359 + def rebuild_use(self):
1360 + if not self.options["quiet"]:
1361 + print()
1362 + print(" -- Scanning installed packages for USE flag settings that")
1363 + print(" do not match the default settings")
1364 + system_use = portage.settings["USE"].split()
1365 + output = RebuildPrinter(
1366 + "use", self.options["pretend"], self.options["exact"],
1367 + self.options['slot'])
1368 + pkgs, cp_counts = cpv_all_diff_use(system_flags=system_use)
1369 + pkg_count = len(pkgs)
1370 + if self.options["verbose"]:
1371 + print()
1372 + print((pp.emph(" -- Found ") + pp.number(str(pkg_count)) +
1373 + pp.emph(" packages that need entries")))
1374 + #print pp.emph(" package.use to maintain their current setting")
1375 + if pkgs:
1376 + pkg_keys = sorted(pkgs)
1377 + #print len(pkgs)
1378 + if self.options["pretend"] and not self.options["quiet"]:
1379 + print()
1380 + print(pp.globaloption(
1381 + " -- These are the installed packages & use flags " +
1382 + "that were detected"))
1383 + print(pp.globaloption(" to need use flag settings other " +
1384 + "than the defaults."))
1385 + print()
1386 + elif not self.options["quiet"]:
1387 + print(" -- preparing pkgs for file entries")
1388 + for pkg in pkg_keys:
1389 + output(pkg, pkgs[pkg], cp_counts[pkg])
1390 + if self.options['verbose']:
1391 + message = (pp.emph(" ") +
1392 + pp.number(str(pkg_count)) +
1393 + pp.emph(" different packages"))
1394 + print()
1395 + print(pp.globaloption(" -- Totals"))
1396 + print(message)
1397 + #print
1398 + #unique = list(unique_flags)
1399 + #unique.sort()
1400 + #print unique
1401 + if not self.options["pretend"]:
1402 + filepath = os.path.expanduser('~/package.use.test')
1403 + self.save_file(filepath, output.lines)
1404 +
1405 + def rebuild_keywords(self):
1406 + print("Module action not yet available")
1407 + print()
1408 + """This will scan the installed packages db and analyze the
1409 + keywords used for installation and produce a report on them.
1410 + """
1411 + system_keywords = portage.settings["ACCEPT_KEYWORDS"].split()
1412 + output = RebuildPrinter(
1413 + "keywords", self.options["pretend"], self.options["exact"],
1414 + self.options['slot'])
1415 + arch = portage.settings["ARCH"]
1416 + if self.options["prefix"]:
1417 + # build a new keyword for testing
1418 + system_keywords = "~" + arch + "-linux"
1419 + if self.options["verbose"] or self.options["prefix"]:
1420 + print("Current system ARCH =", arch)
1421 + print("Current system ACCEPT_KEYWORDS =", system_keywords)
1422 + self.analyser = KeywordAnalyser( arch, system_keywords, VARDB)
1423 + #self.analyser.set_order(portage.settings["USE"].split())
1424 + # only for testing
1425 + test_use = portage.settings["USE"].split()
1426 + if self.options['prefix'] and 'prefix' not in test_use:
1427 + print("REBUILD_KEYWORDS() 'prefix' flag not found in system",
1428 + "USE flags!!! appending for testing")
1429 + print()
1430 + test_use.append('prefix')
1431 + self.analyser.set_order(test_use)
1432 + # /end testing
1433 +
1434 + cpvs = VARDB.cpv_all()
1435 + #print "Total number of installed ebuilds =", len(cpvs)
1436 + pkgs, cp_counts = cpv_all_diff_keywords(
1437 + cpvs=cpvs,
1438 + system_keywords=system_keywords,
1439 + use_portage=self.options['portage'],
1440 + analyser = self.analyser
1441 + )
1442 + #print([pkgs[p][0].cpv for p in pkgs])
1443 + if pkgs:
1444 + pkg_keys = sorted(pkgs)
1445 + #print(len(pkgs))
1446 + if self.options["pretend"] and not self.options["quiet"]:
1447 + print()
1448 + print(pp.globaloption(
1449 + " -- These are the installed packages & keywords " +
1450 + "that were detected"))
1451 + print(pp.globaloption(" to need keyword settings other " +
1452 + "than the defaults."))
1453 + print()
1454 + elif not self.options["quiet"]:
1455 + print(" -- preparing pkgs for file entries")
1456 + for pkg in pkg_keys:
1457 + output(pkg, pkgs[pkg], cp_counts[pkg])
1458 + if not self.options['quiet']:
1459 + if self.analyser.mismatched:
1460 + print("_________________________________________________")
1461 + print(("The following packages were found to have a \n" +
1462 + "different recorded ARCH than the current system ARCH"))
1463 + for cpv in self.analyser.mismatched:
1464 + print("\t", pp.cpv(cpv))
1465 + print("===================================================")
1466 + print("Total number of entries in report =",
1467 + pp.output.red(str(len(pkg_keys))))
1468 + if self.options["verbose"]:
1469 + print("Total number of installed ebuilds =",
1470 + pp.output.red(str(len(cpvs))))
1471 + print()
1472 + if not self.options["pretend"]:
1473 + filepath = os.path.expanduser('~/package.keywords.test')
1474 + self.save_file(filepath, output.lines)
1475 +
1476 +
1477 + def rebuild_unmask(self):
1478 + print("Module action not yet available")
1479 + print()
1480 +
1481 +
1482 + def save_file(self, filepath, data):
1483 + """Writes the data to the file determined by filepath
1484 +
1485 + @param filepath: string. eg. '/path/to/filename'
1486 + @param data: list of lines to write to filepath
1487 + """
1488 + if not self.options["quiet"]:
1489 + print(' - Saving file: %s' %filepath)
1490 + with open(filepath, "w") as output:
1491 + output.write('\n'.join(data))
1492 + print(" - Done")
1493
1494
1495 def main(input_args):
1496 - """Common starting method by the analyze master
1497 - unless all modules are converted to this class method.
1498 + """Common starting method by the analyze master
1499 + unless all modules are converted to this class method.
1500
1501 - @param input_args: input args as supplied by equery master module.
1502 - """
1503 - query_module = Rebuild()
1504 - query_module.run(input_args, gentoolkit.CONFIG['quiet'])
1505 + @param input_args: input args as supplied by equery master module.
1506 + """
1507 + query_module = Rebuild()
1508 + query_module.run(input_args, gentoolkit.CONFIG['quiet'])
1509
1510 # vim: set ts=4 sw=4 tw=79: