diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2012-01-04 14:20:55 +0100 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2012-01-04 14:20:55 +0100 |
| commit | 1fc5fddddd6041eb17331d9943f7f489bd53314a (patch) | |
| tree | f208681ce77aa7c6059342a550d921dd6a082022 /doc/examples/build-deps.py | |
| parent | 375920c5172a5f60acba02b73c3b32ffbccc8ab2 (diff) | |
| download | python-apt-1fc5fddddd6041eb17331d9943f7f489bd53314a.tar.gz | |
* doc/examples/build-deps.py:
- update the build-deps.py example to use the apt API more
Diffstat (limited to 'doc/examples/build-deps.py')
| -rwxr-xr-x | doc/examples/build-deps.py | 55 |
1 files changed, 19 insertions, 36 deletions
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) |
