Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
commit b3b0ba82790bc7805a4804037c57983c44faa629 Author: Peter Hatina phatina@redhat.com Date: Thu Nov 7 10:53:56 2013 +0100
introduce LMIInstance(Name) comparision logic
cli/lmi/shell/LMIInstance.py | 14 ++++++++++++++ cli/lmi/shell/LMIInstanceName.py | 9 +++++++++ 2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/cli/lmi/shell/LMIInstance.py b/cli/lmi/shell/LMIInstance.py index 126d438..17ca570 100644 --- a/cli/lmi/shell/LMIInstance.py +++ b/cli/lmi/shell/LMIInstance.py @@ -50,6 +50,20 @@ class LMIInstance(LMIWrapperBaseObject): self.__dict__["_lmi_class"] = lmi_class super(LMIInstance, self).__init__(conn)
+ def __cmp__(self, other): + """ + :param LMIInstance other: :py:class:`LMIInstance` object to compare + :returns: If both instances are (not) deleted: negative number, if self < other; 0 + if self == other or positive number, if self > other. If the first or second + instance is deleted, -1 or 1 is returned. + :rtype: int + """ + if self._deleted and not other._deleted: + return -1 + elif not self._deleted and other._deleted: + return 1 + return cmp(self._cim_instance, other._cim_instance) + @lmi_possibly_deleted(False) def __contains__(self, key): """ diff --git a/cli/lmi/shell/LMIInstanceName.py b/cli/lmi/shell/LMIInstanceName.py index 254ddc2..08f8eb7 100644 --- a/cli/lmi/shell/LMIInstanceName.py +++ b/cli/lmi/shell/LMIInstanceName.py @@ -33,6 +33,15 @@ class LMIInstanceName(LMIWrapperBaseObject): cim_instance_name = cim_instance_name.wrapped_object self._cim_instance_name = cim_instance_name
+ def __cmp__(self, other): + """ + :param LMIInstanceName other: :py:class:`LMIInstanceName` object to compare + :returns: negative number, if self < other; 0 if self == other or positive + number, if self > other + :rtype: int + """ + return cmp(self._cim_instance_name, other._cim_instance_name) + def __contains__(self, key): """ :param string key: key name, which will be tested for presence in keybindings
cura-tools-devel@lists.fedorahosted.org