r189 - branches/rewrite/src

Otavio Salvador partial-mirror-devel@lists.alioth.debian.org
Thu, 22 Jul 2004 21:17:04 -0600


Author: otavio
Date: Thu Jul 22 21:17:04 2004
New Revision: 189

Modified:
   branches/rewrite/src/PackageList.py
Log:
First version of filter method.

Modified: branches/rewrite/src/PackageList.py
==============================================================================
--- branches/rewrite/src/PackageList.py	(original)
+++ branches/rewrite/src/PackageList.py	Thu Jul 22 21:17:04 2004
@@ -16,6 +16,8 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 # $Id$
 
+import re
+
 class PackageAlreadyExists(Exception):
     """
     Exception called when someone try to add a package but this was already included.
@@ -71,3 +73,19 @@
         del self._name[package['Package']]
         self._subsection[package['Section']].remove(package)
         self._priority[package['Priority']].remove(package)
+
+    def filter(self, condition):
+        packages = []
+        
+        for (item, value) in condition:
+            if item is "subsection":
+                d = self._subsection
+            elif item is "priority":
+                d = self._priority
+            else:
+                d = self._name
+
+            regexp = re.compile(value)
+            for k in d.keys():
+                if regexp.match(k):
+                    packages.append(d[k])