* [gentoo-commits] proj/gentoolkit:gentoolkit commit in: pym/gentoolkit/, pym/gentoolkit/enalyze/
@ 2012-06-07 7:59 Brian Dolbec
0 siblings, 0 replies; 3+ messages in thread
From: Brian Dolbec @ 2012-06-07 7:59 UTC (permalink / raw
To: gentoo-commits
commit: a9881a28da795ce2285187062bfaa822d4e55a18
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Thu Jun 7 07:57:44 2012 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Thu Jun 7 07:57:44 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=a9881a28
fix a bug in enalyze rebuild where it did not consider IUSE defaults for calculating the use flag differences. Discovered by mingdao in #gentoo.
---
pym/gentoolkit/enalyze/lib.py | 23 +++++++++++++++--------
pym/gentoolkit/flag.py | 16 ++++++++++++++++
2 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/pym/gentoolkit/enalyze/lib.py b/pym/gentoolkit/enalyze/lib.py
index 015e23b..9dc28a3 100644
--- a/pym/gentoolkit/enalyze/lib.py
+++ b/pym/gentoolkit/enalyze/lib.py
@@ -14,7 +14,7 @@ from gentoolkit.dbapi import PORTDB, VARDB
from gentoolkit import errors
from gentoolkit.keyword import reduce_keywords
from gentoolkit.flag import (reduce_flags, get_flags, get_all_cpv_use,
- filter_flags, get_installed_use, get_iuse)
+ filter_flags, get_installed_use, get_iuse, defaulted_flags)
#from gentoolkit.package import Package
import portage
@@ -65,10 +65,12 @@ class FlagAnalyzer(object):
@return (plus, minus, unset) sets of USE flags
"""
installed = set(self.get_used(cpv, self.target))
- iuse = set(reduce_flags(self.get_flags(cpv)))
- return self._analyse(installed, iuse)
+ _iuse = self.get_flags(cpv)
+ iuse = set(reduce_flags(_iuse))
+ iuse_defaults = defaulted_flags(_iuse)
+ return self._analyse(installed, iuse, iuse_defaults)
- def _analyse(self, installed, iuse):
+ def _analyse(self, installed, iuse, iuse_defaults):
"""Analyzes the supplied info and returns the flag settings
that differ from the defaults
@@ -78,6 +80,9 @@ class FlagAnalyzer(object):
@param iuse: the current ebuilds IUSE
"""
defaults = self.system.intersection(iuse)
+ # update defaults with iuse_defaults
+ defaults.update(iuse_defaults['+'])
+ defaults = defaults.difference(iuse_defaults['-'])
usedflags = iuse.intersection(set(installed))
if self.filter_defaults:
plus = usedflags.difference(defaults)
@@ -98,10 +103,12 @@ class FlagAnalyzer(object):
@return (plus, minus, unset) sets of USE flags
"""
installed = set(self.pkg_used(pkg))
- print("installed =", installed)
- iuse = set(reduce_flags(self.pkg_flags(pkg)))
- print("iuse =", iuse)
- return self._analyse(installed, iuse)
+ #print("installed =", installed)
+ _iuse = self.pkg_flags(pkg)
+ iuse = set(reduce_flags(_iuse))
+ iuse_defaults = defaulted_flags(_iuse)
+ #print("iuse =", iuse)
+ return self._analyse(installed, iuse, iuse_defaults)
def pkg_used(self, pkg):
if self.target == "USE":
diff --git a/pym/gentoolkit/flag.py b/pym/gentoolkit/flag.py
index b5c8228..0377a81 100644
--- a/pym/gentoolkit/flag.py
+++ b/pym/gentoolkit/flag.py
@@ -13,6 +13,7 @@ __all__ = (
'get_installed_use',
'reduce_flag',
'reduce_flags',
+ 'defaulted_flags',
'filter_flags',
'get_all_cpv_use',
'get_flags'
@@ -84,6 +85,21 @@ def reduce_flags(the_list):
return r
+def defaulted_flags(the_list):
+ """Absolute value function for a USE flag list
+
+ @type the_list: list
+ @param the_list: the use flags to get defaulted ones from.
+ @rtype: dict of lists
+ @return defaulted USE flags {'+': [...], '-': [...]}
+ """
+ r={"+":[], "-": []}
+ for member in the_list:
+ if member[0] in ["+","-"]:
+ r[member[0]].append(member[1:])
+ return r
+
+
def filter_flags(use, use_expand_hidden, usemasked, useforced):
"""Filter function to remove hidden or otherwise not normally
visible USE flags from a list.
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [gentoo-commits] proj/gentoolkit:gentoolkit commit in: pym/gentoolkit/, pym/gentoolkit/enalyze/
@ 2012-06-29 2:40 Brian Dolbec
0 siblings, 0 replies; 3+ messages in thread
From: Brian Dolbec @ 2012-06-29 2:40 UTC (permalink / raw
To: gentoo-commits
commit: d51cbc5ea2f66803d073d9faed2ba79f9fe78472
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 29 02:36:13 2012 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Jun 29 02:36:13 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=d51cbc5e
move enalyse/base.py to gentoolkit for general module use.
---
pym/gentoolkit/enalyze/analyze.py | 786 ++++++++++----------
pym/gentoolkit/enalyze/rebuild.py | 650 ++++++++--------
pym/gentoolkit/{enalyze/base.py => module_base.py} | 0
3 files changed, 718 insertions(+), 718 deletions(-)
diff --git a/pym/gentoolkit/enalyze/analyze.py b/pym/gentoolkit/enalyze/analyze.py
index 180865d..33d1651 100644
--- a/pym/gentoolkit/enalyze/analyze.py
+++ b/pym/gentoolkit/enalyze/analyze.py
@@ -14,7 +14,7 @@ import sys
import gentoolkit
from gentoolkit.dbapi import PORTDB, VARDB
-from gentoolkit.enalyze.base import ModuleBase
+from gentoolkit.module_base import ModuleBase
from gentoolkit import pprinter as pp
from gentoolkit.flag import get_installed_use, get_flags
from gentoolkit.enalyze.lib import FlagAnalyzer, KeywordAnalyser
@@ -26,423 +26,423 @@ import portage
def gather_flags_info(
- cpvs=None,
- system_flags=None,
- include_unset=False,
- target="USE",
- use_portage=False,
- # override-able for testing
- _get_flags=get_flags,
- _get_used=get_installed_use
- ):
- """Analyze the installed pkgs USE flags for frequency of use
+ cpvs=None,
+ system_flags=None,
+ include_unset=False,
+ target="USE",
+ use_portage=False,
+ # override-able for testing
+ _get_flags=get_flags,
+ _get_used=get_installed_use
+ ):
+ """Analyze the installed pkgs USE flags for frequency of use
- @type cpvs: list
- @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
- defaults to entire installed pkg db
- @type: system_flags: list
- @param system_flags: the current default USE flags as defined
- by portage.settings["USE"].split()
- @type include_unset: bool
- @param include_unset: controls the inclusion of unset USE flags in the report.
- @type target: string
- @param target: the environment variable being analyzed
- one of ["USE", "PKGUSE"]
- @type _get_flags: function
- @param _get_flags: ovride-able for testing,
- defaults to gentoolkit.enalyze.lib.get_flags
- @param _get_used: ovride-able for testing,
- defaults to gentoolkit.enalyze.lib.get_installed_use
- @rtype dict. {flag:{"+":[cat/pkg-ver,...], "-":[cat/pkg-ver,...], "unset":[]}
- """
- if cpvs is None:
- cpvs = VARDB.cpv_all()
- # pass them in to override for tests
- flags = FlagAnalyzer(system_flags,
- filter_defaults=False,
- target=target,
- _get_flags=_get_flags,
- _get_used=get_installed_use
- )
- flag_users = {}
- for cpv in cpvs:
- if cpv.startswith("virtual"):
- continue
- if use_portage:
- plus, minus, unset = flags.analyse_cpv(cpv)
- else:
- pkg = Package(cpv)
- plus, minus, unset = flags.analyse_pkg(pkg)
- for flag in plus:
- if flag in flag_users:
- flag_users[flag]["+"].append(cpv)
- else:
- flag_users[flag] = {"+": [cpv], "-": []}
- for flag in minus:
- if flag in flag_users:
- flag_users[flag]["-"].append(cpv)
- else:
- flag_users[flag] = {"+":[], "-": [cpv]}
- if include_unset:
- for flag in unset:
- if flag in flag_users:
- if "unset" in flag_users[flag]:
- flag_users[flag]["unset"].append(cpv)
- else:
- flag_users[flag]["unset"] = [cpv]
- else:
- flag_users[flag] = {"+": [], "-": [], "unset": [cpv]}
- return flag_users
+ @type cpvs: list
+ @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
+ defaults to entire installed pkg db
+ @type: system_flags: list
+ @param system_flags: the current default USE flags as defined
+ by portage.settings["USE"].split()
+ @type include_unset: bool
+ @param include_unset: controls the inclusion of unset USE flags in the report.
+ @type target: string
+ @param target: the environment variable being analyzed
+ one of ["USE", "PKGUSE"]
+ @type _get_flags: function
+ @param _get_flags: ovride-able for testing,
+ defaults to gentoolkit.enalyze.lib.get_flags
+ @param _get_used: ovride-able for testing,
+ defaults to gentoolkit.enalyze.lib.get_installed_use
+ @rtype dict. {flag:{"+":[cat/pkg-ver,...], "-":[cat/pkg-ver,...], "unset":[]}
+ """
+ if cpvs is None:
+ cpvs = VARDB.cpv_all()
+ # pass them in to override for tests
+ flags = FlagAnalyzer(system_flags,
+ filter_defaults=False,
+ target=target,
+ _get_flags=_get_flags,
+ _get_used=get_installed_use
+ )
+ flag_users = {}
+ for cpv in cpvs:
+ if cpv.startswith("virtual"):
+ continue
+ if use_portage:
+ plus, minus, unset = flags.analyse_cpv(cpv)
+ else:
+ pkg = Package(cpv)
+ plus, minus, unset = flags.analyse_pkg(pkg)
+ for flag in plus:
+ if flag in flag_users:
+ flag_users[flag]["+"].append(cpv)
+ else:
+ flag_users[flag] = {"+": [cpv], "-": []}
+ for flag in minus:
+ if flag in flag_users:
+ flag_users[flag]["-"].append(cpv)
+ else:
+ flag_users[flag] = {"+":[], "-": [cpv]}
+ if include_unset:
+ for flag in unset:
+ if flag in flag_users:
+ if "unset" in flag_users[flag]:
+ flag_users[flag]["unset"].append(cpv)
+ else:
+ flag_users[flag]["unset"] = [cpv]
+ else:
+ flag_users[flag] = {"+": [], "-": [], "unset": [cpv]}
+ return flag_users
def gather_keywords_info(
- cpvs=None,
- system_keywords=None,
- use_portage=False,
- # override-able for testing
- keywords=portage.settings["ACCEPT_KEYWORDS"],
- analyser = None
- ):
- """Analyze the installed pkgs 'keywords' for frequency of use
+ cpvs=None,
+ system_keywords=None,
+ use_portage=False,
+ # override-able for testing
+ keywords=portage.settings["ACCEPT_KEYWORDS"],
+ analyser = None
+ ):
+ """Analyze the installed pkgs 'keywords' for frequency of use
- @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
- defaults to entire installed pkg db
- @param system_keywords: list of the system keywords
- @param keywords: user defined list of keywords to check and report on
- or reports on all relevant keywords found to have been used.
- @param _get_kwds: overridable function for testing
- @param _get_used: overridable function for testing
- @rtype dict. {keyword:{"stable":[cat/pkg-ver,...], "testing":[cat/pkg-ver,...]}
- """
- if cpvs is None:
- cpvs = VARDB.cpv_all()
- keyword_users = {}
- for cpv in cpvs:
- if cpv.startswith("virtual"):
- continue
- if use_portage:
- keyword = analyser.get_inst_keyword_cpv(cpv)
- else:
- pkg = Package(cpv)
- keyword = analyser.get_inst_keyword_pkg(pkg)
- #print "returned keyword =", cpv, keyword, keyword[0]
- key = keyword[0]
- if key in ["~", "-"]:
- _kwd = keyword[1:]
- if _kwd in keyword_users:
- if key in ["~"]:
- keyword_users[_kwd]["testing"].append(cpv)
- elif key in ["-"]:
- #print "adding cpv to missing:", cpv
- keyword_users[_kwd]["missing"].append(cpv)
- else:
- if key in ["~"]:
- keyword_users[_kwd] = {"stable": [],
- "testing": [cpv], "missing": []}
- elif key in ["-"]:
- keyword_users[_kwd] = {"stable": [],
- "testing": [], "missing": [cpv]}
- else:
- keyword_users[_kwd] = {"stable": [cpv],
- "testing": [], "missing": []}
- elif keyword in keyword_users:
- keyword_users[keyword]["stable"].append(cpv)
- else:
- keyword_users[keyword] = {
- "stable": [cpv],
- "testing": [],
- "missing": []
- }
- return keyword_users
+ @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
+ defaults to entire installed pkg db
+ @param system_keywords: list of the system keywords
+ @param keywords: user defined list of keywords to check and report on
+ or reports on all relevant keywords found to have been used.
+ @param _get_kwds: overridable function for testing
+ @param _get_used: overridable function for testing
+ @rtype dict. {keyword:{"stable":[cat/pkg-ver,...], "testing":[cat/pkg-ver,...]}
+ """
+ if cpvs is None:
+ cpvs = VARDB.cpv_all()
+ keyword_users = {}
+ for cpv in cpvs:
+ if cpv.startswith("virtual"):
+ continue
+ if use_portage:
+ keyword = analyser.get_inst_keyword_cpv(cpv)
+ else:
+ pkg = Package(cpv)
+ keyword = analyser.get_inst_keyword_pkg(pkg)
+ #print "returned keyword =", cpv, keyword, keyword[0]
+ key = keyword[0]
+ if key in ["~", "-"]:
+ _kwd = keyword[1:]
+ if _kwd in keyword_users:
+ if key in ["~"]:
+ keyword_users[_kwd]["testing"].append(cpv)
+ elif key in ["-"]:
+ #print "adding cpv to missing:", cpv
+ keyword_users[_kwd]["missing"].append(cpv)
+ else:
+ if key in ["~"]:
+ keyword_users[_kwd] = {"stable": [],
+ "testing": [cpv], "missing": []}
+ elif key in ["-"]:
+ keyword_users[_kwd] = {"stable": [],
+ "testing": [], "missing": [cpv]}
+ else:
+ keyword_users[_kwd] = {"stable": [cpv],
+ "testing": [], "missing": []}
+ elif keyword in keyword_users:
+ keyword_users[keyword]["stable"].append(cpv)
+ else:
+ keyword_users[keyword] = {
+ "stable": [cpv],
+ "testing": [],
+ "missing": []
+ }
+ return keyword_users
class Analyse(ModuleBase):
- """Installed db analysis tool to query the installed databse
- and produce/output stats for USE flags or keywords/mask.
- The 'rebuild' action output is in the form suitable for file type output
- to create a new package.use, package.keywords, package.unmask
- type files in the event of needing to rebuild the
- /etc/portage/* user configs
- """
- def __init__(self):
- ModuleBase.__init__(self)
- self.module_name = "enalyze"
- self.options = {
- "flags": False,
- "keywords": False,
- "packages": False,
- "unset": False,
- "verbose": False,
- "quiet": False,
- 'prefix': False,
- 'portage': True
- }
- self.module_opts = {
- "-f": ("flags", "boolean", True),
- "--flags": ("flags", "boolean", True),
- "-k": ("keywords", "boolean", True),
- "--keywords": ("keywords", "boolean", True),
- "-u": ("unset", "boolean", True),
- "--unset": ("unset", "boolean", True),
- "-v": ("verbose", "boolean", True),
- "--verbose": ("verbose", "boolean", True),
- "-p": ("prefix", "boolean", True),
- "--prefix": ("prefix", "boolean", True),
- "-G": ("portage", "boolean", False),
- "--portage": ("portage", "boolean", False),
- }
- self.formatted_options = [
- (" -h, --help", "Outputs this useage message"),
- (" -a, --analyze",
- "Action, sets the module to gather data and output the"),
- ("", "formatted stats/information to the screen"),
- (" -u, --unset",
- "Additionally include any unset USE flags and the packages"),
- ("", "that could use them"),
- (" -v, --verbose",
- "Used in the analyze action to output more detailed information"),
- (" -p, --prefix",
- "Used for testing purposes only, runs report using " +
- "a prefix keyword and 'prefix' USE flag"),
- #(" -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 analyze the installed packages USE flags"),
- (" pkguse",
- "Causes the action to analyze the installed packages PKGUSE flags"),
- (" ",
- "These are flags that have been set in /etc/portage/package.use"),
- (" keywords",
- "Causes the action to analyze the installed packages keywords"),
- (" packages",
- "Causes the action to analyze 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', 'packages']
- self.arg_option = False
- self.warning = (
- " 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")
+ """Installed db analysis tool to query the installed databse
+ and produce/output stats for USE flags or keywords/mask.
+ The 'rebuild' action output is in the form suitable for file type output
+ to create a new package.use, package.keywords, package.unmask
+ type files in the event of needing to rebuild the
+ /etc/portage/* user configs
+ """
+ def __init__(self):
+ ModuleBase.__init__(self)
+ self.module_name = "enalyze"
+ self.options = {
+ "flags": False,
+ "keywords": False,
+ "packages": False,
+ "unset": False,
+ "verbose": False,
+ "quiet": False,
+ 'prefix': False,
+ 'portage': True
+ }
+ self.module_opts = {
+ "-f": ("flags", "boolean", True),
+ "--flags": ("flags", "boolean", True),
+ "-k": ("keywords", "boolean", True),
+ "--keywords": ("keywords", "boolean", True),
+ "-u": ("unset", "boolean", True),
+ "--unset": ("unset", "boolean", True),
+ "-v": ("verbose", "boolean", True),
+ "--verbose": ("verbose", "boolean", True),
+ "-p": ("prefix", "boolean", True),
+ "--prefix": ("prefix", "boolean", True),
+ "-G": ("portage", "boolean", False),
+ "--portage": ("portage", "boolean", False),
+ }
+ self.formatted_options = [
+ (" -h, --help", "Outputs this useage message"),
+ (" -a, --analyze",
+ "Action, sets the module to gather data and output the"),
+ ("", "formatted stats/information to the screen"),
+ (" -u, --unset",
+ "Additionally include any unset USE flags and the packages"),
+ ("", "that could use them"),
+ (" -v, --verbose",
+ "Used in the analyze action to output more detailed information"),
+ (" -p, --prefix",
+ "Used for testing purposes only, runs report using " +
+ "a prefix keyword and 'prefix' USE flag"),
+ #(" -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 analyze the installed packages USE flags"),
+ (" pkguse",
+ "Causes the action to analyze the installed packages PKGUSE flags"),
+ (" ",
+ "These are flags that have been set in /etc/portage/package.use"),
+ (" keywords",
+ "Causes the action to analyze the installed packages keywords"),
+ (" packages",
+ "Causes the action to analyze 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', 'packages']
+ self.arg_option = False
+ self.warning = (
+ " 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")
- def run(self, input_args, quiet=False):
- """runs the module
+ def run(self, input_args, quiet=False):
+ """runs the module
- @param input_args: input arguments to be parsed
- """
- query = self.main_setup(input_args)
- query = self.validate_query(query)
- self.set_quiet(quiet)
- if query in ["use", "pkguse"]:
- self.analyse_flags(query)
- elif query in ["keywords"]:
- self.analyse_keywords()
- elif query in ["packages"]:
- self.analyse_packages()
+ @param input_args: input arguments to be parsed
+ """
+ query = self.main_setup(input_args)
+ query = self.validate_query(query)
+ self.set_quiet(quiet)
+ if query in ["use", "pkguse"]:
+ 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 analyze the
- USE flags used for installation and produce a report on how
- they were used.
+ def analyse_flags(self, target):
+ """This will scan the installed packages db and analyze the
+ USE flags used for installation and produce a report on how
+ they were used.
- @type target: string
- @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)
- if self.options["verbose"]:
- cpvs = VARDB.cpv_all()
- #cpvs = get_installed_cpvs()
- #print "Total number of installed ebuilds =", len(cpvs)
- flag_users = gather_flags_info(cpvs, system_use,
- self.options["unset"], target=target.upper(),
- use_portage=self.options['portage'])
- else:
- cpvs = get_installed_cpvs()
- flag_users = gather_flags_info(cpvs, system_flags=system_use,
- include_unset=self.options["unset"], target=target.upper(),
- use_portage=self.options['portage'])
- #print flag_users
- flag_keys = sorted(flag_users)
- if self.options["verbose"]:
- print(" Flag System #pkgs cat/pkg-ver")
- blankline = nl
- elif not self.options['quiet']:
- print(" Flag System #pkgs")
- blankline = lambda: None
- for flag in flag_keys:
- flag_pos = flag_users[flag]["+"]
- if len(flag_pos):
- self.printer(flag, "+", flag_pos)
- #blankline()
- flag_neg = flag_users[flag]["-"]
- if len(flag_neg):
- self.printer(flag, "-", flag_neg)
- #blankline()
- if "unset" in flag_users[flag] and flag_users[flag]["unset"]:
- flag_unset = flag_users[flag]["unset"]
- self.printer(flag, "unset", flag_unset)
- #blankline()
- if not self.options['quiet']:
- print("===================================================")
- 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()
+ @type target: string
+ @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)
+ if self.options["verbose"]:
+ cpvs = VARDB.cpv_all()
+ #cpvs = get_installed_cpvs()
+ #print "Total number of installed ebuilds =", len(cpvs)
+ flag_users = gather_flags_info(cpvs, system_use,
+ self.options["unset"], target=target.upper(),
+ use_portage=self.options['portage'])
+ else:
+ cpvs = get_installed_cpvs()
+ flag_users = gather_flags_info(cpvs, system_flags=system_use,
+ include_unset=self.options["unset"], target=target.upper(),
+ use_portage=self.options['portage'])
+ #print flag_users
+ flag_keys = sorted(flag_users)
+ if self.options["verbose"]:
+ print(" Flag System #pkgs cat/pkg-ver")
+ blankline = nl
+ elif not self.options['quiet']:
+ print(" Flag System #pkgs")
+ blankline = lambda: None
+ for flag in flag_keys:
+ flag_pos = flag_users[flag]["+"]
+ if len(flag_pos):
+ self.printer(flag, "+", flag_pos)
+ #blankline()
+ flag_neg = flag_users[flag]["-"]
+ if len(flag_neg):
+ self.printer(flag, "-", flag_neg)
+ #blankline()
+ if "unset" in flag_users[flag] and flag_users[flag]["unset"]:
+ flag_unset = flag_users[flag]["unset"]
+ self.printer(flag, "unset", flag_unset)
+ #blankline()
+ if not self.options['quiet']:
+ print("===================================================")
+ 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()
- def analyse_keywords(self, keywords=None):
- """This will scan the installed packages db and analyze the
- keywords used for installation and produce a report on them.
- """
- print()
- system_keywords = portage.settings["ACCEPT_KEYWORDS"]
- arch = portage.settings["ARCH"]
- if self.options["prefix"]:
- # build a new keyword for testing
- system_keywords = "~" + arch + "-linux"
- if self.options["verbose"] or self.options["prefix"]:
- 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.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()
- test_use.append('prefix')
- self.analyser.set_order(test_use)
- # /end testing
+ def analyse_keywords(self, keywords=None):
+ """This will scan the installed packages db and analyze the
+ keywords used for installation and produce a report on them.
+ """
+ print()
+ system_keywords = portage.settings["ACCEPT_KEYWORDS"]
+ arch = portage.settings["ARCH"]
+ if self.options["prefix"]:
+ # build a new keyword for testing
+ system_keywords = "~" + arch + "-linux"
+ if self.options["verbose"] or self.options["prefix"]:
+ 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.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()
+ test_use.append('prefix')
+ self.analyser.set_order(test_use)
+ # /end testing
- if self.options["verbose"]:
- cpvs = VARDB.cpv_all()
- #print "Total number of installed ebuilds =", len(cpvs)
- keyword_users = gather_keywords_info(
- cpvs=cpvs,
- system_keywords=system_keywords,
- use_portage=self.options['portage'],
- keywords=keywords, analyser = self.analyser
- )
- blankline = nl
- else:
- keyword_users = gather_keywords_info(
- system_keywords=system_keywords,
- use_portage=self.options['portage'],
- keywords=keywords,
- analyser = self.analyser
- )
- blankline = lambda: None
- #print keyword_users
- keyword_keys = sorted(keyword_users)
- if self.options["verbose"]:
- print(" Keyword System #pkgs cat/pkg-ver")
- elif not self.options['quiet']:
- print(" Keyword System #pkgs")
- for keyword in keyword_keys:
- kwd_stable = keyword_users[keyword]["stable"]
- if len(kwd_stable):
- self.printer(keyword, " ", kwd_stable)
- blankline()
- kwd_testing = keyword_users[keyword]["testing"]
- if len(kwd_testing):
- self.printer(keyword, "~", kwd_testing)
- blankline()
- kwd_missing = keyword_users[keyword]["missing"]
- if len(kwd_missing):
- self.printer(keyword, "-", kwd_missing)
- blankline
- if not self.options['quiet']:
- if self.analyser.mismatched:
- print("_________________________________________________")
- print(("The following packages were found to have a \n" +
- "different recorded ARCH than the current system ARCH"))
- 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))))
- if self.options["verbose"]:
- print("Total number of installed ebuilds =",
- pp.output.red(str(len(cpvs))))
- print()
+ if self.options["verbose"]:
+ cpvs = VARDB.cpv_all()
+ #print "Total number of installed ebuilds =", len(cpvs)
+ keyword_users = gather_keywords_info(
+ cpvs=cpvs,
+ system_keywords=system_keywords,
+ use_portage=self.options['portage'],
+ keywords=keywords, analyser = self.analyser
+ )
+ blankline = nl
+ else:
+ keyword_users = gather_keywords_info(
+ system_keywords=system_keywords,
+ use_portage=self.options['portage'],
+ keywords=keywords,
+ analyser = self.analyser
+ )
+ blankline = lambda: None
+ #print keyword_users
+ keyword_keys = sorted(keyword_users)
+ if self.options["verbose"]:
+ print(" Keyword System #pkgs cat/pkg-ver")
+ elif not self.options['quiet']:
+ print(" Keyword System #pkgs")
+ for keyword in keyword_keys:
+ kwd_stable = keyword_users[keyword]["stable"]
+ if len(kwd_stable):
+ self.printer(keyword, " ", kwd_stable)
+ blankline()
+ kwd_testing = keyword_users[keyword]["testing"]
+ if len(kwd_testing):
+ self.printer(keyword, "~", kwd_testing)
+ blankline()
+ kwd_missing = keyword_users[keyword]["missing"]
+ if len(kwd_missing):
+ self.printer(keyword, "-", kwd_missing)
+ blankline
+ if not self.options['quiet']:
+ if self.analyser.mismatched:
+ print("_________________________________________________")
+ print(("The following packages were found to have a \n" +
+ "different recorded ARCH than the current system ARCH"))
+ 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))))
+ if self.options["verbose"]:
+ 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 analyze the
- USE flags used for installation and produce a report.
+ def analyse_packages(self):
+ """This will scan the installed packages db and analyze the
+ USE flags used for installation and produce a report.
- @type target: string
- @param target: the target to be analyzed, one of ["use", "pkguse"]
- """
- system_use = portage.settings["USE"].split()
- if self.options["verbose"]:
- cpvs = VARDB.cpv_all()
- key_width = 45
- else:
- cpvs = get_installed_cpvs()
- key_width = 1
+ @type target: string
+ @param target: the target to be analyzed, one of ["use", "pkguse"]
+ """
+ system_use = portage.settings["USE"].split()
+ if self.options["verbose"]:
+ cpvs = VARDB.cpv_all()
+ key_width = 45
+ else:
+ cpvs = get_installed_cpvs()
+ key_width = 1
- self.printer = AnalysisPrinter(
- "packages",
- self.options["verbose"],
- key_width=key_width)
+ self.printer = AnalysisPrinter(
+ "packages",
+ self.options["verbose"],
+ key_width=key_width)
- cpvs = sorted(cpvs)
- flags = FlagAnalyzer(
- system=system_use,
- filter_defaults=False,
- target="USE"
- )
+ cpvs = sorted(cpvs)
+ flags = FlagAnalyzer(
+ system=system_use,
+ filter_defaults=False,
+ target="USE"
+ )
- if self.options["verbose"]:
- print(" cat/pkg-ver USE Flags")
- # "app-emulation/emul-linux-x86-sdl-20100915 ...."
- blankline = nl
- elif not self.options['quiet']:
- print(" cat/pkg-ver USE Flags")
- blankline = lambda: None
- for cpv in cpvs:
- (flag_plus, flag_neg, unset) = flags.analyse_cpv(cpv)
- if self.options["unset"]:
- self.printer(cpv, "", (flag_plus, flag_neg, unset))
- else:
- self.printer(cpv, "", (flag_plus, flag_neg, []))
- if not self.options['quiet']:
- print("===================================================")
- print("Total number of installed ebuilds =",
- pp.output.red(str(len([x for x in cpvs]))))
- print()
+ if self.options["verbose"]:
+ print(" cat/pkg-ver USE Flags")
+ # "app-emulation/emul-linux-x86-sdl-20100915 ...."
+ blankline = nl
+ elif not self.options['quiet']:
+ print(" cat/pkg-ver USE Flags")
+ blankline = lambda: None
+ for cpv in cpvs:
+ (flag_plus, flag_neg, unset) = flags.analyse_cpv(cpv)
+ if self.options["unset"]:
+ self.printer(cpv, "", (flag_plus, flag_neg, unset))
+ else:
+ self.printer(cpv, "", (flag_plus, flag_neg, []))
+ if not self.options['quiet']:
+ print("===================================================")
+ print("Total number of installed ebuilds =",
+ pp.output.red(str(len([x for x in cpvs]))))
+ print()
def main(input_args):
- """Common starting method by the analyze master
- unless all modules are converted to this class method.
+ """Common starting method by the analyze master
+ unless all modules are converted to this class method.
- @param input_args: input args as supplied by equery master module.
- """
- query_module = Analyse()
- query_module.run(input_args, gentoolkit.CONFIG['quiet'])
+ @param input_args: input args as supplied by equery master module.
+ """
+ query_module = Analyse()
+ query_module.run(input_args, gentoolkit.CONFIG['quiet'])
# vim: set ts=4 sw=4 tw=79:
diff --git a/pym/gentoolkit/enalyze/rebuild.py b/pym/gentoolkit/enalyze/rebuild.py
index f1d7e88..0db001e 100644
--- a/pym/gentoolkit/enalyze/rebuild.py
+++ b/pym/gentoolkit/enalyze/rebuild.py
@@ -18,10 +18,10 @@ import sys
import gentoolkit
from gentoolkit.dbapi import PORTDB, VARDB
-from gentoolkit.enalyze.base import ModuleBase
+from gentoolkit.module_base import ModuleBase
from gentoolkit import pprinter as pp
from gentoolkit.enalyze.lib import (get_installed_use, get_flags, FlagAnalyzer,
- KeywordAnalyser)
+ KeywordAnalyser)
from gentoolkit.flag import reduce_flags
from gentoolkit.enalyze.output import RebuildPrinter
from gentoolkit.atom import Atom
@@ -31,339 +31,339 @@ import portage
def cpv_all_diff_use(
- cpvs=None,
- system_flags=None,
- # override-able for testing
- _get_flags=get_flags,
- _get_used=get_installed_use
- ):
- """Data gathering and analysis function determines
- the difference between the current default USE flag settings
- and the currently installed pkgs recorded USE flag settings
-
- @type cpvs: list
- @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
- defaults to entire installed pkg db
- @type: system_flags: list
- @param system_flags: the current default USE flags as defined
- by portage.settings["USE"].split()
- @type _get_flags: function
- @param _get_flags: ovride-able for testing,
- defaults to gentoolkit.enalyze.lib.get_flags
- @param _get_used: ovride-able for testing,
- defaults to gentoolkit.enalyze.lib.get_installed_use
- @rtype dict. {cpv:['flag1', '-flag2',...]}
- """
- if cpvs is None:
- cpvs = VARDB.cpv_all()
- cpvs.sort()
- data = {}
- cp_counts = {}
- # pass them in to override for tests
- flags = FlagAnalyzer(system_flags,
- filter_defaults=True,
- target="USE",
- _get_flags=_get_flags,
- _get_used=get_installed_use
- )
- for cpv in cpvs:
- plus, minus, unset = flags.analyse_cpv(cpv)
- atom = Atom("="+cpv)
- atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
- for flag in minus:
- plus.add("-"+flag)
- if len(plus):
- if atom.cp not in data:
- data[atom.cp] = []
- if atom.cp not in cp_counts:
- cp_counts[atom.cp] = 0
- atom.use = list(plus)
- data[atom.cp].append(atom)
- cp_counts[atom.cp] += 1
- return data, cp_counts
+ cpvs=None,
+ system_flags=None,
+ # override-able for testing
+ _get_flags=get_flags,
+ _get_used=get_installed_use
+ ):
+ """Data gathering and analysis function determines
+ the difference between the current default USE flag settings
+ and the currently installed pkgs recorded USE flag settings
+
+ @type cpvs: list
+ @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
+ defaults to entire installed pkg db
+ @type: system_flags: list
+ @param system_flags: the current default USE flags as defined
+ by portage.settings["USE"].split()
+ @type _get_flags: function
+ @param _get_flags: ovride-able for testing,
+ defaults to gentoolkit.enalyze.lib.get_flags
+ @param _get_used: ovride-able for testing,
+ defaults to gentoolkit.enalyze.lib.get_installed_use
+ @rtype dict. {cpv:['flag1', '-flag2',...]}
+ """
+ if cpvs is None:
+ cpvs = VARDB.cpv_all()
+ cpvs.sort()
+ data = {}
+ cp_counts = {}
+ # pass them in to override for tests
+ flags = FlagAnalyzer(system_flags,
+ filter_defaults=True,
+ target="USE",
+ _get_flags=_get_flags,
+ _get_used=get_installed_use
+ )
+ for cpv in cpvs:
+ plus, minus, unset = flags.analyse_cpv(cpv)
+ atom = Atom("="+cpv)
+ atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
+ for flag in minus:
+ plus.add("-"+flag)
+ if len(plus):
+ if atom.cp not in data:
+ data[atom.cp] = []
+ if atom.cp not in cp_counts:
+ cp_counts[atom.cp] = 0
+ atom.use = list(plus)
+ data[atom.cp].append(atom)
+ cp_counts[atom.cp] += 1
+ return data, cp_counts
def cpv_all_diff_keywords(
- cpvs=None,
- system_keywords=None,
- use_portage=False,
- # override-able for testing
- keywords=portage.settings["ACCEPT_KEYWORDS"],
- analyser = None
- ):
- """Analyze the installed pkgs 'keywords' for difference from ACCEPT_KEYWORDS
-
- @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
- defaults to entire installed pkg db
- @param system_keywords: list of the system keywords
- @param keywords: user defined list of keywords to check and report on
- or reports on all relevant keywords found to have been used.
- @param _get_kwds: overridable function for testing
- @param _get_used: overridable function for testing
- @rtype dict. {keyword:{"stable":[cat/pkg-ver,...],
- "testing":[cat/pkg-ver,...]}
- """
- if cpvs is None:
- cpvs = VARDB.cpv_all()
- keyword_users = {}
- cp_counts = {}
- for cpv in cpvs:
- if cpv.startswith("virtual"):
- continue
- if use_portage:
- keyword = analyser.get_inst_keyword_cpv(cpv)
- else:
- pkg = Package(cpv)
- keyword = analyser.get_inst_keyword_pkg(pkg)
- #print "returned keyword =", cpv, keyword, keyword[0]
- key = keyword[0]
- if key in ["~", "-"] and keyword not in system_keywords:
- atom = Atom("="+cpv)
- if atom.cp not in keyword_users:
- keyword_users[atom.cp] = []
- if atom.cp not in cp_counts:
- cp_counts[atom.cp] = 0
- if key in ["~"]:
- atom.keyword = keyword
- atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
- keyword_users[atom.cp].append(atom)
- cp_counts[atom.cp] += 1
- elif key in ["-"]:
- #print "adding cpv to missing:", cpv
- atom.keyword = "**"
- atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
- keyword_users[atom.cp].append(atom)
- cp_counts[atom.cp] += 1
- return keyword_users, cp_counts
+ cpvs=None,
+ system_keywords=None,
+ use_portage=False,
+ # override-able for testing
+ keywords=portage.settings["ACCEPT_KEYWORDS"],
+ analyser = None
+ ):
+ """Analyze the installed pkgs 'keywords' for difference from ACCEPT_KEYWORDS
+
+ @param cpvs: optional list of [cat/pkg-ver,...] to analyze or
+ defaults to entire installed pkg db
+ @param system_keywords: list of the system keywords
+ @param keywords: user defined list of keywords to check and report on
+ or reports on all relevant keywords found to have been used.
+ @param _get_kwds: overridable function for testing
+ @param _get_used: overridable function for testing
+ @rtype dict. {keyword:{"stable":[cat/pkg-ver,...],
+ "testing":[cat/pkg-ver,...]}
+ """
+ if cpvs is None:
+ cpvs = VARDB.cpv_all()
+ keyword_users = {}
+ cp_counts = {}
+ for cpv in cpvs:
+ if cpv.startswith("virtual"):
+ continue
+ if use_portage:
+ keyword = analyser.get_inst_keyword_cpv(cpv)
+ else:
+ pkg = Package(cpv)
+ keyword = analyser.get_inst_keyword_pkg(pkg)
+ #print "returned keyword =", cpv, keyword, keyword[0]
+ key = keyword[0]
+ if key in ["~", "-"] and keyword not in system_keywords:
+ atom = Atom("="+cpv)
+ if atom.cp not in keyword_users:
+ keyword_users[atom.cp] = []
+ if atom.cp not in cp_counts:
+ cp_counts[atom.cp] = 0
+ if key in ["~"]:
+ atom.keyword = keyword
+ atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
+ keyword_users[atom.cp].append(atom)
+ cp_counts[atom.cp] += 1
+ elif key in ["-"]:
+ #print "adding cpv to missing:", cpv
+ atom.keyword = "**"
+ atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
+ keyword_users[atom.cp].append(atom)
+ cp_counts[atom.cp] += 1
+ return keyword_users, cp_counts
class Rebuild(ModuleBase):
- """Installed db analysis tool to query the installed databse
- and produce/output stats for USE flags or keywords/mask.
- The 'rebuild' action output is in the form suitable for file type output
- to create a new package.use, package.keywords, package.unmask
- type files in the event of needing to rebuild the
- /etc/portage/* user configs
- """
- def __init__(self):
- ModuleBase.__init__(self)
- self.module_name = "rebuild"
- self.options = {
- "use": False,
- "keywords": False,
- "unmask": False,
- "verbose": False,
- "quiet": False,
- "exact": False,
- "pretend": False,
- "prefix": False,
- "portage": True,
- "slot": False
- #"unset": False
- }
- self.module_opts = {
- "-p": ("pretend", "boolean", True),
- "--pretend": ("pretend", "boolean", True),
- "-e": ("exact", "boolean", True),
- "--exact": ("exact", "boolean", True),
- "-s": ("slot", "boolean", True),
- "--slot": ("slot", "boolean", True),
- "-v": ("verbose", "boolean", True),
- "--verbose": ("verbose", "boolean", True),
- }
- self.formatted_options = [
- (" -h, --help", "Outputs this useage message"),
- (" -p, --pretend", "Does not actually create the files."),
- (" ", "It directs the outputs to the screen"),
- (" -e, --exact", "will atomize the package with a"),
- (" ", "leading '=' and include the version"),
- (" -s, --slot", "will atomize the package with a"),
- (" ", "leading '=' and include the slot")
- ]
- self.formatted_args = [
- (" use",
- "causes the action to analyze the installed packages USE flags"),
- (" keywords",
- "causes the action to analyze the installed packages keywords"),
- (" unmask",
- "causes the action to analyze the installed packages " + \
- "current mask status")
- ]
- self.short_opts = "hepsv"
- self.long_opts = ("help", "exact", "pretend", "slot", "verbose")
- self.need_queries = True
- self.arg_spec = "TargetSpec"
- self.arg_options = ['use', 'keywords', 'unmask']
- self.arg_option = False
- self.warning = (
- " CAUTION",
- "This is beta software and some features/options are incomplete,",
- "some features may change in future releases includig its name.",
- "The file generated is saved in your home directory",
- "Feedback will be appreciated, http://bugs.gentoo.org")
-
-
-
- def run(self, input_args, quiet=False):
- """runs the module
-
- @param input_args: input arguments to be parsed
- """
- self.options['quiet'] = quiet
- query = self.main_setup(input_args)
- query = self.validate_query(query)
- if query in ["use"]:
- self.rebuild_use()
- elif query in ["keywords"]:
- self.rebuild_keywords()
- elif query in ["unmask"]:
- self.rebuild_unmask()
-
-
- def rebuild_use(self):
- if not self.options["quiet"]:
- print()
- print(" -- Scanning installed packages for USE flag settings that")
- print(" do not match the default settings")
- system_use = portage.settings["USE"].split()
- output = RebuildPrinter(
- "use", self.options["pretend"], self.options["exact"],
- self.options['slot'])
- pkgs, cp_counts = cpv_all_diff_use(system_flags=system_use)
- pkg_count = len(pkgs)
- if self.options["verbose"]:
- print()
- print((pp.emph(" -- Found ") + pp.number(str(pkg_count)) +
- pp.emph(" packages that need entries")))
- #print pp.emph(" package.use to maintain their current setting")
- if pkgs:
- pkg_keys = sorted(pkgs)
- #print len(pkgs)
- if self.options["pretend"] and not self.options["quiet"]:
- print()
- print(pp.globaloption(
- " -- These are the installed packages & use flags " +
- "that were detected"))
- print(pp.globaloption(" to need use flag settings other " +
- "than the defaults."))
- print()
- elif not self.options["quiet"]:
- print(" -- preparing pkgs for file entries")
- for pkg in pkg_keys:
- output(pkg, pkgs[pkg], cp_counts[pkg])
- if self.options['verbose']:
- message = (pp.emph(" ") +
- pp.number(str(pkg_count)) +
- pp.emph(" different packages"))
- print()
- print(pp.globaloption(" -- Totals"))
- print(message)
- #print
- #unique = list(unique_flags)
- #unique.sort()
- #print unique
- if not self.options["pretend"]:
- filepath = os.path.expanduser('~/package.use.test')
- self.save_file(filepath, output.lines)
-
- def rebuild_keywords(self):
- print("Module action not yet available")
- print()
- """This will scan the installed packages db and analyze the
- keywords used for installation and produce a report on them.
- """
- system_keywords = portage.settings["ACCEPT_KEYWORDS"].split()
- output = RebuildPrinter(
- "keywords", self.options["pretend"], self.options["exact"],
- self.options['slot'])
- arch = portage.settings["ARCH"]
- if self.options["prefix"]:
- # build a new keyword for testing
- system_keywords = "~" + arch + "-linux"
- if self.options["verbose"] or self.options["prefix"]:
- print("Current system ARCH =", arch)
- print("Current system ACCEPT_KEYWORDS =", 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("REBUILD_KEYWORDS() 'prefix' flag not found in system",
- "USE flags!!! appending for testing")
- print()
- test_use.append('prefix')
- self.analyser.set_order(test_use)
- # /end testing
-
- cpvs = VARDB.cpv_all()
- #print "Total number of installed ebuilds =", len(cpvs)
- pkgs, cp_counts = cpv_all_diff_keywords(
- cpvs=cpvs,
- system_keywords=system_keywords,
- use_portage=self.options['portage'],
- analyser = self.analyser
- )
- #print([pkgs[p][0].cpv for p in pkgs])
- if pkgs:
- pkg_keys = sorted(pkgs)
- #print(len(pkgs))
- if self.options["pretend"] and not self.options["quiet"]:
- print()
- print(pp.globaloption(
- " -- These are the installed packages & keywords " +
- "that were detected"))
- print(pp.globaloption(" to need keyword settings other " +
- "than the defaults."))
- print()
- elif not self.options["quiet"]:
- print(" -- preparing pkgs for file entries")
- for pkg in pkg_keys:
- output(pkg, pkgs[pkg], cp_counts[pkg])
- if not self.options['quiet']:
- if self.analyser.mismatched:
- print("_________________________________________________")
- print(("The following packages were found to have a \n" +
- "different recorded ARCH than the current system ARCH"))
- for cpv in self.analyser.mismatched:
- print("\t", pp.cpv(cpv))
- print("===================================================")
- print("Total number of entries in report =",
- pp.output.red(str(len(pkg_keys))))
- if self.options["verbose"]:
- print("Total number of installed ebuilds =",
- pp.output.red(str(len(cpvs))))
- print()
- if not self.options["pretend"]:
- filepath = os.path.expanduser('~/package.keywords.test')
- self.save_file(filepath, output.lines)
-
-
- def rebuild_unmask(self):
- print("Module action not yet available")
- print()
-
-
- def save_file(self, filepath, data):
- """Writes the data to the file determined by filepath
-
- @param filepath: string. eg. '/path/to/filename'
- @param data: list of lines to write to filepath
- """
- if not self.options["quiet"]:
- print(' - Saving file: %s' %filepath)
- with open(filepath, "w") as output:
- output.write('\n'.join(data))
- print(" - Done")
+ """Installed db analysis tool to query the installed databse
+ and produce/output stats for USE flags or keywords/mask.
+ The 'rebuild' action output is in the form suitable for file type output
+ to create a new package.use, package.keywords, package.unmask
+ type files in the event of needing to rebuild the
+ /etc/portage/* user configs
+ """
+ def __init__(self):
+ ModuleBase.__init__(self)
+ self.module_name = "rebuild"
+ self.options = {
+ "use": False,
+ "keywords": False,
+ "unmask": False,
+ "verbose": False,
+ "quiet": False,
+ "exact": False,
+ "pretend": False,
+ "prefix": False,
+ "portage": True,
+ "slot": False
+ #"unset": False
+ }
+ self.module_opts = {
+ "-p": ("pretend", "boolean", True),
+ "--pretend": ("pretend", "boolean", True),
+ "-e": ("exact", "boolean", True),
+ "--exact": ("exact", "boolean", True),
+ "-s": ("slot", "boolean", True),
+ "--slot": ("slot", "boolean", True),
+ "-v": ("verbose", "boolean", True),
+ "--verbose": ("verbose", "boolean", True),
+ }
+ self.formatted_options = [
+ (" -h, --help", "Outputs this useage message"),
+ (" -p, --pretend", "Does not actually create the files."),
+ (" ", "It directs the outputs to the screen"),
+ (" -e, --exact", "will atomize the package with a"),
+ (" ", "leading '=' and include the version"),
+ (" -s, --slot", "will atomize the package with a"),
+ (" ", "leading '=' and include the slot")
+ ]
+ self.formatted_args = [
+ (" use",
+ "causes the action to analyze the installed packages USE flags"),
+ (" keywords",
+ "causes the action to analyze the installed packages keywords"),
+ (" unmask",
+ "causes the action to analyze the installed packages " + \
+ "current mask status")
+ ]
+ self.short_opts = "hepsv"
+ self.long_opts = ("help", "exact", "pretend", "slot", "verbose")
+ self.need_queries = True
+ self.arg_spec = "TargetSpec"
+ self.arg_options = ['use', 'keywords', 'unmask']
+ self.arg_option = False
+ self.warning = (
+ " CAUTION",
+ "This is beta software and some features/options are incomplete,",
+ "some features may change in future releases includig its name.",
+ "The file generated is saved in your home directory",
+ "Feedback will be appreciated, http://bugs.gentoo.org")
+
+
+
+ def run(self, input_args, quiet=False):
+ """runs the module
+
+ @param input_args: input arguments to be parsed
+ """
+ self.options['quiet'] = quiet
+ query = self.main_setup(input_args)
+ query = self.validate_query(query)
+ if query in ["use"]:
+ self.rebuild_use()
+ elif query in ["keywords"]:
+ self.rebuild_keywords()
+ elif query in ["unmask"]:
+ self.rebuild_unmask()
+
+
+ def rebuild_use(self):
+ if not self.options["quiet"]:
+ print()
+ print(" -- Scanning installed packages for USE flag settings that")
+ print(" do not match the default settings")
+ system_use = portage.settings["USE"].split()
+ output = RebuildPrinter(
+ "use", self.options["pretend"], self.options["exact"],
+ self.options['slot'])
+ pkgs, cp_counts = cpv_all_diff_use(system_flags=system_use)
+ pkg_count = len(pkgs)
+ if self.options["verbose"]:
+ print()
+ print((pp.emph(" -- Found ") + pp.number(str(pkg_count)) +
+ pp.emph(" packages that need entries")))
+ #print pp.emph(" package.use to maintain their current setting")
+ if pkgs:
+ pkg_keys = sorted(pkgs)
+ #print len(pkgs)
+ if self.options["pretend"] and not self.options["quiet"]:
+ print()
+ print(pp.globaloption(
+ " -- These are the installed packages & use flags " +
+ "that were detected"))
+ print(pp.globaloption(" to need use flag settings other " +
+ "than the defaults."))
+ print()
+ elif not self.options["quiet"]:
+ print(" -- preparing pkgs for file entries")
+ for pkg in pkg_keys:
+ output(pkg, pkgs[pkg], cp_counts[pkg])
+ if self.options['verbose']:
+ message = (pp.emph(" ") +
+ pp.number(str(pkg_count)) +
+ pp.emph(" different packages"))
+ print()
+ print(pp.globaloption(" -- Totals"))
+ print(message)
+ #print
+ #unique = list(unique_flags)
+ #unique.sort()
+ #print unique
+ if not self.options["pretend"]:
+ filepath = os.path.expanduser('~/package.use.test')
+ self.save_file(filepath, output.lines)
+
+ def rebuild_keywords(self):
+ print("Module action not yet available")
+ print()
+ """This will scan the installed packages db and analyze the
+ keywords used for installation and produce a report on them.
+ """
+ system_keywords = portage.settings["ACCEPT_KEYWORDS"].split()
+ output = RebuildPrinter(
+ "keywords", self.options["pretend"], self.options["exact"],
+ self.options['slot'])
+ arch = portage.settings["ARCH"]
+ if self.options["prefix"]:
+ # build a new keyword for testing
+ system_keywords = "~" + arch + "-linux"
+ if self.options["verbose"] or self.options["prefix"]:
+ print("Current system ARCH =", arch)
+ print("Current system ACCEPT_KEYWORDS =", 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("REBUILD_KEYWORDS() 'prefix' flag not found in system",
+ "USE flags!!! appending for testing")
+ print()
+ test_use.append('prefix')
+ self.analyser.set_order(test_use)
+ # /end testing
+
+ cpvs = VARDB.cpv_all()
+ #print "Total number of installed ebuilds =", len(cpvs)
+ pkgs, cp_counts = cpv_all_diff_keywords(
+ cpvs=cpvs,
+ system_keywords=system_keywords,
+ use_portage=self.options['portage'],
+ analyser = self.analyser
+ )
+ #print([pkgs[p][0].cpv for p in pkgs])
+ if pkgs:
+ pkg_keys = sorted(pkgs)
+ #print(len(pkgs))
+ if self.options["pretend"] and not self.options["quiet"]:
+ print()
+ print(pp.globaloption(
+ " -- These are the installed packages & keywords " +
+ "that were detected"))
+ print(pp.globaloption(" to need keyword settings other " +
+ "than the defaults."))
+ print()
+ elif not self.options["quiet"]:
+ print(" -- preparing pkgs for file entries")
+ for pkg in pkg_keys:
+ output(pkg, pkgs[pkg], cp_counts[pkg])
+ if not self.options['quiet']:
+ if self.analyser.mismatched:
+ print("_________________________________________________")
+ print(("The following packages were found to have a \n" +
+ "different recorded ARCH than the current system ARCH"))
+ for cpv in self.analyser.mismatched:
+ print("\t", pp.cpv(cpv))
+ print("===================================================")
+ print("Total number of entries in report =",
+ pp.output.red(str(len(pkg_keys))))
+ if self.options["verbose"]:
+ print("Total number of installed ebuilds =",
+ pp.output.red(str(len(cpvs))))
+ print()
+ if not self.options["pretend"]:
+ filepath = os.path.expanduser('~/package.keywords.test')
+ self.save_file(filepath, output.lines)
+
+
+ def rebuild_unmask(self):
+ print("Module action not yet available")
+ print()
+
+
+ def save_file(self, filepath, data):
+ """Writes the data to the file determined by filepath
+
+ @param filepath: string. eg. '/path/to/filename'
+ @param data: list of lines to write to filepath
+ """
+ if not self.options["quiet"]:
+ print(' - Saving file: %s' %filepath)
+ with open(filepath, "w") as output:
+ output.write('\n'.join(data))
+ print(" - Done")
def main(input_args):
- """Common starting method by the analyze master
- unless all modules are converted to this class method.
+ """Common starting method by the analyze master
+ unless all modules are converted to this class method.
- @param input_args: input args as supplied by equery master module.
- """
- query_module = Rebuild()
- query_module.run(input_args, gentoolkit.CONFIG['quiet'])
+ @param input_args: input args as supplied by equery master module.
+ """
+ query_module = Rebuild()
+ query_module.run(input_args, gentoolkit.CONFIG['quiet'])
# vim: set ts=4 sw=4 tw=79:
diff --git a/pym/gentoolkit/enalyze/base.py b/pym/gentoolkit/module_base.py
similarity index 100%
rename from pym/gentoolkit/enalyze/base.py
rename to pym/gentoolkit/module_base.py
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [gentoo-commits] proj/gentoolkit:gentoolkit commit in: pym/gentoolkit/, pym/gentoolkit/enalyze/
@ 2012-08-01 3:26 Brian Dolbec
0 siblings, 0 replies; 3+ messages in thread
From: Brian Dolbec @ 2012-08-01 3:26 UTC (permalink / raw
To: gentoo-commits
commit: 58b14f6f6ee39ffbb1eb5ffdce6e04e911a22d5d
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 1 03:23:14 2012 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Wed Aug 1 03:24:58 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=58b14f6f
replace all use of dbapi's PORTDB, VARDB, BINDB assigned variables with the actuall portage calls to take advantage of all 3 being lazyloaded. The assignemt in dbapi causes all 3 to be loaded, slowing down runs that do not need all 3
---
pym/gentoolkit/dependencies.py | 5 ++---
pym/gentoolkit/enalyze/analyze.py | 13 ++++++-------
pym/gentoolkit/enalyze/lib.py | 7 +++----
pym/gentoolkit/enalyze/rebuild.py | 15 +++++++--------
pym/gentoolkit/flag.py | 22 ++++++++++------------
pym/gentoolkit/helpers.py | 21 +++++++++++----------
pym/gentoolkit/package.py | 25 ++++++++++++-------------
pym/gentoolkit/query.py | 15 +++++++--------
8 files changed, 58 insertions(+), 65 deletions(-)
diff --git a/pym/gentoolkit/dependencies.py b/pym/gentoolkit/dependencies.py
index 0396952..84e3672 100644
--- a/pym/gentoolkit/dependencies.py
+++ b/pym/gentoolkit/dependencies.py
@@ -20,7 +20,6 @@ from gentoolkit import errors
from gentoolkit.atom import Atom
from gentoolkit.cpv import CPV
from gentoolkit.helpers import uniqify
-from gentoolkit.dbapi import PORTDB, VARDB
from gentoolkit.query import Query
# =======
@@ -69,10 +68,10 @@ class Dependencies(Query):
# Try to use the Portage tree first, since emerge only uses the tree
# when calculating dependencies
try:
- result = PORTDB.aux_get(self.cpv, envvars)
+ result = portage.db[portage.root]["porttree"].dbapi.aux_get(self.cpv, envvars)
except KeyError:
try:
- result = VARDB.aux_get(self.cpv, envvars)
+ result = portage.db[portage.root]["vartree"].dbapi.aux_get(self.cpv, envvars)
except KeyError:
return []
return result
diff --git a/pym/gentoolkit/enalyze/analyze.py b/pym/gentoolkit/enalyze/analyze.py
index 2ba028f..7033422 100644
--- a/pym/gentoolkit/enalyze/analyze.py
+++ b/pym/gentoolkit/enalyze/analyze.py
@@ -13,7 +13,6 @@ from __future__ import print_function
import sys
import gentoolkit
-from gentoolkit.dbapi import PORTDB, VARDB
from gentoolkit.module_base import ModuleBase
from gentoolkit import pprinter as pp
from gentoolkit.flag import get_installed_use, get_flags
@@ -56,7 +55,7 @@ def gather_flags_info(
@rtype dict. {flag:{"+":[cat/pkg-ver,...], "-":[cat/pkg-ver,...], "unset":[]}
"""
if cpvs is None:
- cpvs = VARDB.cpv_all()
+ cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
# pass them in to override for tests
flags = FlagAnalyzer(system_flags,
filter_defaults=False,
@@ -115,7 +114,7 @@ def gather_keywords_info(
@rtype dict. {keyword:{"stable":[cat/pkg-ver,...], "testing":[cat/pkg-ver,...]}
"""
if cpvs is None:
- cpvs = VARDB.cpv_all()
+ cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
keyword_users = {}
for cpv in cpvs:
if cpv.startswith("virtual"):
@@ -264,7 +263,7 @@ class Analyse(ModuleBase):
self.options["verbose"],
system_use)
if self.options["verbose"]:
- cpvs = VARDB.cpv_all()
+ cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
#cpvs = get_installed_cpvs()
#print "Total number of installed ebuilds =", len(cpvs)
flag_users = gather_flags_info(cpvs, system_use,
@@ -324,7 +323,7 @@ class Analyse(ModuleBase):
"keywords",
self.options["verbose"],
system_keywords)
- self.analyser = KeywordAnalyser( arch, system_keywords, VARDB)
+ self.analyser = KeywordAnalyser( arch, system_keywords, portage.db[portage.root]["vartree"].dbapi)
#self.analyser.set_order(portage.settings["USE"].split())
# only for testing
test_use = portage.settings["USE"].split()
@@ -337,7 +336,7 @@ class Analyse(ModuleBase):
# /end testing
if self.options["verbose"]:
- cpvs = VARDB.cpv_all()
+ cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
#print "Total number of installed ebuilds =", len(cpvs)
keyword_users = gather_keywords_info(
cpvs=cpvs,
@@ -398,7 +397,7 @@ class Analyse(ModuleBase):
"""
system_use = portage.settings["USE"].split()
if self.options["verbose"]:
- cpvs = VARDB.cpv_all()
+ cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
key_width = 45
else:
cpvs = get_installed_cpvs()
diff --git a/pym/gentoolkit/enalyze/lib.py b/pym/gentoolkit/enalyze/lib.py
index 9dc28a3..de306f0 100644
--- a/pym/gentoolkit/enalyze/lib.py
+++ b/pym/gentoolkit/enalyze/lib.py
@@ -10,7 +10,6 @@
import sys
-from gentoolkit.dbapi import PORTDB, VARDB
from gentoolkit import errors
from gentoolkit.keyword import reduce_keywords
from gentoolkit.flag import (reduce_flags, get_flags, get_all_cpv_use,
@@ -158,7 +157,7 @@ class KeywordAnalyser(object):
@param arch: the system ARCH setting
@type accept_keywords: list
@param accept_keywords: eg. ['x86', '~x86']
- @type get_aux: function, defaults to: VARDB.aux_get
+ @type get_aux: function, defaults to: portage.db[portage.root]["vartree"].dbapi.aux_get
@param vardb: vardb class of functions, needed=aux_get()
to return => KEYWORDS & USE flags for a cpv
= aux_get(cpv, ["KEYWORDS", "USE"])
@@ -170,7 +169,7 @@ class KeywordAnalyser(object):
parse_range = list(range(len(normal_order)))
- def __init__(self, arch, accept_keywords, vardb=VARDB):
+ def __init__(self, arch, accept_keywords, vardb=portage.db[portage.root]["vartree"].dbapi):
self.arch = arch
self.accept_keywords = accept_keywords
self.vardb = vardb
@@ -356,6 +355,6 @@ class KeywordAnalyser(object):
self.parse_order = self.normal_order
self.keyword = self.arch
#print "SET_ORDER() completed: prefix =", self.prefix, ", keyword =", \
- # self.keyword, "parse order =",self.parse_order
+ # self.keyword, "parse order =",self.parse_order
#print
diff --git a/pym/gentoolkit/enalyze/rebuild.py b/pym/gentoolkit/enalyze/rebuild.py
index d0e1813..cd1a08a 100644
--- a/pym/gentoolkit/enalyze/rebuild.py
+++ b/pym/gentoolkit/enalyze/rebuild.py
@@ -17,7 +17,6 @@ import os
import sys
import gentoolkit
-from gentoolkit.dbapi import PORTDB, VARDB
from gentoolkit.module_base import ModuleBase
from gentoolkit import pprinter as pp
from gentoolkit.enalyze.lib import (get_installed_use, get_flags, FlagAnalyzer,
@@ -55,7 +54,7 @@ def cpv_all_diff_use(
@rtype dict. {cpv:['flag1', '-flag2',...]}
"""
if cpvs is None:
- cpvs = VARDB.cpv_all()
+ cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
cpvs.sort()
data = {}
cp_counts = {}
@@ -69,7 +68,7 @@ def cpv_all_diff_use(
for cpv in cpvs:
plus, minus, unset = flags.analyse_cpv(cpv)
atom = Atom("="+cpv)
- atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
+ atom.slot = portage.db[portage.root]["vartree"].dbapi.aux_get(atom.cpv, ["SLOT"])[0]
for flag in minus:
plus.add("-"+flag)
if len(plus):
@@ -104,7 +103,7 @@ def cpv_all_diff_keywords(
"testing":[cat/pkg-ver,...]}
"""
if cpvs is None:
- cpvs = VARDB.cpv_all()
+ cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
keyword_users = {}
cp_counts = {}
for cpv in cpvs:
@@ -125,13 +124,13 @@ def cpv_all_diff_keywords(
cp_counts[atom.cp] = 0
if key in ["~"]:
atom.keyword = keyword
- atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
+ atom.slot = portage.db[portage.root]["vartree"].dbapi.aux_get(atom.cpv, ["SLOT"])[0]
keyword_users[atom.cp].append(atom)
cp_counts[atom.cp] += 1
elif key in ["-"]:
#print "adding cpv to missing:", cpv
atom.keyword = "**"
- atom.slot = VARDB.aux_get(atom.cpv, ["SLOT"])[0]
+ atom.slot = portage.db[portage.root]["vartree"].dbapi.aux_get(atom.cpv, ["SLOT"])[0]
keyword_users[atom.cp].append(atom)
cp_counts[atom.cp] += 1
return keyword_users, cp_counts
@@ -283,7 +282,7 @@ class Rebuild(ModuleBase):
if self.options["verbose"] or self.options["prefix"]:
print("Current system ARCH =", arch)
print("Current system ACCEPT_KEYWORDS =", system_keywords)
- self.analyser = KeywordAnalyser( arch, system_keywords, VARDB)
+ self.analyser = KeywordAnalyser( arch, system_keywords, portage.db[portage.root]["vartree"].dbapi)
#self.analyser.set_order(portage.settings["USE"].split())
# only for testing
test_use = portage.settings["USE"].split()
@@ -295,7 +294,7 @@ class Rebuild(ModuleBase):
self.analyser.set_order(test_use)
# /end testing
- cpvs = VARDB.cpv_all()
+ cpvs = portage.db[portage.root]["vartree"].dbapi.cpv_all()
#print "Total number of installed ebuilds =", len(cpvs)
pkgs, cp_counts = cpv_all_diff_keywords(
cpvs=cpvs,
diff --git a/pym/gentoolkit/flag.py b/pym/gentoolkit/flag.py
index 0377a81..9983ba7 100644
--- a/pym/gentoolkit/flag.py
+++ b/pym/gentoolkit/flag.py
@@ -22,8 +22,6 @@ __all__ = (
import sys
-from gentoolkit.dbapi import PORTDB, VARDB
-
import portage
@@ -38,7 +36,7 @@ def get_iuse(cpv):
"""
try:
# aux_get might return dupes, so run them through set() to remove them
- return list(set(PORTDB.aux_get(cpv, ["IUSE"])[0].split()))
+ return list(set(portage.db[portage.root]["porttree"].dbapi.aux_get(cpv, ["IUSE"])[0].split()))
except:
return []
@@ -54,7 +52,7 @@ def get_installed_use(cpv, use="USE"):
@rtype list
@returns [] or the list of IUSE flags
"""
- return VARDB.aux_get(cpv,[use])[0].split()
+ return portage.db[portage.root]["vartree"].dbapi.aux_get(cpv,[use])[0].split()
def reduce_flag(flag):
@@ -144,20 +142,20 @@ def get_all_cpv_use(cpv):
@return use, use_expand_hidden, usemask, useforce
"""
use = None
- PORTDB.settings.unlock()
+ portage.db[portage.root]["porttree"].dbapi.settings.unlock()
try:
- PORTDB.settings.setcpv(cpv, mydb=portage.portdb)
+ portage.db[portage.root]["porttree"].dbapi.settings.setcpv(cpv, mydb=portage.portdb)
use = portage.settings['PORTAGE_USE'].split()
use_expand_hidden = portage.settings["USE_EXPAND_HIDDEN"].split()
- usemask = list(PORTDB.settings.usemask)
- useforce = list(PORTDB.settings.useforce)
+ usemask = list(portage.db[portage.root]["porttree"].dbapi.settings.usemask)
+ useforce = list(portage.db[portage.root]["porttree"].dbapi.settings.useforce)
except KeyError:
- PORTDB.settings.reset()
- PORTDB.settings.lock()
+ portage.db[portage.root]["porttree"].dbapi.settings.reset()
+ portage.db[portage.root]["porttree"].dbapi.settings.lock()
return [], [], [], []
# reset cpv filter
- PORTDB.settings.reset()
- PORTDB.settings.lock()
+ portage.db[portage.root]["porttree"].dbapi.settings.reset()
+ portage.db[portage.root]["porttree"].dbapi.settings.lock()
return use, use_expand_hidden, usemask, useforce
diff --git a/pym/gentoolkit/helpers.py b/pym/gentoolkit/helpers.py
index a0b29ab..e7a27ab 100644
--- a/pym/gentoolkit/helpers.py
+++ b/pym/gentoolkit/helpers.py
@@ -32,11 +32,12 @@ import codecs
from functools import partial
from itertools import chain
+import portage
+
from gentoolkit import pprinter as pp
from gentoolkit import errors
from gentoolkit.atom import Atom
from gentoolkit.cpv import CPV
-from gentoolkit.dbapi import BINDB, PORTDB, VARDB
from gentoolkit.versionmatch import VersionMatch
# This has to be imported below to stop circular import.
#from gentoolkit.package import Package
@@ -387,11 +388,11 @@ def get_cpvs(predicate=None, include_installed=True):
"""
if predicate:
- all_cps = iter(x for x in PORTDB.cp_all() if predicate(x))
+ all_cps = iter(x for x in portage.db[portage.root]["porttree"].dbapi.cp_all() if predicate(x))
else:
- all_cps = PORTDB.cp_all()
+ all_cps = portage.db[portage.root]["porttree"].dbapi.cp_all()
- all_cpvs = chain.from_iterable(PORTDB.cp_list(x) for x in all_cps)
+ all_cpvs = chain.from_iterable(portage.db[portage.root]["porttree"].dbapi.cp_list(x) for x in all_cps)
all_installed_cpvs = set(get_installed_cpvs(predicate))
if include_installed:
@@ -423,11 +424,11 @@ def get_installed_cpvs(predicate=None):
"""
if predicate:
- installed_cps = iter(x for x in VARDB.cp_all() if predicate(x))
+ installed_cps = iter(x for x in portage.db[portage.root]["vartree"].dbapi.cp_all() if predicate(x))
else:
- installed_cps = VARDB.cp_all()
+ installed_cps = portage.db[portage.root]["vartree"].dbapi.cp_all()
- for cpv in chain.from_iterable(VARDB.cp_list(x) for x in installed_cps):
+ for cpv in chain.from_iterable(portage.db[portage.root]["vartree"].dbapi.cp_list(x) for x in installed_cps):
yield cpv
@@ -442,11 +443,11 @@ def get_bintree_cpvs(predicate=None):
"""
if predicate:
- installed_cps = iter(x for x in BINDB.cp_all() if predicate(x))
+ installed_cps = iter(x for x in portage.db[portage.root]["bintree"].dbapi.cp_all() if predicate(x))
else:
- installed_cps = BINDB.cp_all()
+ installed_cps = portage.db[portage.root]["bintree"].dbapi.cp_all()
- for cpv in chain.from_iterable(BINDB.cp_list(x) for x in installed_cps):
+ for cpv in chain.from_iterable(portage.db[portage.root]["bintree"].dbapi.cp_list(x) for x in installed_cps):
yield cpv
diff --git a/pym/gentoolkit/package.py b/pym/gentoolkit/package.py
index cbb7131..f066783 100644
--- a/pym/gentoolkit/package.py
+++ b/pym/gentoolkit/package.py
@@ -37,7 +37,7 @@ __all__ = (
FORMAT_TMPL_VARS = (
'$location', '$mask', '$mask2', '$cp', '$cpv', '$category', '$name',
'$version', '$revision', '$fullversion', '$slot', '$repo', '$keywords'
-)
+)
# =======
# Imports
@@ -52,7 +52,6 @@ from portage.util import LazyItemsDict
import gentoolkit.pprinter as pp
from gentoolkit import errors
from gentoolkit.cpv import CPV
-from gentoolkit.dbapi import PORTDB, VARDB
from gentoolkit.keyword import determine_keyword
from gentoolkit.flag import get_flags
from gentoolkit.eprefix import EPREFIX
@@ -199,23 +198,23 @@ class Package(CPV):
envvars = (envvars,)
if prefer_vdb:
try:
- result = VARDB.aux_get(self.cpv, envvars)
+ result = portage.db[portage.root]["vartree"].dbapi.aux_get(self.cpv, envvars)
except KeyError:
try:
if not fallback:
raise KeyError
- result = PORTDB.aux_get(self.cpv, envvars)
+ result = portage.db[portage.root]["porttree"].dbapi.aux_get(self.cpv, envvars)
except KeyError:
err = "aux_get returned unexpected results"
raise errors.GentoolkitFatalError(err)
else:
try:
- result = PORTDB.aux_get(self.cpv, envvars)
+ result = portage.db[portage.root]["porttree"].dbapi.aux_get(self.cpv, envvars)
except KeyError:
try:
if not fallback:
raise KeyError
- result = VARDB.aux_get(self.cpv, envvars)
+ result = portage.db[portage.root]["vartree"].dbapi.aux_get(self.cpv, envvars)
except KeyError:
err = "aux_get returned unexpected results"
raise errors.GentoolkitFatalError(err)
@@ -227,7 +226,7 @@ class Package(CPV):
def exists(self):
"""Return True if package exists in the Portage tree, else False"""
- return bool(PORTDB.cpv_exists(self.cpv))
+ return bool(portage.db[portage.root]["porttree"].dbapi.cpv_exists(self.cpv))
def settings(self, key):
"""Returns the value of the given key for this package (useful
@@ -258,7 +257,7 @@ class Package(CPV):
try:
result = portage.getmaskingstatus(self.cpv,
settings=self._settings,
- portdb=PORTDB)
+ portdb=portage.db[portage.root]["porttree"].dbapi)
except KeyError:
# getmaskingstatus doesn't support packages without ebuilds in the
# Portage tree.
@@ -277,7 +276,7 @@ class Package(CPV):
try:
result = portage.getmaskingreason(self.cpv,
settings=self._settings,
- portdb=PORTDB,
+ portdb=portage.db[portage.root]["porttree"].dbapi,
return_location=True)
if result is None:
result = tuple()
@@ -299,8 +298,8 @@ class Package(CPV):
"""
if in_vartree:
- return VARDB.findname(self.cpv)
- return PORTDB.findname(self.cpv)
+ return portage.db[portage.root]["vartree"].dbapi.findname(self.cpv)
+ return portage.db[portage.root]["porttree"].dbapi.findname(self.cpv)
def package_path(self, in_vartree=False):
"""Return the path to where the ebuilds and other files reside."""
@@ -387,7 +386,7 @@ class Package(CPV):
def is_overlay(self):
"""Returns True if the package is in an overlay."""
- ebuild, tree = PORTDB.findname2(self.cpv)
+ ebuild, tree = portage.db[portage.root]["porttree"].dbapi.findname2(self.cpv)
if not ebuild:
return None
if self._portdir_path is None:
@@ -400,7 +399,7 @@ class Package(CPV):
@note: We blindly assume that the package actually exists on disk.
"""
- unmasked = PORTDB.xmatch("match-visible", self.cpv)
+ unmasked = portage.db[portage.root]["porttree"].dbapi.xmatch("match-visible", self.cpv)
return self.cpv not in unmasked
diff --git a/pym/gentoolkit/query.py b/pym/gentoolkit/query.py
index 9ad9017..cd8efcc 100644
--- a/pym/gentoolkit/query.py
+++ b/pym/gentoolkit/query.py
@@ -29,7 +29,6 @@ from gentoolkit import helpers
from gentoolkit import pprinter as pp
from gentoolkit.atom import Atom
from gentoolkit.cpv import CPV
-from gentoolkit.dbapi import PORTDB, VARDB
from gentoolkit.package import Package
from gentoolkit.sets import get_set_atoms, SETPREFIX
@@ -189,11 +188,11 @@ class Query(CPV):
try:
if include_masked:
- matches = PORTDB.xmatch("match-all", self.query)
+ matches = portage.db[portage.root]["porttree"].dbapi.xmatch("match-all", self.query)
else:
- matches = PORTDB.match(self.query)
+ matches = portage.db[portage.root]["porttree"].dbapi.match(self.query)
if in_installed:
- matches.extend(VARDB.match(self.query))
+ matches.extend(portage.db[portage.root]["vartree"].dbapi.match(self.query))
except portage.exception.InvalidAtom as err:
message = "query.py: find(), query=%s, InvalidAtom=%s" %(
self.query, str(err))
@@ -205,12 +204,12 @@ class Query(CPV):
"""Return a list of Package objects that matched the search key."""
try:
- matches = VARDB.match(self.query)
+ matches = portage.db[portage.root]["vartree"].dbapi.match(self.query)
# catch the ambiguous package Exception
except portage.exception.AmbiguousPackageName as err:
matches = []
for pkgkey in err.args[0]:
- matches.extend(VARDB.match(pkgkey))
+ matches.extend(portage.db[portage.root]["vartree"].dbapi.match(pkgkey))
except portage.exception.InvalidAtom as err:
raise errors.GentoolkitInvalidAtom(err)
@@ -231,7 +230,7 @@ class Query(CPV):
best = keyworded = masked = None
try:
- best = PORTDB.xmatch("bestmatch-visible", self.query)
+ best = portage.db[portage.root]["porttree"].dbapi.xmatch("bestmatch-visible", self.query)
except portage.exception.InvalidAtom as err:
message = "query.py: find_best(), bestmatch-visible, " + \
"query=%s, InvalidAtom=%s" %(self.query, str(err))
@@ -241,7 +240,7 @@ class Query(CPV):
if not (include_keyworded or include_masked):
return None
try:
- matches = PORTDB.xmatch("match-all", self.query)
+ matches = portage.db[portage.root]["porttree"].dbapi.xmatch("match-all", self.query)
except portage.exception.InvalidAtom as err:
message = "query.py: find_best(), match-all, query=%s, InvalidAtom=%s" %(
self.query, str(err))
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-08-01 3:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-29 2:40 [gentoo-commits] proj/gentoolkit:gentoolkit commit in: pym/gentoolkit/, pym/gentoolkit/enalyze/ Brian Dolbec
-- strict thread matches above, loose matches on Subject: below --
2012-08-01 3:26 Brian Dolbec
2012-06-07 7:59 Brian Dolbec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox