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(-) 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 e3791336f419ea14f3841814f37f4c8f00479588 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 2 Jul 2007 18:37:30 +0200 Subject: * debian/control: - updated for python-distutils-extra (>= 1.9.0) * debian/python-apt.install: - fix i18n files --- debian/changelog | 6 +++++- debian/control | 2 +- debian/python-apt.install | 1 + setup.cfg | 3 --- setup.py | 6 +++--- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/debian/changelog b/debian/changelog index de2039c1..5052d867 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,8 +13,12 @@ python-apt (0.7.3) unstable; urgency=low - generalized some code, bringing it into the Distribution class, and wrote some missing methods for the DebianDistribution one (thanks to Gustavo Noronha Silva) + * debian/control: + - updated for python-distutils-extra (>= 1.9.0) + * debian/python-apt.install: + - fix i18n files - -- + -- Michael Vogt Mon, 02 Jul 2007 18:33:36 +0200 python-apt (0.7.2) unstable; urgency=low diff --git a/debian/control b/debian/control index d8c080d7..1f583e2f 100644 --- a/debian/control +++ b/debian/control @@ -5,7 +5,7 @@ Maintainer: APT Development Team Uploaders: Matt Zimmerman , Michael Vogt Standards-Version: 3.7.2.2 XS-Python-Version: all -Build-Depends: debhelper (>= 5.0.37.1), libapt-pkg-dev (>= 0.7.0), apt-utils, python-all-dev, python-distutils-extra, cdbs, python-central (>= 0.5), python-all-dbg +Build-Depends: debhelper (>= 5.0.37.1), libapt-pkg-dev (>= 0.7.0), apt-utils, python-all-dev, python-distutils-extra (>= 1.9.0), cdbs, python-central (>= 0.5), python-all-dbg XS-Vcs-Bzr: http://people.debian.org/~mvo/bzr/python-apt/debian-sid Package: python-apt diff --git a/debian/python-apt.install b/debian/python-apt.install index 3e08ba50..4910e8ed 100644 --- a/debian/python-apt.install +++ b/debian/python-apt.install @@ -1,2 +1,3 @@ debian/tmp/usr/lib/python* +debian/tmp/usr/share/locale debian/tmp/usr/share/python-apt diff --git a/setup.cfg b/setup.cfg index 718b6e23..c0c0440e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,3 @@ -[build] -l10n=True - [build_l10n] domain=python-apt diff --git a/setup.py b/setup.py index 99bc62c6..b8819b31 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup, Extension from distutils.sysconfig import parse_makefile -from DistUtilsExtra.distutils_extra import build_extra, build_l10n +from DistUtilsExtra.command import * import glob, os, string # The apt_pkg module @@ -40,8 +40,8 @@ setup(name="python-apt", glob.glob('build/data/templates/*.info')), ('share/python-apt/templates', glob.glob('data/templates/*.mirrors'))], - cmdclass = { "build" : build_extra, - "build_l10n" : build_l10n }, + cmdclass = { "build" : build_extra.build_extra, + "build_i18n" : build_i18n.build_i18n }, license = 'GNU GPL', platforms = 'posix' ) -- cgit v1.2.3 From a13e90fd1c1f2809d60f61c1d16a3cf4ebba18c9 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 25 Jul 2007 09:29:23 +0200 Subject: * apt/package.py: * apt/cache.py: * python/indexfile.cc: - increase str buffer in PackageIndexFileRepr --- debian/changelog | 8 +++++--- python/indexfile.cc | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 5052d867..37df62a9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,12 +1,12 @@ python-apt (0.7.3) unstable; urgency=low - * python/package.py: + * apt/package.py: - added Record class that can be accessed like a dictionary and return it in candidateRecord and installedRecord (thanks to Alexander Sack for discussing this with me) * doc/examples/records.py: - added example how to use the new Records class - * python/cache.py: + * apt/cache.py: - throw FetchCancelleException, FetchFailedException, LockFailedException exceptions when something goes wrong * aptsources/distro.py: @@ -17,8 +17,10 @@ python-apt (0.7.3) unstable; urgency=low - updated for python-distutils-extra (>= 1.9.0) * debian/python-apt.install: - fix i18n files + * python/indexfile.cc: + - increase str buffer in PackageIndexFileRepr - -- Michael Vogt Mon, 02 Jul 2007 18:33:36 +0200 + -- python-apt (0.7.2) unstable; urgency=low diff --git a/python/indexfile.cc b/python/indexfile.cc index ef6ffc8a..4e32f2ab 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -56,7 +56,7 @@ static PyObject *PackageIndexFileRepr(PyObject *Self) { pkgIndexFile *File = GetCpp(Self); - char S[300]; + char S[1024]; snprintf(S,sizeof(S),"