r223 - branches/rewrite/src
Marco Presi
partial-mirror-devel@lists.alioth.debian.org
Mon, 20 Sep 2004 17:43:08 -0600
Author: zufus
Date: Mon Sep 20 17:43:08 2004
New Revision: 223
Added:
branches/rewrite/src/Backends.py
Modified:
branches/rewrite/src/Dists.py
Log:
Reading HACKING I convinced myself that previous commit is much more
like Backends.py class.#
Added: branches/rewrite/src/Backends.py
==============================================================================
--- (empty file)
+++ branches/rewrite/src/Backends.py Mon Sep 20 17:43:08 2004
@@ -0,0 +1,88 @@
+# 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 Backends:
+ """
+ This class provides methods to create backendss dirs 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()
Modified: branches/rewrite/src/Dists.py
==============================================================================
--- branches/rewrite/src/Dists.py (original)
+++ branches/rewrite/src/Dists.py Mon Sep 20 17:43:08 2004
@@ -16,14 +16,12 @@
# 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
+ This class provides methods to create backendss dirs into the
+ partial-mirror
"""
_errors = [13]