elif keyword in keyword_users:
keyword_users[keyword]["stable"].append(cpv)
else:
- keyword_users[keyword] = {"stable": [cpv], "testing": [], "missing": []}
+ keyword_users[keyword] = {
+ "stable": [cpv],
+ "testing": [],
+ "missing": []
+ }
return keyword_users
self.options = {
"flags": False,
"keywords": False,
+ "packages": False,
"unset": False,
"verbose": False,
"quiet": False,
"--portage": ("portage", "boolean", False),
}
self.formatted_options = [
- (" -h, --help", "Outputs this useage message"),
- (" -a, --analyse",
+ (" -h, --help", "Outputs this useage message"),
+ (" -a, --analyse",
"Action, sets the module to gather data and output the"),
("", "formatted stats/information to the screen"),
- (" -u, --unset",
+ (" -u, --unset",
"Additionally include any unset USE flags and the packages"),
("", "that could use them"),
- (" -v, --verbose",
+ (" -v, --verbose",
"Used in the analyse action to output more detailed information"),
- (" -p, --prefix",
+ (" -p, --prefix",
"Used for testing purposes only, runs report using " +
"a prefix keyword and 'prefix' USE flag"),
- #(" -G, --portage",
+ #(" -G, --portage",
#"Use portage directly instead of gentoolkit's Package " +
#"object for some operations. Usually a little faster."),
]
self.formatted_args = [
- (" use",
- "causes the action to analyse the installed packages USE flags"),
- (" pkguse",
- "causes the action to analyse the installed packages PKGUSE flags"),
- (" ",
+ (" use",
+ "Causes the action to analyse the installed packages USE flags"),
+ (" pkguse",
+ "Causes the action to analyse the installed packages PKGUSE flags"),
+ (" ",
"These are flags that have been set in /etc/portage/package.use"),
- (" keywords",
- "causes the action to analyse the installed packages keywords"),
+ (" keywords",
+ "Causes the action to analyse the installed packages keywords"),
+ (" packages",
+ "Causes the action to analyse the installed packages and the"),
+ (" ",
+ "USE flags they were installed with"),
]
self.short_opts = "huvpG"
self.long_opts = ("help", "unset", "verbose", "prefix") #, "portage")
self.need_queries = True
self.arg_spec = "Target"
- self.arg_options = ['use', 'pkguse','keywords']
+ self.arg_options = ['use', 'pkguse','keywords', 'packages']
self.arg_option = False
self.warning = (
- " CAUTION",
+ " CAUTION",
"This is beta software and some features/options are incomplete,",
"some features may change in future releases includig its name.",
"Feedback will be appreciated, http://bugs.gentoo.org")
self.analyse_flags(query)
elif query in ["keywords"]:
self.analyse_keywords()
+ elif query in ["packages"]:
+ self.analyse_packages()
def analyse_flags(self, target):
"""This will scan the installed packages db and analyse the
@param target: the target to be analysed, one of ["use", "pkguse"]
"""
system_use = portage.settings["USE"].split()
- self.printer = AnalysisPrinter("use", self.options["verbose"], system_use)
+ self.printer = AnalysisPrinter(
+ "use",
+ self.options["verbose"],
+ system_use)
if self.options["verbose"]:
cpvs = VARDB.cpv_all()
#cpvs = get_installed_cpvs()
#print flag_users
flag_keys = sorted(flag_users)
if self.options["verbose"]:
- print(" Flag System #pkgs cat/pkg-ver")
+ print(" Flag System #pkgs cat/pkg-ver")
blankline = nl
elif not self.options['quiet']:
- print(" Flag System #pkgs")
+ print(" Flag System #pkgs")
blankline = lambda: None
for flag in flag_keys:
flag_pos = flag_users[flag]["+"]
#blankline()
if not self.options['quiet']:
print("===================================================")
- print("Total number of flags in report =", pp.output.red(str(len(flag_keys))))
+ print("Total number of flags in report =",
+ pp.output.red(str(len(flag_keys))))
if self.options["verbose"]:
- print("Total number of installed ebuilds =", pp.output.red(str(len([x for x in cpvs]))))
+ print("Total number of installed ebuilds =",
+ pp.output.red(str(len([x for x in cpvs]))))
print()
print("Current system ARCH =", arch)
print("Current system ACCEPT_KEYWORDS =", system_keywords)
system_keywords = system_keywords.split()
- self.printer = AnalysisPrinter("keywords", self.options["verbose"], system_keywords)
+ self.printer = AnalysisPrinter(
+ "keywords",
+ self.options["verbose"],
+ system_keywords)
self.analyser = KeywordAnalyser( arch, system_keywords, VARDB)
#self.analyser.set_order(portage.settings["USE"].split())
# only for testing
test_use = portage.settings["USE"].split()
if self.options['prefix'] and 'prefix' not in test_use:
- print("ANALYSE_KEYWORDS() 'prefix' flag not found in system USE flags!!! appending for testing")
+ print("ANALYSE_KEYWORDS() 'prefix' flag not found in system",
+ "USE flags!!! appending for testing")
print()
test_use.append('prefix')
self.analyser.set_order(test_use)
#print keyword_users
keyword_keys = sorted(keyword_users)
if self.options["verbose"]:
- print(" Keyword System #pkgs cat/pkg-ver")
+ print(" Keyword System #pkgs cat/pkg-ver")
elif not self.options['quiet']:
- print(" Keyword System #pkgs")
+ print(" Keyword System #pkgs")
for keyword in keyword_keys:
kwd_stable = keyword_users[keyword]["stable"]
if len(kwd_stable):
for cpv in self.analyser.mismatched:
print("\t", pp.cpv(cpv))
print("===================================================")
- print("Total number of keywords in report =", pp.output.red(str(len(keyword_keys))))
+ print("Total number of keywords in report =",
+ pp.output.red(str(len(keyword_keys))))
if self.options["verbose"]:
- print("Total number of installed ebuilds =", pp.output.red(str(len(cpvs))))
+ print("Total number of installed ebuilds =",
+ pp.output.red(str(len(cpvs))))
+ print()
+
+
+ def analyse_packages(self):
+ """This will scan the installed packages db and analyse the
+ USE flags used for installation and produce a report.
+
+ @type target: string
+ @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()
+ else:
+ cpvs = get_installed_cpvs()
+
+ flags = FlagAnalyzer(
+ system=system_use,
+ filter_defaults=False,
+ target="USE"
+ )
+
+ if self.options["verbose"]:
+ print(" cat/pkg-ver USE Flags")
+ blankline = nl
+ elif not self.options['quiet']:
+ 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 not self.options['quiet']:
+ print("===================================================")
+ print("Total number of installed ebuilds =",
+ pp.output.red(str(len([x for x in cpvs]))))
print()
def nl(lines=1):
"""small utility function to print blank lines
-
+
@type lines: integer
@param lines: optional number of blank lines to print
default = 1
self.print_fn = self.print_use_verbose
else:
self.print_fn = self.print_use_quiet
+ self._format_key = self._format_use_keyword
elif target in ["keywords"]:
if verbose:
self.print_fn = self.print_keyword_verbose
else:
self.print_fn = self.print_keyword_quiet
+ self._format_key = self._format_key_
+ elif target in ["packages"]:
+ if verbose:
+ self.print_fn = self.print_pkg_verbose
+ else:
+ self.print_fn = self.print_pkg_quiet
+ self._format_key = self._format_pkg_
- def __call__(self, key, active, pkgs):
- self._format_key(key, active, pkgs)
+ def __call__(self, key, active, data):
+ self._format_key(key, active, data)
- def _format_key(self, key, active, pkgs):
+ def _format_use_keyword(self, key, active, pkgs):
"""Determines the stats for key, formats it and
calls the pre-determined print function
"""
hard_masked=stability=="-"))
print(_key,'.'*(20-len(key)), default, pp.number(count))
+ # W0613: *Unused argument %r*
+ # pylint: disable-msg=W0613
+ def _format_pkg_(self, key, active, flags):
+ """Determines the stats for key, formats it and
+ calls the pre-determined print function
+ """
+ self.print_fn(key, flags)
+
+ @staticmethod
+ def print_pkg_verbose(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))
+ #cpv = _pkgs.pop(0)
+ print(pp.cpv(cpv),'.'*(45-len(cpv)), ", ".join(_flags))
+ #while _pkgs:
+ # cpv = _pkgs.pop(0)
+ # print(' '*52 + pp.cpv(cpv))
+
+
class RebuildPrinter(object):
"""Output functions"""
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
def header(self):
"""Generates a file header
"""
-
+
h=("# This package.%s file was generated by "
%self.target +
"gentoolkit's 'analyse rebuild' module\n"