summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Heinlein <sebi@sebi-laptop>2007-03-23 15:19:02 +0100
committerSebastian Heinlein <sebi@sebi-laptop>2007-03-23 15:19:02 +0100
commited893f0c1b8978acf6b986eb93a2af15d267319d (patch)
tree00750b2fcf5443fb42ffd065c876d7cbc1ce08e4
parented7d0d7a8a323d7a248dba3a1e49852995011435 (diff)
downloadpython-apt-ed893f0c1b8978acf6b986eb93a2af15d267319d.tar.gz
* add a mirror comparision function to clean up the code
* handle multiple server in a more sane way
-rw-r--r--aptsources/distro.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/aptsources/distro.py b/aptsources/distro.py
index 1fb499a0..5630259f 100644
--- a/aptsources/distro.py
+++ b/aptsources/distro.py
@@ -327,7 +327,10 @@ class UbuntuDistribution(Distribution):
def get_server_list(self):
''' Return a list of used and suggested servers '''
-
+ def compare_mirrors(mir1, mir2):
+ '''Helper function that handles comaprision of mirror urls
+ that could contain trailing slashes'''
+ return re.match(mir1.strip("/ "), mir2.rstrip("/ "))
def get_mirror_name(server):
''' Try to get a human readable name for the main mirror of a country'''
country = None
@@ -341,25 +344,27 @@ class UbuntuDistribution(Distribution):
gettext.dgettext("iso-3166",
self.countries[country].rstrip()).rstrip()
else:
- return("%s" % server)
+ return("%s" % server.rstrip("/ "))
# Store all available servers:
# Name, URI, active
mirrors = []
+ import pdb
+ pdb.set_trace()
if len(self.used_servers) < 1 or \
(len(self.used_servers) == 1 and \
- self.used_servers[0].rstrip("/") == self.main_server.rstrip("/")):
+ compare_mirrors(self.used_servers[0], self.main_server)):
mirrors.append([_("Main server"), self.main_server, True])
mirrors.append([get_mirror_name(self.nearest_server),
self.nearest_server, False])
- elif len(self.used_servers) == 1 and not re.match(self.used_servers[0],
- self.main_server):
+ elif len(self.used_servers) == 1 and not \
+ compare_mirrors(self.used_servers[0], self.main_server):
mirrors.append([_("Main server"), self.main_server, False])
# Only one server is used
server = self.used_servers[0]
# Append the nearest server if it's not already used
- if not re.match(server, self.nearest_server):
+ if not compare_mirrors(server, self.nearest_server):
mirrors.append([get_mirror_name(self.nearest_server),
self.nearest_server, False])
mirrors.append([get_mirror_name(server), server, True])
@@ -373,7 +378,8 @@ class UbuntuDistribution(Distribution):
self.nearest_server, False])
mirrors.append([_("Custom servers"), None, True])
for server in self.used_servers:
- if re.match(server, self.nearest_server):
+ if compare_mirrors(server, self.nearest_server) or\
+ compare_mirrors(server, self.main_server):
continue
elif not [get_mirror_name(server), server, False] in mirrors:
mirrors.append([get_mirror_name(server), server, False])