diff options
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/examples/all_deps.py | 34 | ||||
| -rw-r--r-- | doc/examples/indexfile.py | 1 | ||||
| -rwxr-xr-x | doc/examples/print_uris.py | 22 | ||||
| -rw-r--r-- | doc/examples/sources.py | 4 |
4 files changed, 59 insertions, 2 deletions
diff --git a/doc/examples/all_deps.py b/doc/examples/all_deps.py new file mode 100644 index 00000000..f4f1741c --- /dev/null +++ b/doc/examples/all_deps.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python
+
+import sys
+import apt
+
+
+def dependencies(cache, pkg, deps, key="Depends"):
+ #print "pkg: %s (%s)" % (pkg.name, deps)
+ candver = cache._depcache.GetCandidateVer(pkg._pkg)
+ if candver == None:
+ return deps
+ dependslist = candver.DependsList
+ if dependslist.has_key(key):
+ for depVerList in dependslist[key]:
+ for dep in depVerList:
+ if cache.has_key(dep.TargetPkg.Name):
+ if pkg.name != dep.TargetPkg.Name and not dep.TargetPkg.Name in deps:
+ deps.add(dep.TargetPkg.Name)
+ dependencies(cache, cache[dep.TargetPkg.Name], deps, key)
+ return deps
+
+
+pkgname = sys.argv[1]
+c = apt.Cache()
+pkg = c[pkgname]
+
+deps = set()
+
+deps = dependencies(c,pkg, deps, "Depends")
+print " ".join(deps)
+
+preDeps = set()
+preDeps = dependencies(c,pkg, preDeps, "PreDepends")
+print " ".join(preDeps)
diff --git a/doc/examples/indexfile.py b/doc/examples/indexfile.py index 5eaab517..d383fd61 100644 --- a/doc/examples/indexfile.py +++ b/doc/examples/indexfile.py @@ -18,3 +18,4 @@ for (f,i) in cand.FileList: print index.IsTrusted print index.Exists print index.HasPackages + print index.ArchiveURI("some/path") diff --git a/doc/examples/print_uris.py b/doc/examples/print_uris.py new file mode 100755 index 00000000..c8a64223 --- /dev/null +++ b/doc/examples/print_uris.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# +# a example that prints the URIs of all upgradable packages +# + +import apt +import apt_pkg + + +cache = apt.Cache() +upgradable = filter(lambda p: p.isUpgradable, cache) + + +for pkg in upgradable: + pkg._lookupRecord(True) + path = apt_pkg.ParseSection(pkg._records.Record)["Filename"] + cand = pkg._depcache.GetCandidateVer(pkg._pkg) + for (packagefile,i) in cand.FileList: + indexfile = cache._list.FindIndex(packagefile) + if indexfile: + uri = indexfile.ArchiveURI(path) + print uri diff --git a/doc/examples/sources.py b/doc/examples/sources.py index 0a90bae9..c12c6f15 100644 --- a/doc/examples/sources.py +++ b/doc/examples/sources.py @@ -11,5 +11,5 @@ sources = apt_pkg.GetPkgSrcRecords() sources.Restart() while sources.Lookup('hello'): print sources.Package, sources.Version, sources.Maintainer, sources.Section, `sources.Binaries` - #print sources.Files - + print sources.Files + print sources.Index.ArchiveURI("") |
