r172 - branches/rewrite/src

Otavio Salvador partial-mirror-devel@lists.alioth.debian.org
Thu, 22 Jul 2004 16:55:12 -0600


Author: otavio
Date: Thu Jul 22 16:55:11 2004
New Revision: 172

Added:
   branches/rewrite/src/PackageList.py   (contents, props changed)
Log:
Initial draft.

Added: branches/rewrite/src/PackageList.py
==============================================================================
--- (empty file)
+++ branches/rewrite/src/PackageList.py	Thu Jul 22 16:55:11 2004
@@ -0,0 +1,54 @@
+# debpartial-mirror - partial debian mirror package tool
+# (c) 2004 Otavio Salvador <otavio@debian.org>, Nat Budin <natb@brandeis.edu>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# $Id$
+
+from apt_pkg.cache import Package
+
+class PackageAlreadyIncluded(Exception):
+    """
+    Exception called when someone try to add a package but this was already included.
+
+    Attributes:
+        package -- The name of package.
+    """
+    def __init__(self, package):
+        self.package = package
+
+class PackageDoesntExist(Exception):
+    """
+    Exception called when someone try to remove a package but this doesn't exist.
+
+    Attributes:
+        package -- The name of package.
+    """
+    def __init__(self, package):
+        self.package = package
+
+class PackageList:
+    _list = []
+
+    def add(self, package):
+        if self._list.has_key(package.Name):
+            raise PackageAlreadyIncluded(package.Name)
+
+        self._list[package.Name] = package
+
+    def remove(self, package):
+        if not self._list.has_key(package.Name):
+            raise PackageDoesntExist(package.Name)
+
+        del self._list[package.Name]