summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog7
-rwxr-xr-xdoc/examples/build-deps-old.py73
-rwxr-xr-xdoc/examples/build-deps.py55
3 files changed, 99 insertions, 36 deletions
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 <michael.vogt@ubuntu.com> 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)