From: Zac Medico Date: Tue, 22 Apr 2008 23:40:34 +0000 (-0000) Subject: Bug #172812 - Add an Uninstall class derived from the Package class, for X-Git-Tag: v2.2_pre6~133 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=06ad727ea61ba165fc01ba0e61148fe5779050f4;p=portage.git Bug #172812 - Add an Uninstall class derived from the Package class, for packages that may need to be uninstalled to avoid conflicts. svn path=/main/trunk/; revision=9945 --- diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index dfa2def65..7bdc07ca5 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -1201,10 +1201,9 @@ def show_masked_packages(masked_packages): shown_licenses.add(l) return have_eapi_mask -class Package(object): - __slots__ = ("__weakref__", "built", "cpv", "depth", - "installed", "metadata", "root", "onlydeps", "type_name", - "cp", "cpv_slot", "slot_atom", "_digraph_node") +class Task(object): + __slots__ = ("__weakref__", "_hash_key",) + def __init__(self, **kwargs): for myattr in self.__slots__: if myattr == "__weakref__": @@ -1212,14 +1211,56 @@ class Package(object): myvalue = kwargs.get(myattr, None) setattr(self, myattr, myvalue) + def _get_hash_key(self): + try: + return self._hash_key + except AttributeError: + raise NotImplementedError(self) + + def __eq__(self, other): + return self._get_hash_key() == other + + def __ne__(self, other): + return self._get_hash_key() != other + + def __hash__(self): + return hash(self._get_hash_key()) + + def __len__(self): + return len(self._get_hash_key()) + + def __getitem__(self, key): + return self._get_hash_key()[key] + + def __iter__(self): + return iter(self._get_hash_key()) + + def __contains__(self, key): + return key in self._get_hash_key() + + def __str__(self): + return str(self._get_hash_key()) + +class Package(Task): + __slots__ = ("built", "cpv", "depth", + "installed", "metadata", "root", "onlydeps", "type_name", + "cp", "cpv_slot", "slot_atom") + def __init__(self, **kwargs): + Task.__init__(self, **kwargs) self.cp = portage.cpv_getkey(self.cpv) self.slot_atom = "%s:%s" % (self.cp, self.metadata["SLOT"]) self.cpv_slot = "%s:%s" % (self.cpv, self.metadata["SLOT"]) - status = "merge" - if self.onlydeps or self.installed: - status = "nomerge" - self._digraph_node = (self.type_name, self.root, self.cpv, status) + def _get_hash_key(self): + try: + return self._hash_key + except AttributeError: + operation = "merge" + if self.onlydeps or self.installed: + operation = "nomerge" + self._hash_key = \ + (self.type_name, self.root, self.cpv, operation) + return self._hash_key def __lt__(self, other): other_split = portage.catpkgsplit(other.cpv) @@ -1239,22 +1280,14 @@ class Package(object): return True return False - def __eq__(self, other): - return self._digraph_node == other - def __ne__(self, other): - return self._digraph_node != other - def __hash__(self): - return hash(self._digraph_node) - def __len__(self): - return len(self._digraph_node) - def __getitem__(self, key): - return self._digraph_node[key] - def __iter__(self): - return iter(self._digraph_node) - def __contains__(self, key): - return key in self._digraph_node - def __str__(self): - return str(self._digraph_node) +class Uninstall(Package): + def _get_hash_key(self): + try: + return self._hash_key + except AttributeError: + self._hash_key = \ + (self.type_name, self.root, self.cpv, "unmerge") + return self._hash_key class DependencyArg(object): def __init__(self, arg=None, root_config=None):