File: build-deps.py

package info (click to toggle)
python-apt 0.7.7.1%2Bnmu1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,276 kB
  • ctags: 930
  • sloc: cpp: 4,126; python: 3,108; makefile: 52
file content (72 lines) | stat: -rwxr-xr-x 2,044 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
# this is a example how to access the build dependencies of a package

import apt_pkg
import sys
import sets    # only needed for python2.3, python2.4 supports this naively 

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.GetCache()
depcache = apt_pkg.GetDepCache(cache)
depcache.Init()
records = apt_pkg.GetPkgRecords(cache)
srcrecords = apt_pkg.GetPkgSrcRecords()

# 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:
	base = cache[sys.argv[1]]
except KeyError:
	print "No package %s found" % sys.argv[1]
	sys.exit(1)
all_build_depends = sets.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)