From f841101c94f1b5892f042ecab2c0c74e9b947c8c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 9 Dec 2011 09:16:08 +0100 Subject: tests/test_apt_cache.py: use intltool instead of libc6 as the later is not available on ia64 or kfreebsd --- tests/test_apt_cache.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 2bc19353..448aed75 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -190,12 +190,12 @@ class TestAptCache(unittest.TestCase): def test_package_cmp(self): cache = apt.Cache(rootdir="/") l = [] - l.append(cache["libc6"]) + l.append(cache["intltool"]) l.append(cache["python3"]) l.append(cache["apt"]) l.sort() self.assertEqual([p.name for p in l], - ["apt", "libc6", "python3"]) + ["apt", "intltool", "python3"]) def test_get_architectures(self): main_arch = apt.apt_pkg.config.get("APT::Architecture") -- cgit v1.2.3 From 10ec8cd5b5614606b3db9fdc3d6e248984048f0e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 19 Dec 2011 12:06:06 +0100 Subject: * apt/debfile.py: - fix crash in dep multiarch handling --- apt/debfile.py | 3 ++- debian/changelog | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apt/debfile.py b/apt/debfile.py index 160a4a72..cd027c71 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -94,7 +94,8 @@ class DebPackage(object): return pkgname elif self._cache.is_virtual_package(pkgname): return pkgname - elif self._cache[pkgname].candidate.architecture == "all": + elif (pkgname in self._cache and + self._cache[pkgname].candidate.architecture == "all"): return pkgname # now do the real multiarch checking multiarch_pkgname = "%s:%s" % (pkgname, self._multiarch) diff --git a/debian/changelog b/debian/changelog index fcf8ff98..df486b60 100644 --- a/debian/changelog +++ b/debian/changelog @@ -8,6 +8,8 @@ python-apt (0.8.3) unstable; urgency=low - add multiarch support to the debfile.py code * tests/test_apt_cache.py: - add additional check if provides test can actually be run + * apt/debfile.py: + - fix crash in dep multiarch handling -- Michael Vogt Thu, 08 Dec 2011 20:31:52 +0100 -- cgit v1.2.3 From 375920c5172a5f60acba02b73c3b32ffbccc8ab2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 19 Dec 2011 13:35:59 +0100 Subject: pyflakes cleanup, use apt_pkg.gettext in aptsources too --- apt/debfile.py | 12 ++---------- apt/progress/gtk2.py | 3 --- aptsources/distinfo.py | 6 +----- aptsources/distro.py | 4 +--- aptsources/sourceslist.py | 3 +-- 5 files changed, 5 insertions(+), 23 deletions(-) diff --git a/apt/debfile.py b/apt/debfile.py index cd027c71..ab24c50b 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -160,10 +160,6 @@ class DebPackage(object): def _satisfy_or_group(self, or_group): """Try to satisfy the or_group.""" - - or_found = False - virtual_pkg = None - for dep in or_group: depname, ver, oper = dep @@ -233,10 +229,6 @@ class DebPackage(object): def _check_conflicts_or_group(self, or_group): """Check the or-group for conflicts with installed pkgs.""" self._dbg(2, "_check_conflicts_or_group(): %s " % (or_group)) - - or_found = False - virtual_pkg = None - for dep in or_group: depname = dep[0] ver = dep[1] @@ -514,7 +506,7 @@ class DebPackage(object): for pkg in self._need_pkgs: try: self._cache[pkg].mark_install(from_user=False) - except SystemError as e: + except SystemError: self._failure_string = _("Cannot install '%s'") % pkg self._cache.clear() return False @@ -607,7 +599,7 @@ class DebPackage(object): # auto-convert to hex try: data = unicode(data, "utf-8") - except Exception as e: + except Exception: new_data = _("Automatically converted to printable ascii:\n") new_data += self.to_strish(data) return new_data diff --git a/apt/progress/gtk2.py b/apt/progress/gtk2.py index b5794e92..c2635ca0 100644 --- a/apt/progress/gtk2.py +++ b/apt/progress/gtk2.py @@ -22,9 +22,6 @@ # USA """GObject-powered progress classes and a GTK+ status widget.""" -import os -import time - import pygtk pygtk.require('2.0') import gtk diff --git a/aptsources/distinfo.py b/aptsources/distinfo.py index c8ec5c46..ec162c2d 100644 --- a/aptsources/distinfo.py +++ b/aptsources/distinfo.py @@ -24,17 +24,13 @@ import errno import logging import os -import gettext from os import getenv from subprocess import Popen, PIPE import re import apt_pkg - -def _(s): - return gettext.dgettext("python-apt", s) - +from apt_pkg import gettext as _ class Template(object): diff --git a/aptsources/distro.py b/aptsources/distro.py index f777a4ea..b4056b27 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -30,9 +30,7 @@ import sys from xml.etree.ElementTree import ElementTree import gettext - -def _(s): - return gettext.dgettext("python-apt", s) +from apt_pkg import gettext as _ class NoDistroTemplateException(Exception): diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index 40a0379b..e3b8c9be 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -23,7 +23,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import gettext import glob import logging import os.path @@ -35,6 +34,7 @@ import time import apt_pkg from distinfo import DistInfo from apt.deprecation import function_deprecated_by +from apt_pkg import gettext as _ # some global helpers @@ -446,7 +446,6 @@ class SourceEntryMatcher(object): def match(self, source): """Add a matching template to the source""" - _ = gettext.gettext found = False for template in self.templates: if (re.search(template.match_uri, source.uri) and -- cgit v1.2.3 From 1fc5fddddd6041eb17331d9943f7f489bd53314a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 4 Jan 2012 14:20:55 +0100 Subject: * doc/examples/build-deps.py: - update the build-deps.py example to use the apt API more --- debian/changelog | 7 ++++ doc/examples/build-deps-old.py | 73 ++++++++++++++++++++++++++++++++++++++++++ doc/examples/build-deps.py | 55 +++++++++++-------------------- 3 files changed, 99 insertions(+), 36 deletions(-) create mode 100755 doc/examples/build-deps-old.py diff --git a/debian/changelog b/debian/changelog index df486b60..7f582bff 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +python-apt (0.8.4) UNRELEASED; urgency=low + + * doc/examples/build-deps.py: + - update the build-deps.py example to use the apt API more + + -- Michael Vogt Wed, 04 Jan 2012 12:07:48 +0100 + python-apt (0.8.3) unstable; urgency=low [ Alexey Feldgendler ] diff --git a/doc/examples/build-deps-old.py b/doc/examples/build-deps-old.py new file mode 100755 index 00000000..656f1361 --- /dev/null +++ b/doc/examples/build-deps-old.py @@ -0,0 +1,73 @@ +#!/usr/bin/python +# this is a example how to access the build dependencies of a package + +import apt_pkg +import sys + + +def get_source_pkg(pkg, records, depcache): + """ get the source package name of a given package """ + version = depcache.GetCandidateVer(pkg) + if not version: + return None + file, index = version.FileList.pop(0) + records.Lookup((file, index)) + if records.SourcePkg != "": + srcpkg = records.SourcePkg + else: + srcpkg = pkg.Name + return srcpkg + + +# main +apt_pkg.init() +cache = apt_pkg.Cache() +depcache = apt_pkg.DepCache(cache) +depcache.Init() +records = apt_pkg.PackageRecords(cache) +srcrecords = apt_pkg.SourceRecords() + +# base package that we use for build-depends calculation +if len(sys.argv) < 2: + print "need a package name as argument" + sys.exit(1) +try: + pkg = base = cache[sys.argv[1]] +except KeyError: + print "No package %s found" % sys.argv[1] + sys.exit(1) +all_build_depends = set() + +# get the build depdends for the package itself +srcpkg_name = get_source_pkg(base, records, depcache) +print "srcpkg_name: %s " % srcpkg_name +if not srcpkg_name: + print "Can't find source package for '%s'" % pkg.Name +srcrec = srcrecords.Lookup(srcpkg_name) +if srcrec: + print "Files:" + print srcrecords.Files + bd = srcrecords.BuildDepends + print "build-depends of the package: %s " % bd + for b in bd: + all_build_depends.add(b[0]) + +# calculate the build depends for all dependencies +depends = depcache.GetCandidateVer(base).DependsList +for dep in depends["Depends"]: # FIXME: do we need to consider PreDepends? + pkg = dep[0].TargetPkg + srcpkg_name = get_source_pkg(pkg, records, depcache) + if not srcpkg_name: + print "Can't find source package for '%s'" % pkg.Name + continue + srcrec = srcrecords.Lookup(srcpkg_name) + if srcrec: + #print srcrecords.Package + #print srcrecords.Binaries + bd = srcrecords.BuildDepends + #print "%s: %s " % (srcpkg_name, bd) + for b in bd: + all_build_depends.add(b[0]) + + +print "\n".join(all_build_depends) diff --git a/doc/examples/build-deps.py b/doc/examples/build-deps.py index 656f1361..5d243943 100755 --- a/doc/examples/build-deps.py +++ b/doc/examples/build-deps.py @@ -1,30 +1,12 @@ #!/usr/bin/python # this is a example how to access the build dependencies of a package +import apt import apt_pkg import sys - -def get_source_pkg(pkg, records, depcache): - """ get the source package name of a given package """ - version = depcache.GetCandidateVer(pkg) - if not version: - return None - file, index = version.FileList.pop(0) - records.Lookup((file, index)) - if records.SourcePkg != "": - srcpkg = records.SourcePkg - else: - srcpkg = pkg.Name - return srcpkg - - # main -apt_pkg.init() -cache = apt_pkg.Cache() -depcache = apt_pkg.DepCache(cache) -depcache.Init() -records = apt_pkg.PackageRecords(cache) +cache = apt.Cache() srcrecords = apt_pkg.SourceRecords() # base package that we use for build-depends calculation @@ -39,7 +21,7 @@ except KeyError: all_build_depends = set() # get the build depdends for the package itself -srcpkg_name = get_source_pkg(base, records, depcache) +srcpkg_name = base.candidate.source_name print "srcpkg_name: %s " % srcpkg_name if not srcpkg_name: print "Can't find source package for '%s'" % pkg.Name @@ -53,21 +35,22 @@ if srcrec: all_build_depends.add(b[0]) # calculate the build depends for all dependencies -depends = depcache.GetCandidateVer(base).DependsList -for dep in depends["Depends"]: # FIXME: do we need to consider PreDepends? - pkg = dep[0].TargetPkg - srcpkg_name = get_source_pkg(pkg, records, depcache) - if not srcpkg_name: - print "Can't find source package for '%s'" % pkg.Name - continue - srcrec = srcrecords.Lookup(srcpkg_name) - if srcrec: - #print srcrecords.Package - #print srcrecords.Binaries - bd = srcrecords.BuildDepends - #print "%s: %s " % (srcpkg_name, bd) - for b in bd: - all_build_depends.add(b[0]) +depends = base.candidate.dependencies +for or_dep in depends: + for dep in or_dep.or_dependencies: + pkg = cache[dep.name] + srcpkg_name = pkg.candidate.source_name + if not srcpkg_name: + print "Can't find source package for '%s'" % pkg.Name + continue + srcrec = srcrecords.Lookup(srcpkg_name) + if srcrec: + #print srcrecords.Package + #print srcrecords.Binaries + bd = srcrecords.BuildDepends + #print "%s: %s " % (srcpkg_name, bd) + for b in bd: + all_build_depends.add(b[0]) print "\n".join(all_build_depends) -- cgit v1.2.3 From 6c8269fc130c66d4a450a004af4e120e074808ce Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 10 Jan 2012 11:07:12 +0100 Subject: pyflakes fixes --- aptsources/distinfo.py | 1 - aptsources/distro.py | 4 +--- aptsources/sourceslist.py | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/aptsources/distinfo.py b/aptsources/distinfo.py index ec162c2d..ddaeb218 100644 --- a/aptsources/distinfo.py +++ b/aptsources/distinfo.py @@ -24,7 +24,6 @@ import errno import logging import os -from os import getenv from subprocess import Popen, PIPE import re diff --git a/aptsources/distro.py b/aptsources/distro.py index b4056b27..27d7f859 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -25,10 +25,8 @@ import gettext import logging import re import os -import sys from xml.etree.ElementTree import ElementTree -import gettext from apt_pkg import gettext as _ @@ -94,7 +92,7 @@ class Distribution(object): comps = [] cdrom_comps = [] enabled_comps = [] - source_code = [] + #source_code = [] for source in self.sourceslist.list: if (source.invalid == False and self.is_codename(source.dist) and diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index e3b8c9be..03377258 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -28,13 +28,12 @@ import logging import os.path import re import shutil -import sys import time import apt_pkg from distinfo import DistInfo from apt.deprecation import function_deprecated_by -from apt_pkg import gettext as _ +#from apt_pkg import gettext as _ # some global helpers -- cgit v1.2.3 From 2021c1b4973c3201b1e4580d00b7351c23a831c4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 30 Jan 2012 15:25:37 +0100 Subject: RED: policy should support verfile --- po/python-apt.pot | 50 +++++++++++++++++++++++++------------------------- python/cache.cc | 7 +++++++ tests/test_policy.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 tests/test_policy.py diff --git a/po/python-apt.pot b/po/python-apt.pot index f1aecc59..a7cf0a8d 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-12-08 20:01+0100\n" +"POT-Creation-Date: 2012-01-30 15:16+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -410,7 +410,7 @@ msgid "Non-DFSG-compatible Software" msgstr "" #. TRANSLATORS: %s is a country -#: ../aptsources/distro.py:210 ../aptsources/distro.py:438 +#: ../aptsources/distro.py:206 ../aptsources/distro.py:434 #, python-format msgid "Server for %s" msgstr "" @@ -418,35 +418,35 @@ msgstr "" #. 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 -#: ../aptsources/distro.py:228 ../aptsources/distro.py:234 -#: ../aptsources/distro.py:250 +#: ../aptsources/distro.py:224 ../aptsources/distro.py:230 +#: ../aptsources/distro.py:246 msgid "Main server" msgstr "" -#: ../aptsources/distro.py:254 +#: ../aptsources/distro.py:250 msgid "Custom servers" msgstr "" -#: ../apt/progress/gtk2.py:261 ../apt/progress/gtk2.py:317 +#: ../apt/progress/gtk2.py:258 ../apt/progress/gtk2.py:314 #, python-format msgid "Downloading file %(current)li of %(total)li with %(speed)s/s" msgstr "" -#: ../apt/progress/gtk2.py:267 ../apt/progress/gtk2.py:323 +#: ../apt/progress/gtk2.py:264 ../apt/progress/gtk2.py:320 #, python-format msgid "Downloading file %(current)li of %(total)li" msgstr "" #. Setup some child widgets -#: ../apt/progress/gtk2.py:343 +#: ../apt/progress/gtk2.py:340 msgid "Details" msgstr "" -#: ../apt/progress/gtk2.py:431 +#: ../apt/progress/gtk2.py:428 msgid "Starting..." msgstr "" -#: ../apt/progress/gtk2.py:437 +#: ../apt/progress/gtk2.py:434 msgid "Complete" msgstr "" @@ -479,18 +479,18 @@ msgstr "" msgid "List of files for '%s' could not be read" msgstr "" -#: ../apt/debfile.py:205 +#: ../apt/debfile.py:202 #, python-format msgid "Dependency is not satisfiable: %s\n" msgstr "" -#: ../apt/debfile.py:226 +#: ../apt/debfile.py:223 #, python-format msgid "Conflicts with the installed package '%s'" msgstr "" #. TRANSLATORS: the first '%s' is the package that breaks, the second the dependency that makes it break, the third the relation (e.g. >=) and the latest the version for the releation -#: ../apt/debfile.py:371 +#: ../apt/debfile.py:364 #, python-format msgid "" "Breaks existing package '%(pkgname)s' dependency %(depname)s " @@ -498,63 +498,63 @@ msgid "" msgstr "" #. TRANSLATORS: the first '%s' is the package that conflicts, the second the packagename that it conflicts with (so the name of the deb the user tries to install), the third is the relation (e.g. >=) and the last is the version for the relation -#: ../apt/debfile.py:387 +#: ../apt/debfile.py:380 #, python-format msgid "" "Breaks existing package '%(pkgname)s' conflict: %(targetpkg)s (%(comptype)s " "%(targetver)s)" msgstr "" -#: ../apt/debfile.py:397 +#: ../apt/debfile.py:390 #, python-format msgid "" "Breaks existing package '%(pkgname)s' that conflict: '%(targetpkg)s'. But " "the '%(debfile)s' provides it via: '%(provides)s'" msgstr "" -#: ../apt/debfile.py:445 +#: ../apt/debfile.py:438 msgid "No Architecture field in the package" msgstr "" -#: ../apt/debfile.py:455 +#: ../apt/debfile.py:448 #, python-format msgid "Wrong architecture '%s'" msgstr "" #. the deb is older than the installed -#: ../apt/debfile.py:462 +#: ../apt/debfile.py:455 msgid "A later version is already installed" msgstr "" -#: ../apt/debfile.py:487 +#: ../apt/debfile.py:480 msgid "Failed to satisfy all dependencies (broken cache)" msgstr "" -#: ../apt/debfile.py:517 +#: ../apt/debfile.py:510 #, python-format msgid "Cannot install '%s'" msgstr "" -#: ../apt/debfile.py:561 +#: ../apt/debfile.py:554 msgid "Python-debian module not available" msgstr "" -#: ../apt/debfile.py:604 +#: ../apt/debfile.py:597 msgid "" "Automatically decompressed:\n" "\n" msgstr "" -#: ../apt/debfile.py:610 +#: ../apt/debfile.py:603 msgid "Automatically converted to printable ascii:\n" msgstr "" -#: ../apt/debfile.py:700 +#: ../apt/debfile.py:693 #, python-format msgid "Install Build-Dependencies for source package '%s' that builds %s\n" msgstr "" -#: ../apt/debfile.py:711 +#: ../apt/debfile.py:704 msgid "An essential package would be removed" msgstr "" diff --git a/python/cache.cc b/python/cache.cc index b263d320..191e2204 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -229,6 +229,12 @@ static PyObject *PkgCacheGetGroups(PyObject *Self, void*) { return CppPyObject_NEW(Self,&PyGroupList_Type,Cache->GrpBegin()); } +static PyObject *PkgCacheGetPolicy(PyObject *Self, void*) { + pkgCacheFile *CacheFile = GetCpp(Self); + std::cerr << "policy: " << CacheFile->Policy << std::endl; + return CppPyObject_NEW(Self,&PyPolicy_Type,CacheFile->Policy); +} + static PyObject *PkgCacheGetPackages(PyObject *Self, void*) { pkgCache *Cache = GetCpp(Self); return CppPyObject_NEW(Self,&PyPackageList_Type,Cache->PkgBegin()); @@ -289,6 +295,7 @@ static PyGetSetDef PkgCacheGetSet[] = { {"group_count",PkgCacheGetGroupCount,0, "The number of apt_pkg.Group objects stored in the cache."}, {"groups", PkgCacheGetGroups, 0, "A list of Group objects in the cache"}, + {"policy", PkgCacheGetPolicy, 0, "The PkgPolicy for the cache"}, {"is_multi_arch", PkgCacheGetIsMultiArch, 0, "Whether the cache supports multi-arch."}, {"package_count",PkgCacheGetPackageCount,0, diff --git a/tests/test_policy.py b/tests/test_policy.py new file mode 100644 index 00000000..2d261f5f --- /dev/null +++ b/tests/test_policy.py @@ -0,0 +1,31 @@ +#!/usr/bin/python +# +# Copyright (C) 2012 Michael Vogt +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. + +import apt +import unittest + +class TestAptPolicy(unittest.TestCase): + + def test_apt_policy(self): + # get a policy + cache = apt.Cache() + policy = cache._depcache.policy + self.assertNotEqual(policy, None) + # basic tests + pkg = cache["apt"] + self.assertEqual(policy.get_priority(pkg._pkg), 0) + # get verfile + ver = pkg.candidate._cand + verfile_list = ver.file_list + for verfile in verfile_list: + print verfile + self.assertEqual(policy.get_priority(verfile), 500) + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3 From 00ce4d227aef4ccde15f8cfa5b1a5582195eb639 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 30 Jan 2012 15:33:24 +0100 Subject: GREEN: policy should suppors PkgVerFile now --- po/python-apt.pot | 2 +- python/policy.cc | 3 +++ tests/test_policy.py | 13 +++++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/po/python-apt.pot b/po/python-apt.pot index a7cf0a8d..b99c36e1 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: 2012-01-30 15:16+0100\n" +"POT-Creation-Date: 2012-01-30 15:32+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/policy.cc b/python/policy.cc index b11e4dde..b7e648b5 100644 --- a/python/policy.cc +++ b/python/policy.cc @@ -46,6 +46,9 @@ PyObject *policy_get_priority(PyObject *self, PyObject *arg) { if (PyObject_TypeCheck(arg, &PyPackage_Type)) { pkgCache::PkgIterator pkg = GetCpp(arg); return MkPyNumber(policy->GetPriority(pkg)); + } else if (PyObject_TypeCheck(arg, &PyPackageFile_Type)) { + pkgCache::PkgFileIterator pkgfile = GetCpp(arg); + return MkPyNumber(policy->GetPriority(pkgfile)); } else { PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); return 0; diff --git a/tests/test_policy.py b/tests/test_policy.py index 2d261f5f..2aab6722 100644 --- a/tests/test_policy.py +++ b/tests/test_policy.py @@ -19,12 +19,13 @@ class TestAptPolicy(unittest.TestCase): # basic tests pkg = cache["apt"] self.assertEqual(policy.get_priority(pkg._pkg), 0) - # get verfile - ver = pkg.candidate._cand - verfile_list = ver.file_list - for verfile in verfile_list: - print verfile - self.assertEqual(policy.get_priority(verfile), 500) + # get priority for all pkgfiles + for ver in pkg.versions: + lowlevel_ver = ver._cand + for pkgfile, i in lowlevel_ver.file_list: + #print verfile, i, policy.get_priority(pkgfile) + self.assertTrue(policy.get_priority(pkgfile) > 1) + self.assertTrue(policy.get_priority(pkgfile) < 1001) if __name__ == "__main__": -- cgit v1.2.3 From 38165cbeb26313bb468dcf527a843ba55571a8f2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 30 Jan 2012 15:39:42 +0100 Subject: REFACTOR: python/policy.cc update error to include PackageFile() too --- python/policy.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/policy.cc b/python/policy.cc index b7e648b5..96b83abd 100644 --- a/python/policy.cc +++ b/python/policy.cc @@ -50,7 +50,7 @@ PyObject *policy_get_priority(PyObject *self, PyObject *arg) { pkgCache::PkgFileIterator pkgfile = GetCpp(arg); return MkPyNumber(policy->GetPriority(pkgfile)); } else { - PyErr_SetString(PyExc_TypeError,"Argument must be of Package()."); + PyErr_SetString(PyExc_TypeError,"Argument must be of Package() or PackageFile()."); return 0; } } -- cgit v1.2.3 From 055dc32f4025f081293cee32cde935100532c651 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 30 Jan 2012 15:40:50 +0100 Subject: RED: apt.Version should have "policy_priority" property --- debian/changelog | 1 + po/python-apt.pot | 2 +- tests/test_policy.py | 10 ++++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index 7f582bff..1e400dfb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,7 @@ python-apt (0.8.4) UNRELEASED; urgency=low * doc/examples/build-deps.py: - update the build-deps.py example to use the apt API more + * add support for apt_pkg.Policy.get_priority(PkgFileIterator) -- Michael Vogt Wed, 04 Jan 2012 12:07:48 +0100 diff --git a/po/python-apt.pot b/po/python-apt.pot index b99c36e1..58877b55 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: 2012-01-30 15:32+0100\n" +"POT-Creation-Date: 2012-01-30 15:40+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/tests/test_policy.py b/tests/test_policy.py index 2aab6722..449c3961 100644 --- a/tests/test_policy.py +++ b/tests/test_policy.py @@ -11,7 +11,7 @@ import unittest class TestAptPolicy(unittest.TestCase): - def test_apt_policy(self): + def test_apt_policy_lowlevel(self): # get a policy cache = apt.Cache() policy = cache._depcache.policy @@ -23,10 +23,16 @@ class TestAptPolicy(unittest.TestCase): for ver in pkg.versions: lowlevel_ver = ver._cand for pkgfile, i in lowlevel_ver.file_list: - #print verfile, i, policy.get_priority(pkgfile) + print pkgfile, i, policy.get_priority(pkgfile) self.assertTrue(policy.get_priority(pkgfile) > 1) self.assertTrue(policy.get_priority(pkgfile) < 1001) + def test_apt_policy_highlevel(self): + cache = apt.Cache() + pkg = cache["apt"] + self.assertTrue(pkg.candidate.policy_priority > 1 and + pkg.candidate.policy_priority < 1001) + if __name__ == "__main__": unittest.main() -- cgit v1.2.3 From accf60bda95e6a1bad53f26412b12a32f136d54d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 31 Jan 2012 14:52:42 +0100 Subject: * apt/debfile.py: - use apt_inst for reading the control_filelist * debian/control: - remove no longer needed dependency on python-debian --- apt/debfile.py | 37 ++++++++++++++++++++----------------- debian/changelog | 4 ++++ debian/control | 1 - 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/apt/debfile.py b/apt/debfile.py index ab24c50b..6a189502 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -40,8 +40,12 @@ class DebPackage(object): VERSION_SAME, VERSION_NEWER) = range(4) - _supported_data_members = ("data.tar.gz", "data.tar.bz2", "data.tar.lzma", - "data.tar.xz") + _supported_data_members = ( + "data.tar.gz", + "data.tar.bz2", + "data.tar.lzma", + "data.tar.xz", + ) debug = 0 @@ -82,10 +86,22 @@ class DebPackage(object): try: self._debfile.data.go(lambda item, data: files.append(item.name)) except SystemError: - return [_("List of files for '%s' could not be read" % - self.filename)] + return [_("List of files for '%s' could not be read") % + self.filename] return files + @property + def control_filelist(self): + """ return the list of files in control.tar.gt """ + control = [] + try: + self._debfile.control.go(lambda item, data: control.append(item.name)) + except SystemError: + return [_("List of control files for '%s' could not be read") % + self.filename] + return sorted(control) + + # helper that will return a pkgname with a multiarch suffix if needed def _maybe_append_multiarch_suffix(self, pkgname, in_conflict_checking=False): @@ -545,19 +561,6 @@ class DebPackage(object): remove.append(pkg.name) return (install, remove, unauthenticated) - @property - def control_filelist(self): - """ return the list of files in control.tar.gt """ - try: - from debian.debfile import DebFile - except: - raise Exception(_("Python-debian module not available")) - content = [] - for name in DebFile(self.filename).control: - if name and name != ".": - content.append(name) - return sorted(content) - @staticmethod def to_hex(in_data): hex = "" diff --git a/debian/changelog b/debian/changelog index 1e400dfb..17fe379e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,10 @@ python-apt (0.8.4) UNRELEASED; urgency=low * doc/examples/build-deps.py: - update the build-deps.py example to use the apt API more * add support for apt_pkg.Policy.get_priority(PkgFileIterator) + * apt/debfile.py: + - use apt_inst for reading the control_filelist + * debian/control: + - remove no longer needed dependency on python-debian -- Michael Vogt Wed, 04 Jan 2012 12:07:48 +0100 diff --git a/debian/control b/debian/control index 541e4c36..29392858 100644 --- a/debian/control +++ b/debian/control @@ -27,7 +27,6 @@ Breaks: packagekit-backend-apt (<= 0.4.8-0ubuntu4), computer-janitor (<< 1.14.1-1+), debdelta (<< 0.41+), python-dogtail (<< 0.6.1-3.1+), - python-debian (<< 0.1.18+), python-software-properties (<< 0.70.debian-1+), aptdaemon (<< 0.11+bzr343-1~), apt-forktracer (<< 0.3), -- cgit v1.2.3 From 6f538d96ec35e80e19f1b33cad86b9ae45da54f5 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 31 Jan 2012 14:58:14 +0100 Subject: apt/debfile.py: kill _supported_data_members its actually not used anymore and instead done dynamically in arfile.cc using the APT::Configuration::getCompressionTypes() call (yeah!) --- apt/debfile.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/apt/debfile.py b/apt/debfile.py index 6a189502..2eb807b8 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -40,13 +40,6 @@ class DebPackage(object): VERSION_SAME, VERSION_NEWER) = range(4) - _supported_data_members = ( - "data.tar.gz", - "data.tar.bz2", - "data.tar.lzma", - "data.tar.xz", - ) - debug = 0 def __init__(self, filename=None, cache=None): -- cgit v1.2.3