[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] add some useful comparison operators



Signed-off-by: Mark Hymers <mhy@debian.org>
---
 daklib/dbconn.py |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/daklib/dbconn.py b/daklib/dbconn.py
index 7d46076..b993d43 100755
--- a/daklib/dbconn.py
+++ b/daklib/dbconn.py
@@ -59,6 +59,18 @@ class Architecture(object):
     def __init__(self, *args, **kwargs):
         pass
 
+    def __eq__(self, val):
+        if isinstance(val, str):
+            return (self.arch_string== val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
+    def __ne__(self, val):
+        if isinstance(val, str):
+            return (self.arch_string != val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
     def __repr__(self):
         return '<Architecture %s>' % self.arch_string
 
@@ -315,6 +327,18 @@ class Component(object):
     def __init__(self, *args, **kwargs):
         pass
 
+    def __eq__(self, val):
+        if isinstance(val, str):
+            return (self.component_name == val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
+    def __ne__(self, val):
+        if isinstance(val, str):
+            return (self.component_name != val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
     def __repr__(self):
         return '<Component %s>' % self.component_name
 
@@ -977,6 +1001,18 @@ class Priority(object):
     def __init__(self, *args, **kwargs):
         pass
 
+    def __eq__(self, val):
+        if isinstance(val, str):
+            return (self.priority == val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
+    def __ne__(self, val):
+        if isinstance(val, str):
+            return (self.priority != val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
     def __repr__(self):
         return '<Priority %s (%s)>' % (self.priority, self.priority_id)
 
@@ -1196,6 +1232,18 @@ class Section(object):
     def __init__(self, *args, **kwargs):
         pass
 
+    def __eq__(self, val):
+        if isinstance(val, str):
+            return (self.section == val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
+    def __ne__(self, val):
+        if isinstance(val, str):
+            return (self.section != val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
     def __repr__(self):
         return '<Section %s>' % self.section
 
@@ -1440,6 +1488,18 @@ class Suite(object):
     def __repr__(self):
         return '<Suite %s>' % self.suite_name
 
+    def __eq__(self, val):
+        if isinstance(val, str):
+            return (self.suite_name == val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
+    def __ne__(self, val):
+        if isinstance(val, str):
+            return (self.suite_name != val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
     def details(self):
         ret = []
         for disp, field in SUITE_FIELDS:
@@ -1561,6 +1621,18 @@ class Uid(object):
     def __init__(self, *args, **kwargs):
         pass
 
+    def __eq__(self, val):
+        if isinstance(val, str):
+            return (self.uid == val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
+    def __ne__(self, val):
+        if isinstance(val, str):
+            return (self.uid != val)
+        # This signals to use the normal comparison operator
+        return NotImplemented
+
     def __repr__(self):
         return '<Uid %s (%s)>' % (self.uid, self.name)
 
-- 
1.5.6.5



Reply to: