From ed893f0c1b8978acf6b986eb93a2af15d267319d Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Fri, 23 Mar 2007 15:19:02 +0100 Subject: * add a mirror comparision function to clean up the code * handle multiple server in a more sane way --- aptsources/distro.py | 20 +++++++++++++------- 1 file 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]) -- cgit v1.2.3 From bf5f2b17ba2dbb17af7e88b824482e9d9161d47d Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Fri, 23 Mar 2007 15:20:48 +0100 Subject: * missed a debug breakpoint --- aptsources/distro.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/aptsources/distro.py b/aptsources/distro.py index 5630259f..45a7172d 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -349,8 +349,6 @@ class UbuntuDistribution(Distribution): # 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 \ compare_mirrors(self.used_servers[0], self.main_server)): -- cgit v1.2.3