From 46abf8f70e4ec1c520cd2bcf1a9493f2869193a1 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 7 Nov 2008 21:06:03 +0100 Subject: python/acquire.cc (GetPkgAcqFile): Support DestDir and DestFilename. --- debian/changelog | 4 ++++ doc/examples/acquire.py | 13 +------------ python/acquire.cc | 12 ++++++++---- python/apt_pkgmodule.cc | 2 +- python/apt_pkgmodule.h | 1 + 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/debian/changelog b/debian/changelog index be0fa7cb..ac775f9c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ python-apt (0.7.8) UNRELEASED; urgency=low + [ Michael Vogt ] * python/cache.cc: - fix crash if Ver.PriorityType() returns NULL - fix GetCandidateVer() reporting incorrect versions after @@ -25,6 +26,9 @@ python-apt (0.7.8) UNRELEASED; urgency=low * data/templates/Ubuntu.info.in: - updated + [ Julian Andres Klode ] + * python/acquire.cc (GetPkgAcqFile): Support DestDir and DestFilename. + -- Michael Vogt Wed, 30 Jul 2008 10:24:30 +0200 python-apt (0.7.7.1) unstable; urgency=low diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py index 1291dbfa..eef6c1f7 100644 --- a/doc/examples/acquire.py +++ b/doc/examples/acquire.py @@ -5,24 +5,13 @@ import sys import tempfile def get_file(fetcher, uri, destFile): - cwd = os.getcwd() - # create a temp dir - dir = tempfile.mkdtemp() - os.chdir(dir) # get the file af = apt_pkg.GetPkgAcqFile(fetcher, uri=uri, - descr="sample descr") + descr="sample descr", destFile=destFile) res = fetcher.Run() if res != fetcher.ResultContinue: - os.rmdir(dir) - os.chdir(cwd) return False - filename = os.path.basename(uri) - os.rename(dir+"/"+filename,destFile) - # cleanup - os.rmdir(dir) - os.chdir(cwd) return True apt_pkg.init() diff --git a/python/acquire.cc b/python/acquire.cc index 65f8f2d7..9cf84928 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -242,6 +242,8 @@ PyTypeObject PkgAcquireFileType = 0, // tp_hash }; +char *doc_GetPkgAcqFile = +"GetPkgAcqFile(pkgAquire, uri[, md5, size, descr, shortDescr, destDir, destFile]) -> PkgAcqFile\n"; PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) { PyObject *pyfetcher; @@ -250,11 +252,11 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) uri = md5 = descr = shortDescr = destDir = destFile = ""; char * kwlist[] = {"owner","uri", "md5", "size", "descr", "shortDescr", - NULL}; + "destDir", "destFile", NULL}; - if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|siss", kwlist, + if (PyArg_ParseTupleAndKeywords(Args, kwds, "O!s|sissss", kwlist, &PkgAcquireType, &pyfetcher, &uri, &md5, - &size, &descr, &shortDescr) == 0) + &size, &descr, &shortDescr, &destDir, &destFile) == 0) return 0; pkgAcquire *fetcher = GetCpp(pyfetcher); @@ -263,7 +265,9 @@ PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) md5, // md5 size, // size descr, // descr - shortDescr); // short-desc + shortDescr, + destDir, + destFile); // short-desc CppPyObject *AcqFileObj = CppPyObject_NEW(&PkgAcquireFileType); AcqFileObj->Object = af; diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index fae85f00..7b13c838 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -447,7 +447,7 @@ static PyMethodDef methods[] = // Acquire {"GetAcquire",GetAcquire,METH_VARARGS,"GetAcquire() -> Acquire"}, - {"GetPkgAcqFile",(PyCFunction)GetPkgAcqFile,METH_KEYWORDS|METH_VARARGS,"GetPkgAcquireFile() -> pkgAcquireFile"}, + {"GetPkgAcqFile",(PyCFunction)GetPkgAcqFile,METH_KEYWORDS|METH_VARARGS, doc_GetPkgAcqFile}, // PkgManager {"GetPackageManager",GetPkgManager,METH_VARARGS,"GetPackageManager(DepCache) -> PackageManager"}, diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index f59c8ca0..6e02d8e3 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -75,6 +75,7 @@ PyObject *GetCdrom(PyObject *Self,PyObject *Args); // acquire extern PyTypeObject PkgAcquireType; +extern char *doc_GetPkgAcqFile; PyObject *GetAcquire(PyObject *Self,PyObject *Args); PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject *kwds); -- cgit v1.2.3 From b4fac97986469c356a3b1030c14d600ba333202e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 10 Nov 2008 10:41:45 +0100 Subject: * aptsources/distro.py: - add parameter to get_distro() to make unit testing easier * tests/test_aptsources_ports.py: - add test for arch specific handling (when sub arch is on a different mirror than "main" arches) --- aptsources/distro.py | 19 ++++++++---- data/templates/Ubuntu.info.in | 2 +- debian/changelog | 5 ++++ tests/test-data-ports/sources.list | 59 ++++++++++++++++++++++++++++++++++++++ tests/test_aptsources_ports.py | 37 ++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 tests/test-data-ports/sources.list create mode 100644 tests/test_aptsources_ports.py diff --git a/aptsources/distro.py b/aptsources/distro.py index 6d3b453f..f271bbc4 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -414,15 +414,22 @@ class UbuntuDistribution(Distribution): Distribution.get_mirrors(self, mirror_template="http://%s.archive.ubuntu.com/ubuntu/") -def get_distro(): - ''' Check the currently used distribution and return the corresponding - distriubtion class that supports distro specific features. ''' - lsb_info = [] - for lsb_option in ["-i", "-c", "-d", "-r"]: +def get_distro(id=None,codename=None,description=None,release=None): + """ + Check the currently used distribution and return the corresponding + distriubtion class that supports distro specific features. + + If no paramter are given the distro will be auto detected via + a call to lsb-release + """ + # make testing easier + if not (id and codename and description and release): + lsb_info = [] + for lsb_option in ["-i", "-c", "-d", "-r"]: pipe = os.popen("lsb_release %s -s" % lsb_option) lsb_info.append(pipe.read().strip()) del pipe - (id, codename, description, release) = lsb_info + (id, codename, description, release) = lsb_info if id == "Ubuntu": return UbuntuDistribution(id, codename, description, release) diff --git a/data/templates/Ubuntu.info.in b/data/templates/Ubuntu.info.in index 3b8f05c4..c3ebe052 100644 --- a/data/templates/Ubuntu.info.in +++ b/data/templates/Ubuntu.info.in @@ -116,7 +116,7 @@ RepositoryType: deb BaseURI: http://archive.ubuntu.com/ubuntu/ MatchURI: archive.ubuntu.com/ubuntu BaseURI-powerpc: http://ports.ubuntu.com/ -MatchURI-powerpc: ports.ubuntu.com +MatchURI-powerpc: ports.ubuntu.com|archive.ubuntu.com MirrorsFile-amd64: /usr/share/python-apt/templates/Ubuntu.mirrors MirrorsFile-i386: /usr/share/python-apt/templates/Ubuntu.mirrors _Description: Ubuntu 8.04 'Hardy Heron' diff --git a/debian/changelog b/debian/changelog index ac775f9c..f16964f4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -25,6 +25,11 @@ python-apt (0.7.8) UNRELEASED; urgency=low - fix crash when incorrect attribute is given * data/templates/Ubuntu.info.in: - updated + * aptsources/distro.py: + - add parameter to get_distro() to make unit testing easier + * tests/test_aptsources_ports.py: + - add test for arch specific handling (when sub arch is on + a different mirror than "main" arches) [ Julian Andres Klode ] * python/acquire.cc (GetPkgAcqFile): Support DestDir and DestFilename. diff --git a/tests/test-data-ports/sources.list b/tests/test-data-ports/sources.list new file mode 100644 index 00000000..a6b2f6ed --- /dev/null +++ b/tests/test-data-ports/sources.list @@ -0,0 +1,59 @@ +# +# deb cdrom:[Ubuntu-Server 8.04.1 _Hardy Heron_ - Release powerpc (20080703)]/ hardy main restricted + +# deb cdrom:[Ubuntu-Server 8.04.1 _Hardy Heron_ - Release powerpc (20080703)]/ hardy main restricted +# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to +# newer versions of the distribution. + +deb http://ports.ubuntu.com/ubuntu-ports/ hardy main restricted +deb-src http://archive.ubuntu.com/ubuntu hardy main restricted + +## Major bug fix updates produced after the final release of the +## distribution. +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates main restricted +deb-src http://archive.ubuntu.com/ubuntu hardy-updates main restricted + +## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu +## team, and may not be under a free licence. Please satisfy yourself as to +## your rights to use the software. Also, please note that software in +## universe WILL NOT receive any review or updates from the Ubuntu security +## team. +deb http://ports.ubuntu.com/ubuntu-ports/ hardy universe +deb-src http://archive.ubuntu.com/ubuntu hardy universe +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates universe +deb-src http://archive.ubuntu.com/ubuntu hardy-updates universe + +## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu +## team, and may not be under a free licence. Please satisfy yourself as to +## your rights to use the software. Also, please note that software in +## multiverse WILL NOT receive any review or updates from the Ubuntu +## security team. +deb http://ports.ubuntu.com/ubuntu-ports/ hardy multiverse +deb-src http://archive.ubuntu.com/ubuntu hardy multiverse +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-updates multiverse +deb-src http://archive.ubuntu.com/ubuntu hardy-updates multiverse + +## Uncomment the following two lines to add software from the 'backports' +## repository. +## N.B. software from this repository may not have been tested as +## extensively as that contained in the main release, although it includes +## newer versions of some applications which may provide useful features. +## Also, please note that software in backports WILL NOT receive any review +## or updates from the Ubuntu security team. +# deb http://ports.ubuntu.com/ubuntu-ports/ hardy-backports main restricted universe multiverse +# deb-src http://archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse + +## Uncomment the following two lines to add software from Canonical's +## 'partner' repository. This software is not part of Ubuntu, but is +## offered by Canonical and the respective vendors as a service to Ubuntu +## users. +# deb http://archive.canonical.com/ubuntu hardy partner +# deb-src http://archive.canonical.com/ubuntu hardy partner + +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted +deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security main restricted +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security universe +deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security universe +deb http://ports.ubuntu.com/ubuntu-ports/ hardy-security multiverse +deb-src http://ports.ubuntu.com/ubuntu-ports/ hardy-security multiverse +deb-src http://archive.ubuntu.com/ubuntu/ hardy-proposed restricted main multiverse universe diff --git a/tests/test_aptsources_ports.py b/tests/test_aptsources_ports.py new file mode 100644 index 00000000..203721c7 --- /dev/null +++ b/tests/test_aptsources_ports.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +import unittest +import apt_pkg +import os +import copy + +import sys +sys.path.insert(0, "../") +import aptsources +import aptsources.sourceslist +import aptsources.distro + +class TestAptSources(unittest.TestCase): + def __init__(self, methodName): + unittest.TestCase.__init__(self, methodName) + apt_pkg.init() + apt_pkg.Config.Set("APT::Architecture","powerpc") + apt_pkg.Config.Set("Dir::Etc", os.path.join(os.getcwd(),"test-data-ports")) + apt_pkg.Config.Set("Dir::Etc::sourceparts","/xxx") + + def testMatcher(self): + apt_pkg.Config.Set("Dir::Etc::sourcelist","sources.list") + sources = aptsources.sourceslist.SourcesList() + distro = aptsources.distro.get_distro("Ubuntu","hardy","desc","8.04") + distro.get_sources(sources) + # test if all suits of the current distro were detected correctly + dist_templates = set() + for s in sources: + if not s.line.strip() or s.line.startswith("#"): + continue + if not s.template: + self.fail("source entry '%s' has no matcher" % s) + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3 From a4a6295a580846c3af96ca4b54940e4405360272 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 10 Nov 2008 11:31:55 +0100 Subject: fix missing base uris for *-security and powerpc --- data/templates/Ubuntu.info.in | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/data/templates/Ubuntu.info.in b/data/templates/Ubuntu.info.in index c3ebe052..6b4bc3e8 100644 --- a/data/templates/Ubuntu.info.in +++ b/data/templates/Ubuntu.info.in @@ -3,9 +3,9 @@ _ChangelogURI: http://changelogs.ubuntu.com/changelogs/pool/%s/%s/%s/%s_%s/chang Suite: jaunty RepositoryType: deb BaseURI: http://archive.ubuntu.com/ubuntu/ -BaseURI-powerpc: http://ports.ubuntu.com/ -MatchURI-powerpc: ports.ubuntu.com MatchURI: archive.ubuntu.com/ubuntu +BaseURI-powerpc: http://ports.ubuntu.com/ +MatchURI-powerpc: ports.ubuntu.com|archive.ubuntu.com MirrorsFile-amd64: /usr/share/python-apt/templates/Ubuntu.mirrors MirrorsFile-i386: /usr/share/python-apt/templates/Ubuntu.mirrors _Description: Ubuntu 9.04 'Jaunty Jackalope' @@ -38,6 +38,8 @@ ParentSuite: jaunty RepositoryType: deb BaseURI: http://security.ubuntu.com/ubuntu/ MatchURI: archive.ubuntu.com/ubuntu|security.ubuntu.com +BaseURI-powerpc: http://ports.ubuntu.com/ +MatchURI-powerpc: ports.ubuntu.com/ubuntu _Description: Important security updates Suite: jaunty-updates @@ -58,9 +60,9 @@ _Description: Unsupported updates Suite: intrepid RepositoryType: deb BaseURI: http://archive.ubuntu.com/ubuntu/ -BaseURI-powerpc: http://ports.ubuntu.com/ -MatchURI-powerpc: ports.ubuntu.com MatchURI: archive.ubuntu.com/ubuntu +BaseURI-powerpc: http://ports.ubuntu.com/ +MatchURI-powerpc: ports.ubuntu.com|archive.ubuntu.com MirrorsFile-amd64: /usr/share/python-apt/templates/Ubuntu.mirrors MirrorsFile-i386: /usr/share/python-apt/templates/Ubuntu.mirrors _Description: Ubuntu 8.10 'Intrepid Ibex' @@ -93,6 +95,8 @@ ParentSuite: intrepid RepositoryType: deb BaseURI: http://security.ubuntu.com/ubuntu/ MatchURI: archive.ubuntu.com/ubuntu|security.ubuntu.com +BaseURI-powerpc: http://ports.ubuntu.com/ +MatchURI-powerpc: ports.ubuntu.com/ubuntu _Description: Important security updates Suite: intrepid-updates -- cgit v1.2.3 From 969986c30b34fc47b47a9ca2c9e1cd6ab38fe5ea Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 10 Nov 2008 11:33:51 +0100 Subject: add missing lpia --- data/templates/Ubuntu.info.in | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/data/templates/Ubuntu.info.in b/data/templates/Ubuntu.info.in index 6b4bc3e8..67180bcb 100644 --- a/data/templates/Ubuntu.info.in +++ b/data/templates/Ubuntu.info.in @@ -6,6 +6,8 @@ BaseURI: http://archive.ubuntu.com/ubuntu/ MatchURI: archive.ubuntu.com/ubuntu BaseURI-powerpc: http://ports.ubuntu.com/ MatchURI-powerpc: ports.ubuntu.com|archive.ubuntu.com +BaseURI-lpia: http://ports.ubuntu.com/ +MatchURI-lpia: ports.ubuntu.com|archive.ubuntu.com MirrorsFile-amd64: /usr/share/python-apt/templates/Ubuntu.mirrors MirrorsFile-i386: /usr/share/python-apt/templates/Ubuntu.mirrors _Description: Ubuntu 9.04 'Jaunty Jackalope' @@ -40,6 +42,8 @@ BaseURI: http://security.ubuntu.com/ubuntu/ MatchURI: archive.ubuntu.com/ubuntu|security.ubuntu.com BaseURI-powerpc: http://ports.ubuntu.com/ MatchURI-powerpc: ports.ubuntu.com/ubuntu +BaseURI-lpia: http://ports.ubuntu.com/ +MatchURI-lpia: ports.ubuntu.com/ubuntu _Description: Important security updates Suite: jaunty-updates @@ -63,6 +67,8 @@ BaseURI: http://archive.ubuntu.com/ubuntu/ MatchURI: archive.ubuntu.com/ubuntu BaseURI-powerpc: http://ports.ubuntu.com/ MatchURI-powerpc: ports.ubuntu.com|archive.ubuntu.com +BaseURI-lpia: http://ports.ubuntu.com/ +MatchURI-lpia: ports.ubuntu.com|archive.ubuntu.com MirrorsFile-amd64: /usr/share/python-apt/templates/Ubuntu.mirrors MirrorsFile-i386: /usr/share/python-apt/templates/Ubuntu.mirrors _Description: Ubuntu 8.10 'Intrepid Ibex' @@ -97,6 +103,8 @@ BaseURI: http://security.ubuntu.com/ubuntu/ MatchURI: archive.ubuntu.com/ubuntu|security.ubuntu.com BaseURI-powerpc: http://ports.ubuntu.com/ MatchURI-powerpc: ports.ubuntu.com/ubuntu +BaseURI-lpia: http://ports.ubuntu.com/ +MatchURI-lpia: ports.ubuntu.com/ubuntu _Description: Important security updates Suite: intrepid-updates @@ -121,6 +129,8 @@ BaseURI: http://archive.ubuntu.com/ubuntu/ MatchURI: archive.ubuntu.com/ubuntu BaseURI-powerpc: http://ports.ubuntu.com/ MatchURI-powerpc: ports.ubuntu.com|archive.ubuntu.com +BaseURI-lpia: http://ports.ubuntu.com/ +MatchURI-lpia: ports.ubuntu.com|archive.ubuntu.com MirrorsFile-amd64: /usr/share/python-apt/templates/Ubuntu.mirrors MirrorsFile-i386: /usr/share/python-apt/templates/Ubuntu.mirrors _Description: Ubuntu 8.04 'Hardy Heron' -- cgit v1.2.3