r222 - in branches/rewrite: src tests
Marco Presi
partial-mirror-devel@lists.alioth.debian.org
Mon, 20 Sep 2004 11:23:52 -0600
Author: zufus
Date: Mon Sep 20 11:23:50 2004
New Revision: 222
Added:
branches/rewrite/src/Dists.py
branches/rewrite/tests/dists.py
Log:
Added Dists class.
Todo: add errors to catch, get Otavio's approval!
Added: branches/rewrite/src/Dists.py
==============================================================================
--- (empty file)
+++ branches/rewrite/src/Dists.py Mon Sep 20 11:23:50 2004
@@ -0,0 +1,87 @@
+# 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
+
+
+
+
+import os
+
+
+class Dists:
+ """
+ This class provides methods to create dists dir into the partial-mirror
+ """
+
+ _errors = [13]
+ _ready = True
+
+ def __init__(self, backend, mirror_dir = "/var/cache/debpartial-mirror/"):
+ self.dir = mirror_dir + backend
+ self.dist = os.path.join(self.dir, "dists")
+ self.pool = os.path.join(self.dir, "pool")
+ self._dirs = [self.dir,
+ self.dist,
+ self.pool]
+
+ if not os.path.exists(mirror_dir):
+ print "Warning! %s does not exists!!" % mirror_dir
+ self._ready = False
+
+ def _check(self, path):
+ """ Check if directories for this backend are already created """
+ if not os.path.exists (path):
+ return False
+
+ def check (self):
+ """ Check backend structure """
+ for directory in self._1dirs:
+ if not self._check(directory):
+ print "Dir %s not found" % directory
+
+
+ def _create(self, path):
+ """ Create dir """
+ print "Attempt to create %s" % path
+ try:
+ os.mkdir (path)
+ return "ok"
+ except OSError, (errno,strerror):
+ if errno in self._errors:
+ return strerror
+
+ def create(self):
+ """ Create backend dir struct """
+ if not self._ready:
+ return
+
+ for directory in self._dirs:
+ ret = self._create(directory)
+ if not ret=="ok":
+ print ret
+
+
+ def remove(self):
+ """ Remove backend """
+ self._dirs.reverse()
+ for directory in self._dirs:
+ if not self._check(directory):
+ try:
+ print "Removing %s" % directory
+ os.rmdir(directory)
+ except OSError, (errno, strerror):
+ print strerror
+ self._dirs.reverse()
Added: branches/rewrite/tests/dists.py
==============================================================================
--- (empty file)
+++ branches/rewrite/tests/dists.py Mon Sep 20 11:23:50 2004
@@ -0,0 +1,9 @@
+from sys import path, stdout
+path.append("../src/")
+
+from Dists import *
+
+d = Dists("sarge")
+d.create()
+
+d.remove()