summaryrefslogtreecommitdiff
path: root/doc/examples/build-deps.py
blob: c00e60e63a18131ef700bef80bc2f8aff77d911f (plain)
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
#!/usr/bin/python

import apt_pkg
import sys


def get_source_pkg(pkg, records, depcache):
	# FIXME: use candidate version here
	version = depcache.GetCandidateVer(pkg)
	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 pkgname as argument"
base = cache[sys.argv[1]]
all_build_depends = set()

depends = base.CurrentVer.DependsList
for dep in depends["Depends"]:
	pkg = dep[0].TargetPkg
	srcpkg_name = get_source_pkg(pkg, records, depcache)
	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)