summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt/debfile.py32
-rw-r--r--apt/package.py11
-rw-r--r--aptsources/distinfo.py1
-rw-r--r--aptsources/distro.py4
-rw-r--r--aptsources/sourceslist.py3
-rw-r--r--debian/changelog12
-rw-r--r--debian/control1
-rwxr-xr-xdoc/examples/build-deps-old.py73
-rwxr-xr-xdoc/examples/build-deps.py55
-rw-r--r--po/python-apt.pot56
-rw-r--r--python/cache.cc7
-rw-r--r--python/policy.cc5
-rw-r--r--tests/test_policy.py39
13 files changed, 209 insertions, 90 deletions
diff --git a/apt/debfile.py b/apt/debfile.py
index ab24c50b..2eb807b8 100644
--- a/apt/debfile.py
+++ b/apt/debfile.py
@@ -40,9 +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):
@@ -82,10 +79,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 +554,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/apt/package.py b/apt/package.py
index 81f33a8b..73f68c87 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -409,6 +409,17 @@ class Version(object):
return self._cand.priority_str
@property
+ def policy_priority(self):
+ """Return the internal policy priority as a number.
+ See apt_preferences(5) for more information about what it means.
+ """
+ priority = 0
+ policy = self.package._pcache._depcache.policy
+ for (packagefile, _) in self._cand.file_list:
+ priority = max(priority, policy.get_priority(packagefile))
+ return priority
+
+ @property
def record(self):
"""Return a Record() object for this version.
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
diff --git a/debian/changelog b/debian/changelog
index 908843e7..4deb8b3b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,15 @@
+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 <michael.vogt@ubuntu.com> Wed, 04 Jan 2012 12:07:48 +0100
+
python-apt (0.8.3.1) UNRELEASED; urgency=low
* tests/test_apt_cache.py:
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),
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)
diff --git a/po/python-apt.pot b/po/python-apt.pot
index f1aecc59..02c65f13 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:44+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""
@@ -455,11 +455,11 @@ msgstr ""
msgid "Invalid unicode in description for '%s' (%s). Please report."
msgstr ""
-#: ../apt/package.py:1074 ../apt/package.py:1180
+#: ../apt/package.py:1085 ../apt/package.py:1191
msgid "The list of changes is not available"
msgstr ""
-#: ../apt/package.py:1186
+#: ../apt/package.py:1197
#, 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:1193
+#: ../apt/package.py:1204
msgid ""
"Failed to download the list of changes. \n"
"Please check your Internet connection."
@@ -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<GrpListStruct>(Self,&PyGroupList_Type,Cache->GrpBegin());
}
+static PyObject *PkgCacheGetPolicy(PyObject *Self, void*) {
+ pkgCacheFile *CacheFile = GetCpp<pkgCacheFile *>(Self);
+ std::cerr << "policy: " << CacheFile->Policy << std::endl;
+ return CppPyObject_NEW<pkgPolicy*>(Self,&PyPolicy_Type,CacheFile->Policy);
+}
+
static PyObject *PkgCacheGetPackages(PyObject *Self, void*) {
pkgCache *Cache = GetCpp<pkgCache *>(Self);
return CppPyObject_NEW<PkgListStruct>(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/python/policy.cc b/python/policy.cc
index b11e4dde..96b83abd 100644
--- a/python/policy.cc
+++ b/python/policy.cc
@@ -46,8 +46,11 @@ PyObject *policy_get_priority(PyObject *self, PyObject *arg) {
if (PyObject_TypeCheck(arg, &PyPackage_Type)) {
pkgCache::PkgIterator pkg = GetCpp<pkgCache::PkgIterator>(arg);
return MkPyNumber(policy->GetPriority(pkg));
+ } else if (PyObject_TypeCheck(arg, &PyPackageFile_Type)) {
+ pkgCache::PkgFileIterator pkgfile = GetCpp<pkgCache::PkgFileIterator>(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;
}
}
diff --git a/tests/test_policy.py b/tests/test_policy.py
new file mode 100644
index 00000000..d77fb27e
--- /dev/null
+++ b/tests/test_policy.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2012 Michael Vogt <mvo@ubuntu.com>
+#
+# 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_lowlevel(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 priority for all pkgfiles
+ for ver in pkg.versions:
+ lowlevel_ver = ver._cand
+ for pkgfile, i in lowlevel_ver.file_list:
+ #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()