Make the Package class emulate the interface of it's own
authorZac Medico <zmedico@gentoo.org>
Mon, 12 Nov 2007 03:34:22 +0000 (03:34 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 12 Nov 2007 03:34:22 +0000 (03:34 -0000)
digraph_node tuple so that the Package instance itself
can be added directly to the digraph.

svn path=/main/trunk/; revision=8492

pym/_emerge/__init__.py
pym/portage/__init__.py

index 5c3f20c776b9e3cb93d19b947ea5b16cd6bb21b5..e1df8a3fbe3c5fe621de35920c411f3166b9fb6c 100644 (file)
@@ -915,7 +915,9 @@ def iter_atoms(deps):
 class Package(object):
        __slots__ = ("__weakref__", "built", "cpv", "depth",
                "installed", "metadata", "root", "onlydeps", "type_name",
-               "_digraph_node", "_slot_atom")
+               "slot_atom",
+               "digraph_node", "__eq__", "__hash__", "__str__",
+               "__len__", "__getitem__", "__iter__", "__contains__")
        def __init__(self, **kwargs):
                for myattr in self.__slots__:
                        if myattr == "__weakref__":
@@ -923,21 +925,21 @@ class Package(object):
                        myvalue = kwargs.get(myattr, None)
                        setattr(self, myattr, myvalue)
 
-       @property
-       def slot_atom(self):
-               if self._slot_atom is None:
-                       self._slot_atom = "%s:%s" % \
-                               (portage.cpv_getkey(self.cpv), self.metadata["SLOT"])
-               return self._slot_atom
-
-       @property
-       def digraph_node(self):
-               if self._digraph_node is None:
-                       status = "merge"
-                       if self.onlydeps or self.installed:
-                               status = "nomerge"
-                       self._digraph_node = (self.type_name, self.root, self.cpv, status)
-               return self._digraph_node
+               self.slot_atom = "%s:%s" % \
+                       (portage.cpv_getkey(self.cpv), self.metadata["SLOT"])
+
+               status = "merge"
+               if self.onlydeps or self.installed:
+                       status = "nomerge"
+               node = (self.type_name, self.root, self.cpv, status)
+               self.digraph_node = node
+               self.__eq__       = node.__eq__
+               self.__hash__     = node.__hash__
+               self.__str__      = node.__str__
+               self.__len__      = node.__len__
+               self.__getitem__  = node.__getitem__
+               self.__iter__     = node.__iter__
+               self.__contains__ = node.__contains__
 
 class DependencyArg(object):
        def __init__(self, arg=None, root_config=None):
@@ -1391,8 +1393,6 @@ class depgraph(object):
 
        def _add_pkg(self, pkg, myparent=None,
                priority=None, arg=None, depth=0):
-               if myparent is not None:
-                       myparent = myparent.digraph_node
                """
                Fills the digraph with nodes comprised of packages to merge.
                mybigkey is the package spec of the package to merge.
index 40814d4b84aad1e908fbb6c45254b54a3adcbad1..6c368365e699e4a5d0f065c90e5a7c51812e22a3 100644 (file)
@@ -451,7 +451,9 @@ class digraph(object):
 
        def clone(self):
                clone = digraph()
-               clone.nodes = copy.deepcopy(self.nodes)
+               clone.nodes = {}
+               for k, v in self.nodes.iteritems():
+                       clone.nodes[k] = (v[0].copy(), v[1].copy())
                clone.order = self.order[:]
                return clone