From a1de071656261bb3e488c373cc8b6e9e62bf1a6c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 14 Jun 2007 12:12:57 +0200 Subject: * aptsources/sourceslist.py: - merge missing fix from ubuntu branch --- aptsources/sourceslist.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'aptsources') diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index 16784ec4..e0f32f8d 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -254,12 +254,9 @@ class SourcesList: The method will search for existing matching repos and will try to reuse them as far as possible """ - - # create a working copy of the component list so that we can modify it later - # FIXME: perhaps could be done in a prittier way - comps = [] - for c in orig_comps: - comps.append(c) + # create a working copy of the component list so that + # we can modify it later + comps = orig_comps[:] # check if we have this source already in the sources.list for source in self.list: if source.disabled == False and source.invalid == False and \ -- cgit v1.2.3 From be23d152022cb79b74f9d7c6a07567b4e53c57d2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 28 Jun 2007 16:48:08 +0200 Subject: * aptsources/distro.py: - generalized some code, bringing it into the Distribution class, and wrote some missing methods for the DebianDistribution one (thanks to Gustavo Noronha Silva) --- aptsources/distro.py | 202 +++++++++++++++++++++++++++++---------------------- debian/changelog | 4 + 2 files changed, 118 insertions(+), 88 deletions(-) (limited to 'aptsources') diff --git a/aptsources/distro.py b/aptsources/distro.py index 9d3b4105..22c86b27 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -131,7 +131,7 @@ class Distribution: self.get_mirrors() - def get_mirrors(self): + def get_mirrors(self, mirror_template=None): """ Provide a set of mirrors where you can get the distribution from """ @@ -149,6 +149,97 @@ class Distribution: else: self.default_server = self.main_sources[0].uri + # get a list of country codes and real names + self.countries = {} + try: + f = open("/usr/share/iso-codes/iso_3166.tab", "r") + lines = f.readlines() + for line in lines: + parts = line.split("\t") + self.countries[parts[0].lower()] = parts[1].strip() + except: + print "could not open file '%s'" % file + else: + f.close() + + # try to guess the nearest mirror from the locale + self.country = None + self.country_code = None + locale = os.getenv("LANG", default="en.UK") + a = locale.find("_") + z = locale.find(".") + if z == -1: + z = len(locale) + country_code = locale[a+1:z].lower() + + if mirror_template: + self.nearest_server = mirror_template % country_code + + if self.countries.has_key(country_code): + self.country = self.countries[country_code] + self.country_code = country_code + + def _get_mirror_name(self, server): + ''' Try to get a human readable name for the main mirror of a country + Customize for different distributions ''' + country = None + i = server.find("://") + l = server.find(".archive.ubuntu.com") + if i != -1 and l != -1: + country = server[i+len("://"):l] + if self.countries.has_key(country): + # TRANSLATORS: %s is a country + return _("Server for %s") % \ + gettext.dgettext("iso_3166", + self.countries[country].rstrip()).rstrip() + else: + return("%s" % server.rstrip("/ ")) + + 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("/ ")) + + # Store all available servers: + # Name, URI, active + mirrors = [] + if len(self.used_servers) < 1 or \ + (len(self.used_servers) == 1 and \ + compare_mirrors(self.used_servers[0], self.main_server)): + mirrors.append([_("Main server"), self.main_server, True]) + mirrors.append([self._get_mirror_name(self.nearest_server), + self.nearest_server, False]) + 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 compare_mirrors(server, self.nearest_server): + mirrors.append([self._get_mirror_name(self.nearest_server), + self.nearest_server, False]) + mirrors.append([self._get_mirror_name(server), server, True]) + + elif len(self.used_servers) > 1: + # More than one server is used. Since we don't handle this case + # in the user interface we set "custom servers" to true and + # append a list of all used servers + mirrors.append([_("Main server"), self.main_server, False]) + mirrors.append([self._get_mirror_name(self.nearest_server), + self.nearest_server, False]) + mirrors.append([_("Custom servers"), None, True]) + for server in self.used_servers: + if compare_mirrors(server, self.nearest_server) or\ + compare_mirrors(server, self.main_server): + continue + elif not [self._get_mirror_name(server), server, False] in mirrors: + mirrors.append([self._get_mirror_name(server), server, False]) + + return mirrors + def add_source(self, type=None, uri=None, dist=None, comps=None, comment=""): """ @@ -295,96 +386,31 @@ class DebianDistribution(Distribution): else: return False + def _get_mirror_name(self, server): + ''' Try to get a human readable name for the main mirror of a country + Debian specific ''' + country = None + i = server.find("://ftp.") + l = server.find(".debian.org") + if i != -1 and l != -1: + country = server[i+len("://ftp."):l] + if self.countries.has_key(country): + # TRANSLATORS: %s is a country + return _("Server for %s") % \ + gettext.dgettext("iso_3166", + self.countries[country].rstrip()).rstrip() + else: + return("%s" % server.rstrip("/ ")) + + def get_mirrors(self): + Distribution.get_mirrors(self, + mirror_template="http://ftp.%s.debian.org/debian/") + class UbuntuDistribution(Distribution): ''' Class to support specific Ubuntu features ''' def get_mirrors(self): - Distribution.get_mirrors(self) - # get a list of country codes and real names - self.countries = {} - try: - f = open("/usr/share/iso-codes/iso_3166.tab", "r") - lines = f.readlines() - for line in lines: - parts = line.split("\t") - self.countries[parts[0].lower()] = parts[1].strip() - except: - print "could not open file '%s'" % file - else: - f.close() - - # try to guess the nearest mirror from the locale - self.country = None - self.country_code = None - locale = os.getenv("LANG", default="en.UK") - a = locale.find("_") - z = locale.find(".") - if z == -1: - z = len(locale) - country_code = locale[a+1:z].lower() - self.nearest_server = "http://%s.archive.ubuntu.com/ubuntu/" % \ - country_code - if self.countries.has_key(country_code): - self.country = self.countries[country_code] - self.country_code = country_code - - 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 - i = server.find("://") - l = server.find(".archive.ubuntu.com") - if i != -1 and l != -1: - country = server[i+len("://"):l] - if self.countries.has_key(country): - # TRANSLATORS: %s is a country - return _("Server for %s") % \ - gettext.dgettext("iso_3166", - self.countries[country].rstrip()).rstrip() - else: - return("%s" % server.rstrip("/ ")) - - # Store all available servers: - # Name, URI, active - mirrors = [] - if len(self.used_servers) < 1 or \ - (len(self.used_servers) == 1 and \ - 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 \ - 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 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]) - - elif len(self.used_servers) > 1: - # More than one server is used. Since we don't handle this case - # in the user interface we set "custom servers" to true and - # append a list of all used servers - mirrors.append([_("Main server"), self.main_server, False]) - mirrors.append([get_mirror_name(self.nearest_server), - self.nearest_server, False]) - mirrors.append([_("Custom servers"), None, True]) - for server in self.used_servers: - 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]) - - return mirrors + Distribution.get_mirrors(self, + mirror_template="http://%s.archive.ubuntu.com/ubuntu/") def get_distro(): ''' Check the currently used distribution and return the corresponding diff --git a/debian/changelog b/debian/changelog index 2e61f39b..de2039c1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,6 +9,10 @@ python-apt (0.7.3) unstable; urgency=low * python/cache.py: - throw FetchCancelleException, FetchFailedException, LockFailedException exceptions when something goes wrong + * aptsources/distro.py: + - generalized some code, bringing it into the Distribution + class, and wrote some missing methods for the DebianDistribution + one (thanks to Gustavo Noronha Silva) -- -- cgit v1.2.3 From ddf91759e3fabee1e0d61372247c4256758c387c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 3 Aug 2007 14:23:44 +0200 Subject: * aptsources/distro.py: - throw NoDistroTemplateException if not distribution template can be found * NMU * Fix version to not use CPU and OS since it's not available on APT anymore (closes: #435653, #435674) --- aptsources/distro.py | 8 +++++--- debian/changelog | 11 +++++++++++ python/apt_pkgmodule.cc | 2 -- 3 files changed, 16 insertions(+), 5 deletions(-) (limited to 'aptsources') diff --git a/aptsources/distro.py b/aptsources/distro.py index 22c86b27..debbb12a 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -31,6 +31,9 @@ import gettext def _(s): return gettext.dgettext("python-apt", s) +class NoDistroTemplateException(Exception): + pass + class Distribution: def __init__(self, id, codename, description, release): """ Container for distribution specific informations """ @@ -78,9 +81,8 @@ class Distribution: self.source_template = template break if self.source_template == None: - print "Error: could not find a distribution template" - # FIXME: will go away - only for debugging issues - sys.exit(1) + raise (NoDistroTemplateException, + "Error: could not find a distribution template") # find main and child sources media = [] diff --git a/debian/changelog b/debian/changelog index 09df061d..f206ad0d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,9 +5,20 @@ python-apt (0.7.4) UNRELEASED; urgency=low - support dictionary like access * python/apt_instmodule.cc: - added arCheckMember() + * aptsources/distro.py: + - throw NoDistroTemplateException if not distribution template + can be found -- Michael Vogt Mon, 30 Jul 2007 22:33:59 +0200 +python-apt (0.7.3.1) unstable; urgency=low + + * NMU + * Fix version to not use CPU and OS since it's not available on APT + anymore (closes: #435653, #435674) + + -- Otavio Salvador Thu, 02 Aug 2007 18:45:25 -0300 + python-apt (0.7.3) unstable; urgency=low * apt/package.py: diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index a0352d4e..15f7d238 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -483,8 +483,6 @@ extern "C" void initapt_pkg() // Version.. AddStr(Dict,"Version",pkgVersion); AddStr(Dict,"LibVersion",pkgLibVersion); - AddStr(Dict,"CPU",pkgCPU); - AddStr(Dict,"OS",pkgOS); AddStr(Dict,"Date",__DATE__); AddStr(Dict,"Time",__TIME__); -- cgit v1.2.3