From f17fc818cca41668bb6358e490ff3278e64fa493 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 5 Oct 2011 10:32:04 +0200 Subject: * tests/test_apt_cache.py: - add __cmp__ to apt.Package so that sort() sorts by name on list of package objects --- tests/test_apt_cache.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 2f812059..9c1f549f 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -181,5 +181,16 @@ class TestAptCache(unittest.TestCase): apt_pkg.config.set("dir::etc::sourcelist", old_source_list) apt_pkg.config.set("dir::etc::sourceparts", old_source_parts) + def test_package_cmp(self): + cache = apt.Cache() + l = [] + l.append(cache["libc6"]) + l.append(cache["xterm"]) + l.append(cache["apt"]) + l.sort() + self.assertEqual([p.name for p in l], + ["apt", "libc6", "xterm"]) + + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From b7ce3c2b47e1234631e00cb0ba8a86fa0aa9c8d8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 21 Oct 2011 10:08:44 +0200 Subject: * python/apt_pkgmodule.cc: - add apt_pkg.get_architectures() call --- debian/changelog | 2 ++ po/python-apt.pot | 20 ++++++++++---------- python/apt_pkgmodule.cc | 27 +++++++++++++++++++++++++++ tests/test_apt_cache.py | 5 +++++ 4 files changed, 44 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index 39c506e6..6fbc5241 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,6 +13,8 @@ python-apt (0.8.2) UNRELEASED; urgency=low - updated, thanks to Joe Dalton (closes: #631309) * po/sr.po: - updated, thanks to Nikola Nenadic (closes: #638308) + * python/apt_pkgmodule.cc: + - add apt_pkg.get_architectures() call [ Tshepang Lekhonkhobe ] * rm usage of camelcase in cache.py doc (closes: #626617) diff --git a/po/python-apt.pot b/po/python-apt.pot index 70c68099..48b4fb18 100644 --- a/po/python-apt.pot +++ b/po/python-apt.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-10-19 18:07+0200\n" +"POT-Creation-Date: 2011-10-21 10:05+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -455,11 +455,11 @@ msgstr "" msgid "Invalid unicode in description for '%s' (%s). Please report." msgstr "" -#: ../apt/package.py:1065 ../apt/package.py:1171 +#: ../apt/package.py:1068 ../apt/package.py:1174 msgid "The list of changes is not available" msgstr "" -#: ../apt/package.py:1177 +#: ../apt/package.py:1180 #, python-format msgid "" "The list of changes is not available yet.\n" @@ -468,7 +468,7 @@ msgid "" "until the changes become available or try again later." msgstr "" -#: ../apt/package.py:1184 +#: ../apt/package.py:1187 msgid "" "Failed to download the list of changes. \n" "Please check your Internet connection." @@ -535,26 +535,26 @@ msgstr "" msgid "Cannot install '%s'" msgstr "" -#: ../apt/debfile.py:508 +#: ../apt/debfile.py:510 msgid "Python-debian module not available" msgstr "" -#: ../apt/debfile.py:542 +#: ../apt/debfile.py:544 msgid "" "Automatically decompressed:\n" "\n" msgstr "" -#: ../apt/debfile.py:548 +#: ../apt/debfile.py:550 msgid "Automatically converted to printable ascii:\n" msgstr "" -#: ../apt/debfile.py:638 +#: ../apt/debfile.py:640 #, python-format msgid "Install Build-Dependencies for source package '%s' that builds %s\n" msgstr "" -#: ../apt/debfile.py:648 +#: ../apt/debfile.py:650 msgid "An essential package would be removed" msgstr "" @@ -605,6 +605,6 @@ msgstr "" msgid "Please insert a Disc in the drive and press enter" msgstr "" -#: ../apt/cache.py:149 +#: ../apt/cache.py:148 msgid "Building data structures" msgstr "" diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index e8490b4e..03c88e9a 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -393,6 +394,29 @@ static PyObject *sha256sum(PyObject *Self,PyObject *Args) return 0; } /*}}}*/ +// get_architectures - return the list of architectures /*{{{*/ +// --------------------------------------------------------------------- +static const char *doc_GetArchitectures = + "get_architectures() -> list\n\n" + "Return the list of supported architectures on this system. On a \n" + "multiarch system this can be more than one.";; +static PyObject *GetArchitectures(PyObject *Self,PyObject *Args) +{ + PyObject *Obj; + if (PyArg_ParseTuple(Args,"",&Obj) == 0) + return 0; + + PyObject *List = PyList_New(0); + vector arches = APT::Configuration::getArchitectures(); + vector::const_iterator I; + for (I = arches.begin(); I != arches.end(); I++) + { + PyList_Append(List, CppPyString(*I)); + } + + return List; +} + /*}}}*/ // init - 3 init functions /*{{{*/ // --------------------------------------------------------------------- static char *doc_Init = @@ -539,6 +563,9 @@ static PyMethodDef methods[] = {"sha1sum",sha1sum,METH_VARARGS,doc_sha1sum}, {"sha256sum",sha256sum,METH_VARARGS,doc_sha256sum}, + // multiarch + {"get_architectures", GetArchitectures, METH_VARARGS, doc_GetArchitectures}, + // Strings {"check_domain_list",StrCheckDomainList,METH_VARARGS, "check_domain_list(host: str, domains: str) -> bool\n\n" diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 2b742dfa..0d80f617 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -191,6 +191,11 @@ class TestAptCache(unittest.TestCase): self.assertEqual([p.name for p in l], ["apt", "libc6", "xterm"]) + def test_get_architectures(self): + main_arch = apt.apt_pkg.config.get("APT::Architecture") + arches = apt_pkg.get_architectures() + self.assertTrue(main_arch in arches) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From 628d7caf9ca6ee819398a4b88c23e42094fe2c10 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 10 Nov 2011 17:20:58 +0100 Subject: fix build against apt in experimental --- debian/changelog | 1 + po/python-apt.pot | 2 +- python/apt_pkgmodule.cc | 11 ++++++----- python/apt_pkgmodule.h | 1 + python/arfile.cc | 8 ++++---- python/cdrom.cc | 4 ++-- python/configuration.cc | 2 +- python/depcache.cc | 1 + python/lock.cc | 2 ++ python/metaindex.cc | 4 ++-- python/progress.cc | 14 +++++++------- python/progress.h | 6 +++--- python/tag.cc | 1 + python/tarfile.cc | 2 +- tests/test_debfile.py | 13 ++++++++++++- 15 files changed, 45 insertions(+), 27 deletions(-) (limited to 'tests') diff --git a/debian/changelog b/debian/changelog index f5ae2b79..58326dc2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,7 @@ python-apt (0.8.2) UNRELEASED; urgency=low * apt/cache.py: - remove "print" when creating dirs in apt.Cache(rootdir=dir), thanks to Martin Pitt + * fix build against apt in experimental [ Tshepang Lekhonkhobe ] * rm usage of camelcase in cache.py doc (closes: #626617) diff --git a/po/python-apt.pot b/po/python-apt.pot index d19871d0..046f5779 100644 --- a/po/python-apt.pot +++ b/po/python-apt.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-10-21 10:10+0200\n" +"POT-Creation-Date: 2011-11-10 17:20+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 8532b1e3..acfdf019 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -185,11 +186,11 @@ static const char *parse_src_depends_doc = "only contains those dependencies for the architecture set in the\n" "configuration variable APT::Architecture"; static PyObject *RealParseDepends(PyObject *Self,PyObject *Args, - bool ParseArchFlags, string name, + bool ParseArchFlags, std::string name, bool debStyle=false) { - string Package; - string Version; + std::string Package; + std::string Version; unsigned int Op; bool StripMultiArch=true; @@ -408,8 +409,8 @@ static PyObject *GetArchitectures(PyObject *Self,PyObject *Args) return 0; PyObject *List = PyList_New(0); - vector arches = APT::Configuration::getArchitectures(); - vector::const_iterator I; + std::vector arches = APT::Configuration::getArchitectures(); + std::vector::const_iterator I; for (I = arches.begin(); I != arches.end(); I++) { PyList_Append(List, CppPyString(*I)); diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index b3534a30..85c34130 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "generic.h" // Configuration Stuff diff --git a/python/arfile.cc b/python/arfile.cc index c31ea35e..44cd3c82 100644 --- a/python/arfile.cc +++ b/python/arfile.cc @@ -204,7 +204,7 @@ static PyObject *_extract(FileFd &Fd, const ARArchive::Member *member, if (!Fd.Seek(member->Start)) return HandleErrors(); - string outfile_str = flCombine(dir,member->Name); + std::string outfile_str = flCombine(dir,member->Name); char *outfile = (char*)outfile_str.c_str(); // We are not using FileFd here, because we want to raise OSErrror with @@ -539,8 +539,8 @@ static PyObject *debfile_new(PyTypeObject *type, PyObject *args, PyObject *kwds) for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) { - string member = string("data.tar.").append(*t); - string comp = _config->Find(string("Acquire::CompressionTypes::").append(*t)); + std::string member = std::string("data.tar.").append(*t); + std::string comp = _config->Find(std::string("Acquire::CompressionTypes::").append(*t)); self->data = _gettar(self, self->Object->FindMember(member.c_str()), comp.c_str()); if (self->data) @@ -548,7 +548,7 @@ static PyObject *debfile_new(PyTypeObject *type, PyObject *args, PyObject *kwds) } // no data found, we need to if (!self->data) { - string error; + std::string error; for (std::vector::const_iterator t = types.begin(); t != types.end(); ++t) error.append(*t + ","); diff --git a/python/cdrom.cc b/python/cdrom.cc index 6ac16d59..46bb769c 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -67,7 +67,7 @@ static PyObject *cdrom_ident(PyObject *Self,PyObject *Args) PyCdromProgress progress; progress.setCallbackInst(pyCdromProgressInst); - string ident; + std::string ident; bool res = Cdrom.Ident(ident, &progress); if (res) @@ -94,7 +94,7 @@ static PyObject *cdrom_ident_old(PyObject *Self,PyObject *Args) PyCdromProgress progress; progress.setCallbackInst(pyCdromProgressInst); - string ident; + std::string ident; bool res = Cdrom.Ident(ident, &progress); PyObject *boolres = PyBool_FromLong(res); diff --git a/python/configuration.cc b/python/configuration.cc index 9000f71f..3e634901 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -262,7 +262,7 @@ static PyObject *CnfDump(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"") == 0) return 0; - stringstream ss; + std::stringstream ss; GetSelf(Self).Dump(ss); return CppPyString(ss.str()); } diff --git a/python/depcache.cc b/python/depcache.cc index e6113429..73993c82 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/python/lock.cc b/python/lock.cc index 2c957df1..38a2bc74 100644 --- a/python/lock.cc +++ b/python/lock.cc @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "generic.h" static PyObject *systemlock_exit(PyObject *self, PyObject *args) diff --git a/python/metaindex.cc b/python/metaindex.cc index a00cf04e..9e330d3d 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -33,8 +33,8 @@ static PyObject *MetaIndexGetIsTrusted(PyObject *Self,void*) { static PyObject *MetaIndexGetIndexFiles(PyObject *Self,void*) { metaIndex *meta = GetCpp(Self); PyObject *List = PyList_New(0); - vector *indexFiles = meta->GetIndexFiles(); - for (vector::const_iterator I = indexFiles->begin(); + std::vector *indexFiles = meta->GetIndexFiles(); + for (std::vector::const_iterator I = indexFiles->begin(); I != indexFiles->end(); I++) { CppPyObject *Obj; diff --git a/python/progress.cc b/python/progress.cc index bd3c2ad6..a7fd7ae1 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -127,7 +127,7 @@ PyObject *PyFetchProgress::GetDesc(pkgAcquire::ItemDesc *item) { return pyDesc; } -bool PyFetchProgress::MediaChange(string Media, string Drive) +bool PyFetchProgress::MediaChange(std::string Media, std::string Drive) { PyCbObj_END_ALLOW_THREADS //std::cout << "MediaChange" << std::endl; @@ -485,7 +485,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) PyObject *v = PyObject_GetAttrString(callbackInst, "writefd"); if(v) { int fd = PyObject_AsFileDescriptor(v); - cout << "got fd: " << fd << endl; + std::cout << "got fd: " << fd << std::endl; res = pm->DoInstall(fd); } else { res = pm->DoInstall(); @@ -542,7 +542,7 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) //----------------------------------------------------------------------------- // apt-cdrom interface -void PyCdromProgress::Update(string text, int current) +void PyCdromProgress::Update(std::string text, int current) { PyObject *arglist = Py_BuildValue("(si)", text.c_str(), current); setattr(callbackInst, "total_steps", "i", totalSteps); @@ -569,7 +569,7 @@ bool PyCdromProgress::ChangeCdrom() } -bool PyCdromProgress::AskCdromName(string &Name) +bool PyCdromProgress::AskCdromName(std::string &Name) { PyObject *arglist = Py_BuildValue("()"); const char *new_name; @@ -582,7 +582,7 @@ bool PyCdromProgress::AskCdromName(string &Name) if(!PyArg_Parse(result, "(bs)", &res, &new_name)) std::cerr << "AskCdromName: result could not be parsed" << std::endl; // set the new name - Name = string(new_name); + Name =std:: string(new_name); return res; } // New style: String on success, None on failure. @@ -593,7 +593,7 @@ bool PyCdromProgress::AskCdromName(string &Name) if(!PyArg_Parse(result, "s", &new_name)) std::cerr << "ask_cdrom_name: result could not be parsed" << std::endl; else - Name = string(new_name); - return true; + Name = std::string(new_name); + return true; } } diff --git a/python/progress.h b/python/progress.h index 4e66c771..af8e3acc 100644 --- a/python/progress.h +++ b/python/progress.h @@ -72,7 +72,7 @@ struct PyFetchProgress : public pkgAcquireStatus, public PyCallbackObj void UpdateStatus(pkgAcquire::ItemDesc & Itm, int status); - virtual bool MediaChange(string Media, string Drive); + virtual bool MediaChange(std::string Media, std::string Drive); void setPyAcquire(PyObject *o) { Py_CLEAR(pyAcquire); @@ -107,11 +107,11 @@ struct PyInstallProgress : public PyCallbackObj struct PyCdromProgress : public pkgCdromStatus, public PyCallbackObj { // update steps, will be called regularly as a "pulse" - virtual void Update(string text="", int current=0); + virtual void Update(std::string text="", int current=0); // ask for cdrom insert virtual bool ChangeCdrom(); // ask for cdrom name - virtual bool AskCdromName(string &Name); + virtual bool AskCdromName(std::string &Name); PyCdromProgress() : PyCallbackObj() {}; }; diff --git a/python/tag.cc b/python/tag.cc index 94554400..3996af8e 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -26,6 +26,7 @@ #include "apt_pkgmodule.h" #include +#include #include #include diff --git a/python/tarfile.cc b/python/tarfile.cc index cdfe0a7c..bd903b57 100644 --- a/python/tarfile.cc +++ b/python/tarfile.cc @@ -348,7 +348,7 @@ static const char *tarfile_extractall_doc = "can be used to change the target directory."; static PyObject *tarfile_extractall(PyObject *self, PyObject *args) { - string cwd = SafeGetCWD(); + std::string cwd = SafeGetCWD(); char *rootdir = 0; if (PyArg_ParseTuple(args,"|s:extractall",&rootdir) == 0) return 0; diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 951c2afe..501b8f61 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -87,7 +87,7 @@ class TestDebfilee(unittest.TestCase): self.assertEqual(deb["Maintainer"], "Samuel Lidén Borell ") - def testContent(self): + def test_content(self): # no python-debian for python3 yet, so fail gracefully try: import debian @@ -130,6 +130,17 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading # we need to support python2.6 self.assertTrue(raised) + def test_multiarch_deb(self): + print apt_pkg.get_architectures() + if apt_pkg.get_architectures() != ["amd64", "i386"]: + logging.warn("skipping test because running on a non-multiarch system") + return + deb = apt.debfile.DebPackage("./data/test_debs/multiarch-test1_i386.deb") + print deb.missing_deps() + + + + if __name__ == "__main__": #logging.basicConfig(level=logging.DEBUG) unittest.main() -- cgit v1.2.3 From add08632b8a66c7ba5de7ab44d8a10ec9462692e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 17 Nov 2011 17:57:34 +0100 Subject: allow Dependency object to be iteratable, this allows to write code like: for or_dep_group in pkg.candidate.dependencies: for dep in or_dep_group: do_something() --- apt/package.py | 3 +++ debian/changelog | 4 ++++ tests/test_apt_cache.py | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/apt/package.py b/apt/package.py index e09acca4..ab692788 100644 --- a/apt/package.py +++ b/apt/package.py @@ -107,6 +107,9 @@ class Dependency(object): def __repr__(self): return repr(self.or_dependencies) + def __iter__(self): + return self.or_dependencies.__iter__() + class DeprecatedProperty(property): """A property which gives DeprecationWarning on access. diff --git a/debian/changelog b/debian/changelog index afffdf12..7d939702 100644 --- a/debian/changelog +++ b/debian/changelog @@ -24,6 +24,10 @@ python-apt (0.8.2) UNRELEASED; urgency=low (LP: #885895) * apt/package.py: - add new "suggests" property, thanks to Christop Groth + - allow Dependency object to be iteratable, this allows to write + code like: + for or_dep_group in pkg.candidate.dependencies: + for dep in or_dep_group: do_something() [ Tshepang Lekhonkhobe ] * rm usage of camelcase in cache.py doc (closes: #626617) diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 0d80f617..7784a25f 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -55,8 +55,8 @@ class TestAptCache(unittest.TestCase): # that is possible and does not crash for pkg in cache: if pkg.candidate: - for or_dep in pkg.candidate.dependencies: - for dep in or_dep.or_dependencies: + for or_deps in pkg.candidate.dependencies: + for dep in or_deps: self.assertTrue(dep.name) self.assertTrue(isinstance(dep.relation, str)) self.assertTrue(dep.pre_depend in (True, False)) -- cgit v1.2.3 From b7b608bf2c66e7466313ea02568348aea9cc29ba Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:01:26 +0100 Subject: cleanup based on feedback from juliank --- apt/cache.py | 10 ++++++++-- apt/debfile.py | 19 +++++++++++++------ debian/changelog | 6 +++--- tests/test_debfile.py | 12 +++++++----- 4 files changed, 31 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/apt/cache.py b/apt/cache.py index 8a456715..b4d67fa5 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -46,7 +46,13 @@ class LockFailedException(IOError): class Cache(object): """Dictionary-like package cache. - The dictionary of this class contains all available packages. + The APT cache file contains a hash table mapping names of binary + packages to their metadata. A Cache object is the in-core + representation of the same. It provides access to APTs idea of the + list of available packages. + + The cache can be used like a mapping from package names to Package + objects (although only getting items is supported). Keyword arguments: progress -- a OpProgress object @@ -510,7 +516,7 @@ class Cache(object): self._callbacks[name].append(callback) def actiongroup(self): - """Return an action group object for the current cache. + """Return an `ActionGroup` object for the current cache. Action groups can be used to speedup actions. The action group is active as soon as it is created, and disabled when the object is diff --git a/apt/debfile.py b/apt/debfile.py index 104b0814..5b9274b2 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -53,6 +53,7 @@ class DebPackage(object): self.pkgname = "" self._sections = {} self._need_pkgs = [] + self._check_was_run = False self._failure_string = "" if filename: self.open(filename) @@ -68,7 +69,8 @@ class DebPackage(object): control = self._debfile.control.extractdata("control") self._sections = apt_pkg.TagSection(control) self.pkgname = self._sections["Package"] - + self._check_was_run = False + def __getitem__(self, key): return self._sections[key] @@ -393,6 +395,8 @@ class DebPackage(object): """Check if the package is installable.""" self._dbg(3, "check") + self._check_was_run = True + # check arch if not "Architecture" in self._sections: self._dbg(1, "ERROR: no architecture field") @@ -472,8 +476,8 @@ class DebPackage(object): def missing_deps(self): """Return missing dependencies.""" self._dbg(1, "Installing: %s" % self._need_pkgs) - if not self._need_pkgs: - self.check() + if not self._check_was_run: + raise ValueError("property only available after check() was run") return self._need_pkgs @property @@ -485,8 +489,8 @@ class DebPackage(object): install = [] remove = [] unauthenticated = [] - if not self._cache: - self.check() + if not self._check_was_run: + raise ValueError("property only available after check() was run") for pkg in self._cache: if pkg.marked_install or pkg.marked_upgrade: install.append(pkg.name) @@ -641,7 +645,8 @@ class DscSrcPackage(DebPackage): "source package '%s' that builds %s\n") % (self.pkgname, " ".join(self.binaries)) self._sections["Description"] = s - + self._check_was_run = False + def check(self): """Check if the package is installable..""" if not self.check_conflicts(): @@ -649,6 +654,8 @@ class DscSrcPackage(DebPackage): if self._cache[pkgname]._pkg.essential: raise Exception(_("An essential package would be removed")) self._cache[pkgname].mark_delete() + # properties are ok now + self._check_was_run = True # FIXME: a additional run of the check_conflicts() # after _satisfy_depends() should probably be done return self._satisfy_depends(self.depends) diff --git a/debian/changelog b/debian/changelog index 27eb8e97..cc922735 100644 --- a/debian/changelog +++ b/debian/changelog @@ -26,13 +26,13 @@ python-apt (0.8.2) UNRELEASED; urgency=low - set Dir::bin::dpkg if a alternate rootdir is given (LP: #885895) * build fixes for the apt in experimental + * apt/debfile.py: raise error when accessing require_changes and + missing_deps without calling check() before, thanks to + Tshepang Lekhonkhobe (closes: #624379) [ Tshepang Lekhonkhobe ] * rm usage of camelcase in cache.py doc (closes: #626617) * grammar fix in the cache.py doc (closes: #626610) - * apt/debfile.py: Remove the need to explcitly call check() in order - to get output from require_changes and missing_deps - (closes: #624379) -- Michael Vogt Wed, 19 Oct 2011 18:03:42 +0200 diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 501b8f61..e6c475d3 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -88,11 +88,6 @@ class TestDebfilee(unittest.TestCase): "Samuel Lidén Borell ") def test_content(self): - # no python-debian for python3 yet, so fail gracefully - try: - import debian - except ImportError: - return # normal deb = apt.debfile.DebPackage(cache=self.cache) deb.open(os.path.join("data", "test_debs", "gdebi-test11.deb")) @@ -119,6 +114,13 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb") self.assertEqual(deb.filelist, ["./", "usr/", "usr/bin/"]) + def test_check_exception(self): + deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb") + with self.assertRaises(ValueError): + deb.missing_deps + deb.check() + deb.missing_deps + def test_no_supported_data_tar(self): # ensure that a unknown data.tar.xxx raises a exception raised = False -- cgit v1.2.3 From b1c645c534e14bc21da638aefd54d2c59085f3ec Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:09:44 +0100 Subject: tests/test_debfile.py: fix test after previous exception change --- tests/test_debfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_debfile.py b/tests/test_debfile.py index e6c475d3..89f50d2a 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -116,7 +116,7 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading def test_check_exception(self): deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb") - with self.assertRaises(ValueError): + with self.assertRaises(AttributeError): deb.missing_deps deb.check() deb.missing_deps -- cgit v1.2.3 From ff886d6a8c468a31433013250aed337dfe0770cc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:32:56 +0100 Subject: tests/test_debfile.py: remove debug print --- tests/test_debfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 89f50d2a..7619f33d 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -133,7 +133,7 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading self.assertTrue(raised) def test_multiarch_deb(self): - print apt_pkg.get_architectures() + #print apt_pkg.get_architectures() if apt_pkg.get_architectures() != ["amd64", "i386"]: logging.warn("skipping test because running on a non-multiarch system") return -- cgit v1.2.3 From bdf3dfdca30b0d822d267b8453dd1101e864d276 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:45:23 +0100 Subject: tests/test_apt_cache.py: fix test failure by explicitely setting rootdir --- tests/test_apt_cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 0d80f617..74d94ed8 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -182,7 +182,7 @@ class TestAptCache(unittest.TestCase): apt_pkg.config.set("dir::etc::sourceparts", old_source_parts) def test_package_cmp(self): - cache = apt.Cache() + cache = apt.Cache(rootdir="/") l = [] l.append(cache["libc6"]) l.append(cache["xterm"]) -- cgit v1.2.3 From ea348ef49c34f22c8f06cdbcbcae3c2fbc7652fd Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:51:57 +0100 Subject: tests/test_debfile.py: fix test on python2.6 --- tests/test_debfile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 7619f33d..30a2be0a 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -116,8 +116,7 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading def test_check_exception(self): deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb") - with self.assertRaises(AttributeError): - deb.missing_deps + self.assertRaises(AttributeError, lambda: deb.missing_deps) deb.check() deb.missing_deps -- cgit v1.2.3 From d76a13a50fda292fe011a86f2b761d5753dc1470 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Nov 2011 18:58:06 +0100 Subject: tests/test_debfile.py: remove unneeded debug print --- tests/test_debfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 30a2be0a..d7c38b3d 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -137,7 +137,7 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading logging.warn("skipping test because running on a non-multiarch system") return deb = apt.debfile.DebPackage("./data/test_debs/multiarch-test1_i386.deb") - print deb.missing_deps() + #print deb.missing_deps() -- cgit v1.2.3 From c8bfdda85fbd2df250fbc6d3faeb2bd5875a77d6 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Dec 2011 13:32:42 +0100 Subject: py3 fixes/clean --- apt/progress/base.py | 2 ++ tests/test_debfile.py | 4 ++-- tests/test_utils.py | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/apt/progress/base.py b/apt/progress/base.py index 4943978c..c2a9a9c8 100644 --- a/apt/progress/base.py +++ b/apt/progress/base.py @@ -192,12 +192,14 @@ class InstallProgress(object): # and the execution continues in the # parent code leading to very confusing bugs try: + raise Exception("foo") os._exit(obj.do_install(self.write_stream.fileno())) except AttributeError: os._exit(os.spawnlp(os.P_WAIT, "dpkg", "dpkg", "--status-fd", str(self.write_stream.fileno()), "-i", obj)) except Exception as e: + os.write(self.writefd, "pmerror:::%s" % e) sys.stderr.write("%s\n" % e) os._exit(apt_pkg.PackageManager.RESULT_FAILED) diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 501b8f61..56410153 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -131,12 +131,12 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading self.assertTrue(raised) def test_multiarch_deb(self): - print apt_pkg.get_architectures() if apt_pkg.get_architectures() != ["amd64", "i386"]: logging.warn("skipping test because running on a non-multiarch system") return deb = apt.debfile.DebPackage("./data/test_debs/multiarch-test1_i386.deb") - print deb.missing_deps() + res = deb.check() + # FIXME: do something sensible with the multiarch test diff --git a/tests/test_utils.py b/tests/test_utils.py index 23511f32..26ee0bff 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -7,7 +7,6 @@ # notice and this notice are preserved. import sys -sys.path.insert(0, "..") import apt_pkg import apt.utils import datetime -- cgit v1.2.3 From fb595849bc7149619b3e47b65f145a1f66fc7dbe Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 1 Dec 2011 13:45:58 +0100 Subject: fix debfile binary test for py3 --- apt/debfile.py | 11 +++++++++-- tests/test_debfile.py | 5 ----- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/apt/debfile.py b/apt/debfile.py index 104b0814..4a82842a 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -525,12 +525,19 @@ class DebPackage(object): @staticmethod def to_strish(in_data): + # helper for py3 compat, in_data is str in py2 and bytes in py3 + def my_ord(c): + if type(c) == int: + return c + else: + return ord(c) + # convert s = "" for c in in_data: - if ord(c) < 10 or ord(c) > 127: + if my_ord(c) < 10 or my_ord(c) > 127: s += " " else: - s += c + s += chr(c) return s def _get_content(self, part, name, auto_decompress=True, auto_hex=True): diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 56410153..70979689 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -88,11 +88,6 @@ class TestDebfilee(unittest.TestCase): "Samuel Lidén Borell ") def test_content(self): - # no python-debian for python3 yet, so fail gracefully - try: - import debian - except ImportError: - return # normal deb = apt.debfile.DebPackage(cache=self.cache) deb.open(os.path.join("data", "test_debs", "gdebi-test11.deb")) -- cgit v1.2.3