replace all use of dbapi's PORTDB, VARDB, BINDB assigned variables with the actuall...
authorBrian Dolbec <dolsen@gentoo.org>
Wed, 1 Aug 2012 03:23:14 +0000 (20:23 -0700)
committerBrian Dolbec <dolsen@gentoo.org>
Wed, 1 Aug 2012 03:24:58 +0000 (20:24 -0700)
pym/gentoolkit/dependencies.py
pym/gentoolkit/enalyze/analyze.py
pym/gentoolkit/enalyze/lib.py
pym/gentoolkit/enalyze/rebuild.py
pym/gentoolkit/flag.py
pym/gentoolkit/helpers.py
pym/gentoolkit/package.py
pym/gentoolkit/query.py

index 039695227c52e67e53d0182fd597e332c5a2c992..84e3672ec51cdfaf123d882f945c3405ba1a215f 100644 (file)
@@ -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
index 2ba028f282f0227e7686d6b2dc238f186bb22b23..70334221327d29f2cdd9aa0994e9d2620ce90334 100644 (file)
@@ -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()
index 9dc28a35f5b4dc151e51c48e238519f37e26a5e3..de306f015332ed9acc2fb6a5ad3722176ef49085 100644 (file)
@@ -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
 
index d0e181331996cf31f2b0e2cb38acb7a9dc5d30a1..cd1a08a4b7d5c0b195d929cf1ef268dfb1e4a3bd 100644 (file)
@@ -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,
index 0377a813f64ecfc1ffc5319636a090de92739052..9983ba7f6a42bab3eda424cd16e88c0bf151765a 100644 (file)
@@ -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
 
 
index a0b29abdd9f5f37ed713a137e91c677c3e721317..e7a27ab5a5fc0554ba9d8b2bf8b1607aedecefc7 100644 (file)
@@ -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
 
 
index cbb7131842b367ff464896fe73fedb74a282a611..f066783c2429b92f1d71395b3e20a9132a3d2507 100644 (file)
@@ -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
 
 
index 9ad9017a0ab881128da1b3f622f9c6b21720e090..cd8efcc9f36d1fc8e2c30f031a09053c3762f96c 100644 (file)
@@ -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))