summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlec Warner <antarus@gentoo.org>2007-07-23 07:21:31 +0000
committerAlec Warner <antarus@gentoo.org>2007-07-23 07:21:31 +0000
commit35f99427b08e8b6de7d039ea2d48a6bd75252ef5 (patch)
treee5ca8eb65b9ee1467c0ac92b55444ffff94fb613
parent29b10eda9289ce8057de38186fb3b8a141eeeb1b (diff)
downloadportage-35f99427b08e8b6de7d039ea2d48a6bd75252ef5.tar.gz
portage-35f99427b08e8b6de7d039ea2d48a6bd75252ef5.tar.bz2
portage-35f99427b08e8b6de7d039ea2d48a6bd75252ef5.zip
Move classes out of __init__.py, they do not belong there. Fix import style, and import statements broken by class moves.
svn path=/main/trunk/; revision=7366
-rw-r--r--pym/portage/sets/__init__.py158
-rw-r--r--pym/portage/sets/dbapi.py156
-rw-r--r--pym/portage/sets/profiles.py3
-rw-r--r--pym/portage/sets/security.py5
-rw-r--r--pym/portage/sets/shell.py2
5 files changed, 161 insertions, 163 deletions
diff --git a/pym/portage/sets/__init__.py b/pym/portage/sets/__init__.py
index 0f4eca16a..96c4be8a5 100644
--- a/pym/portage/sets/__init__.py
+++ b/pym/portage/sets/__init__.py
@@ -4,173 +4,18 @@
import os
-from portage.const import PRIVATE_PATH, USER_CONFIG_PATH
-from portage.exception import InvalidAtom
-from portage.dep import isvalidatom, match_from_list, best_match_to_list, dep_getkey, use_reduce, paren_reduce
-from portage import flatten
-
OPERATIONS = ["merge", "unmerge"]
DEFAULT_SETS = ["world", "system", "everything", "security"] \
+["package_"+x for x in ["mask", "unmask", "use", "keywords"]]
del x
-class PackageSet(object):
- # Set this to operations that are supported by your subclass. While
- # technically there is no difference between "merge" and "unmerge" regarding
- # package sets, the latter doesn't make sense for some sets like "system"
- # or "security" and therefore isn't supported by them.
- _operations = ["merge"]
- _atommap = {}
- description = "generic package set"
-
- def __init__(self, name):
- self.name = name
- self._atoms = set()
- self._atommap = {}
- self._loaded = False
- self._loading = False
-
- def __contains__(self, atom):
- return atom in self.getAtoms()
-
- def __iter__(self):
- for x in self.getAtoms():
- yield x
-
- def supportsOperation(self, op):
- if not op in OPERATIONS:
- raise ValueError(op)
- return op in self._operations
-
- def getAtoms(self):
- if not (self._loaded or self._loading):
- self._loading = True
- self.load()
- self._loaded = True
- self._loading = False
- return self._atoms
-
- def _setAtoms(self, atoms):
- atoms = map(str.strip, atoms)
- for a in atoms[:]:
- if a == "":
- atoms.remove(a)
- elif not isvalidatom(a):
- raise InvalidAtom(a)
- self._atoms = set(atoms)
- self._updateAtomMap()
-
- def load(self):
- # This method must be overwritten by subclasses
- # Editable sets should use the value of self._mtime to determine if they
- # need to reload themselves
- raise NotImplementedError()
-
- def containsCPV(self, cpv):
- for a in self.getAtoms():
- if match_from_list(a, [cpv]):
- return True
- return False
-
- def getMetadata(self, key):
- if hasattr(self, key.lower()):
- return getattr(self, key.lower())
- else:
- return ""
-
- def _updateAtomMap(self, atoms=None):
- """Update self._atommap for specific atoms or all atoms."""
- if not atoms:
- self._atommap.clear()
- atoms = self._atoms
- for a in atoms:
- cp = dep_getkey(a)
- self._atommap.setdefault(cp, set())
- self._atommap[cp].add(a)
-
- # Not sure if this one should really be in PackageSet
- def findAtomForPackage(self, cpv, metadata):
- """Return the best match for a given package from the arguments, or
- None if there are no matches. This matches virtual arguments against
- the PROVIDE metadata. This can raise an InvalidDependString exception
- if an error occurs while parsing PROVIDE."""
- cpv_slot = "%s:%s" % (cpv, metadata["SLOT"])
- cp = dep_getkey(cpv)
- self.getAtoms() # make sure the atoms are loaded
- atoms = self._atommap.get(cp)
- if atoms:
- best_match = best_match_to_list(cpv_slot, atoms)
- if best_match:
- return best_match
- if not metadata["PROVIDE"]:
- return None
- provides = flatten(use_reduce(paren_reduce(metadata["PROVIDE"]),
- uselist=metadata["USE"].split()))
- for provide in provides:
- provided_cp = dep_getkey(provide)
- atoms = self._atommap.get(provided_cp)
- if atoms:
- atoms = list(atoms)
- transformed_atoms = [atom.replace(provided_cp, cp) for atom in atoms]
- best_match = best_match_to_list(cpv_slot, transformed_atoms)
- if best_match:
- return atoms[transformed_atoms.index(best_match)]
- return None
-
-class EditablePackageSet(PackageSet):
-
- def update(self, atoms):
- self.getAtoms()
- self._atoms.update(atoms)
- self._updateAtomMap(atoms=atoms)
- self.write()
-
- def add(self, atom):
- self.update([atom])
-
- def replace(self, atoms):
- self._setAtoms(atoms)
- self.write()
-
- def remove(self, atom):
- self.getAtoms()
- self._atoms.discard(atom)
- self._updateAtomMap()
- self.write()
-
- def removePackageAtoms(self, cp):
- for a in list(self.getAtoms()):
- if dep_getkey(a) == cp:
- self.remove(a)
- self.write()
-
- def write(self):
- # This method must be overwritten in subclasses that should be editable
- raise NotImplementedError()
-
-
-class InternalPackageSet(EditablePackageSet):
- def __init__(self, initial_atoms=None):
- super(InternalPackageSet, self).__init__("")
- if initial_atoms != None:
- self.update(initial_atoms)
-
- def clear(self):
- self._atoms.clear()
- self._updateAtomMap()
-
- def load(self):
- pass
-
- def write(self):
- pass
-
def make_default_sets(configroot, root, profile_paths, settings=None,
vdbapi=None, portdbapi=None):
from portage.sets.files import StaticFileSet, ConfigFileSet
from portage.sets.profiles import PackagesSystemSet
from portage.sets.security import NewAffectedSet
from portage.sets.dbapi import EverythingSet
+ from portage.const import PRIVATE_PATH, USER_CONFIG_PATH
rValue = set()
worldset = StaticFileSet("world", os.path.join(root, PRIVATE_PATH, "world"))
@@ -194,6 +39,7 @@ def make_default_sets(configroot, root, profile_paths, settings=None,
def make_extra_static_sets(configroot):
from portage.sets.files import StaticFileSet
+ from portage.const import PRIVATE_PATH, USER_CONFIG_PATH
rValue = set()
mydir = os.path.join(configroot, USER_CONFIG_PATH.lstrip(os.sep), "sets")
diff --git a/pym/portage/sets/dbapi.py b/pym/portage/sets/dbapi.py
index 1b2520ef6..13c0fd530 100644
--- a/pym/portage/sets/dbapi.py
+++ b/pym/portage/sets/dbapi.py
@@ -3,8 +3,162 @@
# $Id$
from portage.versions import catsplit
+from portage import flatten
+from portage.dep import isvalidatom, match_from_list, \
+ best_match_to_list, dep_getkey, use_reduce, paren_reduce
+from portage.exception import InvalidAtom
+from portage.sets import OPERATIONS
-from portage.sets import PackageSet
+class PackageSet(object):
+ # Set this to operations that are supported by your subclass. While
+ # technically there is no difference between "merge" and "unmerge" regarding
+ # package sets, the latter doesn't make sense for some sets like "system"
+ # or "security" and therefore isn't supported by them.
+ _operations = ["merge"]
+ _atommap = {}
+ description = "generic package set"
+
+ def __init__(self, name):
+ self.name = name
+ self._atoms = set()
+ self._atommap = {}
+ self._loaded = False
+ self._loading = False
+
+ def __contains__(self, atom):
+ return atom in self.getAtoms()
+
+ def __iter__(self):
+ for x in self.getAtoms():
+ yield x
+
+ def supportsOperation(self, op):
+ if not op in OPERATIONS:
+ raise ValueError(op)
+ return op in self._operations
+
+ def getAtoms(self):
+ if not (self._loaded or self._loading):
+ self._loading = True
+ self.load()
+ self._loaded = True
+ self._loading = False
+ return self._atoms
+
+ def _setAtoms(self, atoms):
+ atoms = map(str.strip, atoms)
+ for a in atoms[:]:
+ if a == "":
+ atoms.remove(a)
+ elif not isvalidatom(a):
+ raise InvalidAtom(a)
+ self._atoms = set(atoms)
+ self._updateAtomMap()
+
+ def load(self):
+ # This method must be overwritten by subclasses
+ # Editable sets should use the value of self._mtime to determine if they
+ # need to reload themselves
+ raise NotImplementedError()
+
+ def containsCPV(self, cpv):
+ for a in self.getAtoms():
+ if match_from_list(a, [cpv]):
+ return True
+ return False
+
+ def getMetadata(self, key):
+ if hasattr(self, key.lower()):
+ return getattr(self, key.lower())
+ else:
+ return ""
+
+ def _updateAtomMap(self, atoms=None):
+ """Update self._atommap for specific atoms or all atoms."""
+ if not atoms:
+ self._atommap.clear()
+ atoms = self._atoms
+ for a in atoms:
+ cp = dep_getkey(a)
+ self._atommap.setdefault(cp, set())
+ self._atommap[cp].add(a)
+
+ # Not sure if this one should really be in PackageSet
+ def findAtomForPackage(self, cpv, metadata):
+ """Return the best match for a given package from the arguments, or
+ None if there are no matches. This matches virtual arguments against
+ the PROVIDE metadata. This can raise an InvalidDependString exception
+ if an error occurs while parsing PROVIDE."""
+ cpv_slot = "%s:%s" % (cpv, metadata["SLOT"])
+ cp = dep_getkey(cpv)
+ self.getAtoms() # make sure the atoms are loaded
+ atoms = self._atommap.get(cp)
+ if atoms:
+ best_match = best_match_to_list(cpv_slot, atoms)
+ if best_match:
+ return best_match
+ if not metadata["PROVIDE"]:
+ return None
+ provides = flatten(use_reduce(paren_reduce(metadata["PROVIDE"]),
+ uselist=metadata["USE"].split()))
+ for provide in provides:
+ provided_cp = dep_getkey(provide)
+ atoms = self._atommap.get(provided_cp)
+ if atoms:
+ atoms = list(atoms)
+ transformed_atoms = [atom.replace(provided_cp, cp) for atom in atoms]
+ best_match = best_match_to_list(cpv_slot, transformed_atoms)
+ if best_match:
+ return atoms[transformed_atoms.index(best_match)]
+ return None
+
+class EditablePackageSet(PackageSet):
+
+ def update(self, atoms):
+ self.getAtoms()
+ self._atoms.update(atoms)
+ self._updateAtomMap(atoms=atoms)
+ self.write()
+
+ def add(self, atom):
+ self.update([atom])
+
+ def replace(self, atoms):
+ self._setAtoms(atoms)
+ self.write()
+
+ def remove(self, atom):
+ self.getAtoms()
+ self._atoms.discard(atom)
+ self._updateAtomMap()
+ self.write()
+
+ def removePackageAtoms(self, cp):
+ for a in list(self.getAtoms()):
+ if dep_getkey(a) == cp:
+ self.remove(a)
+ self.write()
+
+ def write(self):
+ # This method must be overwritten in subclasses that should be editable
+ raise NotImplementedError()
+
+
+class InternalPackageSet(EditablePackageSet):
+ def __init__(self, initial_atoms=None):
+ super(InternalPackageSet, self).__init__("")
+ if initial_atoms != None:
+ self.update(initial_atoms)
+
+ def clear(self):
+ self._atoms.clear()
+ self._updateAtomMap()
+
+ def load(self):
+ pass
+
+ def write(self):
+ pass
class EverythingSet(PackageSet):
_operations = ["merge", "unmerge"]
diff --git a/pym/portage/sets/profiles.py b/pym/portage/sets/profiles.py
index 55b7942f5..4e369e5e2 100644
--- a/pym/portage/sets/profiles.py
+++ b/pym/portage/sets/profiles.py
@@ -4,8 +4,7 @@
import os
from portage.util import grabfile_package, stack_lists
-
-from portage.sets import PackageSet
+from portage.sets.dbapi import PackageSet
class PackagesSystemSet(PackageSet):
_operations = ["merge"]
diff --git a/pym/portage/sets/security.py b/pym/portage/sets/security.py
index dffde9c0e..d1efa4df7 100644
--- a/pym/portage/sets/security.py
+++ b/pym/portage/sets/security.py
@@ -2,12 +2,11 @@
# Distributed under the terms of the GNU General Public License v2
# $Id$
+import os
import portage.glsa as glsa
from portage.util import grabfile, write_atomic
from portage.const import CACHE_PATH
-import os
-
-from portage.sets import PackageSet
+from portage.sets.dbapi import PackageSet
class SecuritySet(PackageSet):
_operations = ["merge"]
diff --git a/pym/portage/sets/shell.py b/pym/portage/sets/shell.py
index 6a84918a7..5c316c1e4 100644
--- a/pym/portage/sets/shell.py
+++ b/pym/portage/sets/shell.py
@@ -5,7 +5,7 @@
import subprocess
import os
-from portage.sets import PackageSet
+from portage.sets.dbapi import PackageSet
class CommandOutputSet(PackageSet):
"""This class creates a PackageSet from the output of a shell command.