r267 - in branches/rewrite: . src
Otavio Salvador
partial-mirror-devel@lists.alioth.debian.org
Tue, 09 Nov 2004 14:06:11 -0700
Author: otavio
Date: Tue Nov 9 14:06:10 2004
New Revision: 267
Modified:
branches/rewrite/ (props changed)
branches/rewrite/src/Backend.py
branches/rewrite/src/Config.py
branches/rewrite/src/Dists.py
branches/rewrite/src/Pool.py
branches/rewrite/src/debpartial-mirror.in
Log:
r173@nurf: otavio | 2004-11-09T21:05:34.670127Z
Change the way to pass information to Dists and Pool; Change Backend to use this instead of Dir directly.
Modified: branches/rewrite/src/Backend.py
==============================================================================
--- branches/rewrite/src/Backend.py (original)
+++ branches/rewrite/src/Backend.py Tue Nov 9 14:06:10 2004
@@ -17,8 +17,9 @@
# $Id: DirManagement.py 249 2004-09-25 23:32:39Z zufus $
-import os
-from Dir import *
+from Config import *
+from Dists import *
+from Pool import *
class Backend:
"""
@@ -28,28 +29,30 @@
backends = []
- def __init__(self, backend = "sarge", mirror_dir = "../debpartial-mirror/"):
+ def __init__ (self, name, config):
# Store myself on list
self.backends.append(self)
- self._mirrorDir = Dir (backend, mirror_dir)
- self._distsDir = Dir ("dists", self._mirrorDir.path() )
- self._poolDir = Dir ("pool", self._mirrorDir.path() )
-
- self.dirs = [self._mirrorDir,
- self._distsDir,
- self._poolDir]
+ self._cfg = config
+ self._name = name
+
+ if isinstance(self._cfg.getBackend(self._name), ConfigBackendMirror):
+ self._dists = RemoteDists(self)
+ elif isinstance(self._cfg.getBackend(self._name), ConfigBackendMerge):
+ self._dists = LocalDists(self)
+
+ self._pool = Pool(self)
+
+ def __getitem__ (self, key):
+ return self._cfg.getOption(key, self._name)
def check (self):
""" Check Mirror Status """
- #Dir status
- for i in self.dirs:
- print "%s status: %s" % (i.path(), i.check())
+ # I can only check dists since if Package is updated then my
+ # mirror is
+ return self._dists.check()
def remove (self):
""" Remove backend """
- rmDirs = self.dirs
- rmDirs.reverse()
- for d in rmDirs:
- d.remove()
-
+ self._pool.remove()
+ self._dists.remove()
Modified: branches/rewrite/src/Config.py
==============================================================================
--- branches/rewrite/src/Config.py (original)
+++ branches/rewrite/src/Config.py Tue Nov 9 14:06:10 2004
@@ -254,27 +254,37 @@
self.sectionObjs[section] = sectionObj
self.confs[section] = sectionObj.confs
- def getBackends(self, type):
+ def getBackends(self):
backends = []
for section in self.sectionObjs.values():
- if isinstance(section, type):
+ if not isinstance(section, ConfigGlobal):
backends.append(section)
return backends
-
+
+ def getBackend(self, name):
+ if name in self.sectionObjs:
+ return self.sectionObjs[name]
+ raise InvalidSection(name)
+
+# def getBackends(self, type):
+# backends = []
+
+# for section in self.sectionObjs.values():
+# if isinstance(section, type):
+# backends.append(section)
+# return backends
+
def getOption(self, option, section='GLOBAL'):
# get a config value for a certain section. if it's not
# specified, fall back to GLOBAL
- if not self.confs.has_key(section):
- debug("no config section called [%s]." % (section))
- raise InvalidSection(section)
if self.confs[section].has_key(option):
return self.confs[section][option]
else:
if section != 'GLOBAL':
debug("[%s] is not present in section [%s]. Fallback to global section." % (option, section))
try:
- self.getOption(option, 'GLOBAL')
+ return self.getOption(option, 'GLOBAL')
except InvalidOption, msg:
debug("[%s] is not present in section [%s]." % (option, section))
raise InvalidOption(section, msg.option)
Modified: branches/rewrite/src/Dists.py
==============================================================================
--- branches/rewrite/src/Dists.py (original)
+++ branches/rewrite/src/Dists.py Tue Nov 9 14:06:10 2004
@@ -17,29 +17,17 @@
# $Id$
import os
-
from Dir import *
import Config
-class Dists (Dir):
+class Dists:
"""
- This class provides methods to create dist dirs into the
- partial-mirror
+ This class provides methods to manage dists on partial-mirrors
"""
- def __init__(self, parent, directory = "dists"):
- Dir.__init__ (self, parent, directory)
- self._files = [os.path.join(directory, "Packages.gz"),
- os.path.join(directory, "Sources.gz"),
- os.path.join(directory, "Release")]
-
- self._backend = os.path.split(self._parent)[1]
-
- self._md5sum = {}
- for f in self._files:
- self._md5sum [f] = self.md5_on(f)
-
- self._need_updates = ()
+ def __init__(self, backend):
+ self._backend = backend
+ self._files = []
def _find_updates (self):
""" Determine which files need updates.
@@ -53,10 +41,25 @@
"""
This class provides methods to fill dists dir downloading remote files
"""
- pass
-
+ def __init__(self, backend):
+ Dists.__init__(self, backend)
+ for c in backend["components"]:
+ for d in backend["distributions"]:
+ for a in backend["architectures"]:
+ for f in ["Packages.gz", "Sources.gz", "Release"]:
+ self._files.append("%s/debian/%s/%s/binary-%s/%s" %
+ (backend["server"], d, c, a, f))
+
class LocalDists (Dists):
"""
This class provides methods to fill dists dir downloading local files
"""
- pass
+ def __init__(self, backend):
+ Dists.__init__(self, backend)
+ for c in backend["components"]:
+ for d in backend["distributions"]:
+ for a in backend["architectures"]:
+ for f in ["Packages.gz", "Sources.gz", "Release"]:
+ self._files.append("%s/debian/%s/%s/binary-%s/%s" %
+ (backend["mirror_dir"] + backend["name"], d, c, a, f))
+ print self._files
Modified: branches/rewrite/src/Pool.py
==============================================================================
--- branches/rewrite/src/Pool.py (original)
+++ branches/rewrite/src/Pool.py Tue Nov 9 14:06:10 2004
@@ -27,10 +27,8 @@
partial-mirror
"""
- def __init__(self, parent, directory = "pool"):
- Dir.__init__ (self, parent, directory)
-
- self._backend = os.path.split(self._parent)[1]
+ def __init__(self, backend):
+ self._backend = backend
class RemotePool (Pool):
Modified: branches/rewrite/src/debpartial-mirror.in
==============================================================================
--- branches/rewrite/src/debpartial-mirror.in (original)
+++ branches/rewrite/src/debpartial-mirror.in Tue Nov 9 14:06:10 2004
@@ -19,6 +19,7 @@
# $Id$
from Config import *
+from Backend import *
def version():
print "debpartial-mirror @VERSION@ - Partial mirroring tool for Debian - @DATE@"
@@ -26,7 +27,7 @@
print
def usage():
- print "Usage: debpartial-mirros [OPTION]"
+ print "Usage: debpartial-mirror [OPTION]"
print
print "-h --help\t\t\tDisplay this help end exit"
print "-c<file> --configfile=<file>\tSelect a config file"
@@ -36,7 +37,7 @@
version()
try:
- cnf = Config("../etc/debpartial-mirror.conf")
+ cnf = Config.Config("../etc/debpartial-mirror.conf")
except InvalidOption, msg:
print("Wrong option [%s] found on [%s] section."
% (msg.option, msg.section))
@@ -49,8 +50,6 @@
% (msg.option, msg.section))
exit(1)
-for backend in cnf.getBackends(ConfigBackendMirror):
- print cnf.getOption("server", backend.section)
-
-for backend in cnf.getBackends(ConfigBackendMerge):
- print cnf.getOption("backends", backend.section)
+backends = []
+for b in cnf.getBackends():
+ backends.append(Backend(b.section, cnf))