diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-01-11 19:30:07 +0100 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-01-11 19:30:07 +0100 |
| commit | b237760c6d7009f9833b86e6dbfc3cbf6d059977 (patch) | |
| tree | 19dd8f4f11b1c004a7f9bbb2b9e9f545d0ed2492 /doc | |
| parent | 31cdfa2e20361f76f6e011bbcdad19f9daa1f58f (diff) | |
| parent | 7b14352c54b7acbf2a68240fa960e188c6e8742a (diff) | |
| download | python-apt-b237760c6d7009f9833b86e6dbfc3cbf6d059977.tar.gz | |
Merge Ben Finney's whitespace changes (Closes: #481563)
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/examples/acquire.py | 25 | ||||
| -rw-r--r-- | doc/examples/action.py | 15 | ||||
| -rw-r--r-- | doc/examples/all_deps.py | 70 | ||||
| -rwxr-xr-x | doc/examples/build-deps.py | 76 | ||||
| -rw-r--r-- | doc/examples/cdrom.py | 11 | ||||
| -rwxr-xr-x | doc/examples/checkstate.py | 34 | ||||
| -rwxr-xr-x | doc/examples/config.py | 48 | ||||
| -rwxr-xr-x | doc/examples/configisc.py | 41 | ||||
| -rwxr-xr-x | doc/examples/deb_inspect.py | 12 | ||||
| -rw-r--r-- | doc/examples/depcache.py | 3 | ||||
| -rwxr-xr-x | doc/examples/dependant-pkgs.py | 38 | ||||
| -rw-r--r-- | doc/examples/desc.py | 7 | ||||
| -rwxr-xr-x | doc/examples/gui-inst.py | 4 | ||||
| -rw-r--r-- | doc/examples/indexfile.py | 2 | ||||
| -rw-r--r-- | doc/examples/inst.py | 49 | ||||
| -rw-r--r-- | doc/examples/metaindex.py | 6 | ||||
| -rwxr-xr-x | doc/examples/print_uris.py | 16 | ||||
| -rw-r--r-- | doc/examples/progress.py | 27 | ||||
| -rwxr-xr-x | doc/examples/recommends.py | 44 | ||||
| -rwxr-xr-x | doc/examples/records.py | 11 | ||||
| -rw-r--r-- | doc/examples/sources.py | 7 | ||||
| -rwxr-xr-x | doc/examples/tagfile.py | 6 | ||||
| -rwxr-xr-x | doc/examples/update.py | 2 | ||||
| -rwxr-xr-x | doc/examples/versiontest.py | 56 |
24 files changed, 314 insertions, 296 deletions
diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py index 939c33a2..58372961 100644 --- a/doc/examples/acquire.py +++ b/doc/examples/acquire.py @@ -4,15 +4,15 @@ import os import sys import tempfile + def get_file(fetcher, uri, destFile): - # get the file - af = apt_pkg.GetPkgAcqFile(fetcher, - uri=uri, - descr="sample descr", destFile=destFile) - res = fetcher.Run() - if res != fetcher.ResultContinue: - return False - return True + # get the file + af = apt_pkg.GetPkgAcqFile(fetcher, uri=uri, descr="sample descr", + destFile=destFile) + res = fetcher.Run() + if res != fetcher.ResultContinue: + return False + return True apt_pkg.init() @@ -32,7 +32,7 @@ depcache.Upgrade(True) progress = apt.progress.TextFetchProgress() fetcher = apt_pkg.GetAcquire(progress) pm = apt_pkg.GetPackageManager(depcache) -pm.GetArchives(fetcher,list,recs) +pm.GetArchives(fetcher, list, recs) print "%s (%s)" % (apt_pkg.SizeToStr(fetcher.FetchNeeded), fetcher.FetchNeeded) actiongroup = apt_pkg.GetPkgActionGroup(depcache) for pkg in cache.Packages: @@ -43,7 +43,7 @@ try: os.mkdir("/tmp/pyapt-test/partial") except OSError: pass -apt_pkg.Config.Set("Dir::Cache::archives","/tmp/pyapt-test") +apt_pkg.Config.Set("Dir::Cache::archives", "/tmp/pyapt-test") pkg = cache["3ddesktop"] depcache.MarkInstall(pkg) @@ -58,7 +58,7 @@ print fetcher get_file(fetcher, "ftp://ftp.debian.org/debian/dists/README", "/tmp/lala") -pm.GetArchives(fetcher,list,recs) +pm.GetArchives(fetcher, list, recs) for item in fetcher.Items: print item @@ -75,6 +75,3 @@ print "fetcher.Run() returned: %s" % res print "now runing pm.DoInstall()" res = pm.DoInstall(1) print "pm.DoInstall() returned: %s"% res - - - diff --git a/doc/examples/action.py b/doc/examples/action.py index adf26539..7153292c 100644 --- a/doc/examples/action.py +++ b/doc/examples/action.py @@ -21,15 +21,6 @@ cache.Update(progress) print "Exiting" sys.exit(0) - - - - - - - - - iter = cache["base-config"] print "example package iter: %s" % iter @@ -45,7 +36,6 @@ depcache.Init(progress) #sys.exit() - # get a canidate version ver= depcache.GetCandidateVer(iter) print "Candidate version: %s " % ver @@ -66,7 +56,6 @@ depcache.MarkDelete(iter) print "DelCount: %s " % depcache.DelCount print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter)) - iter = cache["3dchess"] print "\nMarking '%s' for install" % iter.Name depcache.MarkInstall(iter) @@ -97,10 +86,10 @@ print "UsrSize: %s " % apt_pkg.SizeToStr(depcache.UsrSize) print "DebSize: %s " % apt_pkg.SizeToStr(depcache.DebSize) for pkg in cache.Packages: - if pkg.CurrentVer != None and not depcache.MarkedInstall(pkg) and depcache.IsUpgradable(pkg): + if pkg.CurrentVer != None and not depcache.MarkedInstall(pkg) \ + and depcache.IsUpgradable(pkg): print "Upgrade didn't upgrade (kept): %s" % pkg.Name - print "\nPerforming DistUpgrade" depcache.Upgrade(True) print "Keep: %s " % depcache.KeepCount diff --git a/doc/examples/all_deps.py b/doc/examples/all_deps.py index f4f1741c..e8c9eaaf 100644 --- a/doc/examples/all_deps.py +++ b/doc/examples/all_deps.py @@ -1,34 +1,36 @@ -#!/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)
+#!/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/build-deps.py b/doc/examples/build-deps.py index 81a8b408..dc1a6f4e 100755 --- a/doc/examples/build-deps.py +++ b/doc/examples/build-deps.py @@ -5,18 +5,20 @@ 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 + """ 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() @@ -28,45 +30,45 @@ 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) + print "need a package name as argument" + sys.exit(1) try: - base = cache[sys.argv[1]] + base = cache[sys.argv[1]] except KeyError: - print "No package %s found" % sys.argv[1] - sys.exit(1) + 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 + 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]) + 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]) - + 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/cdrom.py b/doc/examples/cdrom.py index bf044d7c..743220a6 100644 --- a/doc/examples/cdrom.py +++ b/doc/examples/cdrom.py @@ -2,7 +2,8 @@ # example how to deal with the depcache import apt_pkg -import sys, os +import sys +import os import copy from progress import CdromProgress @@ -16,17 +17,11 @@ print cdrom progress = CdromProgress() -(res,ident) = cdrom.Ident(progress) +(res, ident) = cdrom.Ident(progress) print "ident result is: %s (%s) " % (res, ident) apt_pkg.Config.Set("APT::CDROM::Rename", "True") cdrom.Add(progress) - - print "Exiting" sys.exit(0) - - - - diff --git a/doc/examples/checkstate.py b/doc/examples/checkstate.py index 2986872f..3368d500 100755 --- a/doc/examples/checkstate.py +++ b/doc/examples/checkstate.py @@ -14,23 +14,23 @@ packages = cache.Packages uninstalled, updated, upgradable = {}, {}, {} for package in packages: - versions = package.VersionList - if not versions: - continue - version = versions[0] - for other_version in versions: - if apt_pkg.VersionCompare(version.VerStr, other_version.VerStr)<0: - version = other_version - if package.CurrentVer: - current = package.CurrentVer - if apt_pkg.VersionCompare(current.VerStr, version.VerStr)<0: - upgradable[package.Name] = version - break - else: - updated[package.Name] = current - else: - uninstalled[package.Name] = version + versions = package.VersionList + if not versions: + continue + version = versions[0] + for other_version in versions: + if apt_pkg.VersionCompare(version.VerStr, other_version.VerStr)<0: + version = other_version + if package.CurrentVer: + current = package.CurrentVer + if apt_pkg.VersionCompare(current.VerStr, version.VerStr)<0: + upgradable[package.Name] = version + break + else: + updated[package.Name] = current + else: + uninstalled[package.Name] = version for l in (uninstalled, updated, upgradable): - print l.items()[0] + print l.items()[0] diff --git a/doc/examples/config.py b/doc/examples/config.py index 24d90a0d..9d4e51fc 100755 --- a/doc/examples/config.py +++ b/doc/examples/config.py @@ -6,49 +6,53 @@ # config.py -no-h --no-help --help=no ; Turn off help # config.py -qqq -q=3 ; verbosity to 3 # config.py -c /etc/apt/apt.conf ; include that config file] -# config.py -o help=true ; Turn on help by giving a config file string +# config.py -o help=true ; Turn on help by giving a +# ; config file string # config.py -no-h -- -help ; Turn off help, specify the file '-help' # -c and -o are standard APT-program options. # This shows how to use the system for configuration and option control. # The other varient is for ISC object config files. See configisc.py. -import apt_pkg,sys,posixpath; +import apt_pkg +import sys +import posixpath # Create a new empty Configuration object - there is also the system global # configuration object apt_pkg.Config which is used interally by apt-pkg # routines to control unusual situations. I recommend using the sytem global # whenever possible.. -Cnf = apt_pkg.newConfiguration(); +Cnf = apt_pkg.newConfiguration() -print "Command line is",sys.argv +print "Command line is", sys.argv # Load the default configuration file, InitConfig() does this better.. -Cnf.Set("config-file","/etc/apt/apt.conf"); # or Cnf["config-file"] = ".."; +Cnf.Set("config-file", "/etc/apt/apt.conf") # or Cnf["config-file"] = ".." if posixpath.exists(Cnf.FindFile("config-file")): - apt_pkg.ReadConfigFile(Cnf,"/etc/apt/apt.conf"); + apt_pkg.ReadConfigFile(Cnf, "/etc/apt/apt.conf") # Merge the command line arguments into the configuration space -Arguments = [('h',"help","help"), - ('v',"version","version"), - ('q',"quiet","quiet","IntLevel"), - ('c',"config-file","","ConfigFile"), - ('o',"option","","ArbItem")] -print "FileNames",apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv); +Arguments = [('h', "help", "help"), + ('v', "version", "version"), + ('q', "quiet", "quiet", "IntLevel"), + ('c', "config-file", "", "ConfigFile"), + ('o', "option", "", "ArbItem")] +print "FileNames", apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv) -print "Quiet level selected is",Cnf.FindI("quiet",0); +print "Quiet level selected is", Cnf.FindI("quiet", 0) # Do some stuff with it -if Cnf.FindB("version",0) == 1: - print "Version selected - 1.1"; +if Cnf.FindB("version", 0) == 1: + print "Version selected - 1.1" -if Cnf.FindB("help",0) == 1: - print "python-apt",apt_pkg.Version,"compiled on",apt_pkg.Date,apt_pkg.Time; - print "Hi, I am the help text for this program"; - sys.exit(0); +if Cnf.FindB("help", 0) == 1: + print "python-apt", apt_pkg.Version, \ + "compiled on", apt_pkg.Date, apt_pkg.Time + print "Hi, I am the help text for this program" + sys.exit(0) -print "No help for you, try -h"; +print "No help for you, try -h" # Print the configuration space -print "The Configuration space looks like:"; +print "The Configuration space looks like:" for I in Cnf.keys(): - print "%s \"%s\";"%(I,Cnf[I]); + print "%s \"%s\";" % (I, Cnf[I]) diff --git a/doc/examples/configisc.py b/doc/examples/configisc.py index 1773a919..1d5965f5 100755 --- a/doc/examples/configisc.py +++ b/doc/examples/configisc.py @@ -8,32 +8,37 @@ # doc/examples/ftp-archive.conf # or a bind8 config file.. -import apt_pkg,sys,posixpath; +import apt_pkg +import sys +import posixpath -ConfigFile = apt_pkg.ParseCommandLine(apt_pkg.Config,[],sys.argv); +ConfigFile = apt_pkg.ParseCommandLine(apt_pkg.Config, [], sys.argv) if len(ConfigFile) != 1: - print "Must have exactly 1 file name"; - sys.exit(0); + print "Must have exactly 1 file name" + sys.exit(0) -Cnf = apt_pkg.newConfiguration(); -apt_pkg.ReadConfigFileISC(Cnf,ConfigFile[0]); +Cnf = apt_pkg.newConfiguration() +apt_pkg.ReadConfigFileISC(Cnf, ConfigFile[0]) # Print the configuration space -#print "The Configuration space looks like:"; +#print "The Configuration space looks like:" #for I in Cnf.keys(): -# print "%s \"%s\";"%(I,Cnf[I]); +# print "%s \"%s\";" % (I, Cnf[I]) # bind8 config file.. if Cnf.has_key("Zone"): - print "Zones: ",Cnf.SubTree("zone").List(); - for I in Cnf.List("zone"): - SubCnf = Cnf.SubTree(I); - if SubCnf.Find("type") == "slave": - print "Masters for %s: %s"%(SubCnf.MyTag(),SubCnf.ValueList("masters")); + print "Zones: ", Cnf.SubTree("zone").List() + for I in Cnf.List("zone"): + SubCnf = Cnf.SubTree(I) + if SubCnf.Find("type") == "slave": + print "Masters for %s: %s" % ( + SubCnf.MyTag(), SubCnf.ValueList("masters")) else: - print "Tree definitions:"; - for I in Cnf.List("tree"): - SubCnf = Cnf.SubTree(I); - # This could use Find which would eliminate the possibility of exceptions. - print "Subtree %s with sections '%s' and architectures '%s'"%(SubCnf.MyTag(),SubCnf["Sections"],SubCnf["Architectures"]); + print "Tree definitions:" + for I in Cnf.List("tree"): + SubCnf = Cnf.SubTree(I) + # This could use Find which would eliminate the possibility of + # exceptions. + print "Subtree %s with sections '%s' and architectures '%s'" % ( + SubCnf.MyTag(), SubCnf["Sections"], SubCnf["Architectures"]) diff --git a/doc/examples/deb_inspect.py b/doc/examples/deb_inspect.py index b57526c6..cc0d04be 100755 --- a/doc/examples/deb_inspect.py +++ b/doc/examples/deb_inspect.py @@ -6,11 +6,11 @@ import apt_inst import sys import os.path -def Callback(What,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor): - """ callback for debExtract """ - print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u"\ - % (What,Name,Link,Mode,UID,GID,Size, MTime, Major, Minor); +def Callback(What, Name, Link, Mode, UID, GID, Size, MTime, Major, Minor): + """ callback for debExtract """ + print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u" \ + % (What, Name, Link, Mode, UID, GID, Size, MTime, Major, Minor) if __name__ == "__main__": @@ -39,9 +39,11 @@ if __name__ == "__main__": print "extracting archive" dir = "/tmp/deb" os.mkdir(dir) - apt_inst.debExtractArchive(open(file),dir) + apt_inst.debExtractArchive(open(file), dir) + def visit(arg, dirname, names): print "%s/" % dirname for file in names: print "\t%s" % file + os.path.walk(dir, visit, None) diff --git a/doc/examples/depcache.py b/doc/examples/depcache.py index 556c954b..ad884fe7 100644 --- a/doc/examples/depcache.py +++ b/doc/examples/depcache.py @@ -84,7 +84,8 @@ print "UsrSize: %s " % apt_pkg.SizeToStr(depcache.UsrSize) print "DebSize: %s " % apt_pkg.SizeToStr(depcache.DebSize) for pkg in cache.Packages: - if pkg.CurrentVer != None and not depcache.MarkedInstall(pkg) and depcache.IsUpgradable(pkg): + if pkg.CurrentVer != None and not depcache.MarkedInstall(pkg) \ + and depcache.IsUpgradable(pkg): print "Upgrade didn't upgrade (kept): %s" % pkg.Name diff --git a/doc/examples/dependant-pkgs.py b/doc/examples/dependant-pkgs.py index f36936a8..bb10ce70 100755 --- a/doc/examples/dependant-pkgs.py +++ b/doc/examples/dependant-pkgs.py @@ -6,31 +6,31 @@ import sys pkgs = set() cache = apt.Cache() for pkg in cache: - candver = cache._depcache.GetCandidateVer(pkg._pkg) - if candver == None: - continue - dependslist = candver.DependsList - for dep in dependslist.keys(): - # get the list of each dependency object - for depVerList in dependslist[dep]: - for z in depVerList: - # get all TargetVersions of - # the dependency object - for tpkg in z.AllTargets(): - if sys.argv[1] == tpkg.ParentPkg.Name: - pkgs.add(pkg.name) + candver = cache._depcache.GetCandidateVer(pkg._pkg) + if candver == None: + continue + dependslist = candver.DependsList + for dep in dependslist.keys(): + # get the list of each dependency object + for depVerList in dependslist[dep]: + for z in depVerList: + # get all TargetVersions of + # the dependency object + for tpkg in z.AllTargets(): + if sys.argv[1] == tpkg.ParentPkg.Name: + pkgs.add(pkg.name) main = set() universe = set() for pkg in pkgs: - if "universe" in cache[pkg].section: - universe.add(cache[pkg].sourcePackageName) - else: - main.add(cache[pkg].sourcePackageName) + if "universe" in cache[pkg].section: + universe.add(cache[pkg].sourcePackageName) + else: + main.add(cache[pkg].sourcePackageName) -print "main:" +print "main:" print "\n".join(main) print -print "universe:" +print "universe:" print "\n".join(universe) diff --git a/doc/examples/desc.py b/doc/examples/desc.py index 87b9473b..f47517cf 100644 --- a/doc/examples/desc.py +++ b/doc/examples/desc.py @@ -3,7 +3,7 @@ import apt_pkg apt_pkg.init() -apt_pkg.Config.Set("APT::Acquire::Translation","de") +apt_pkg.Config.Set("APT::Acquire::Translation", "de") cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) @@ -15,11 +15,10 @@ print cand desc = cand.TranslatedDescription print desc print desc.FileList -(f,index) = desc.FileList.pop(0) +(f, index) = desc.FileList.pop(0) records = apt_pkg.GetPkgRecords(cache) -records.Lookup((f,index)) +records.Lookup((f, index)) desc = records.LongDesc print len(desc) print desc - diff --git a/doc/examples/gui-inst.py b/doc/examples/gui-inst.py index 9a3b007f..cb49db3e 100755 --- a/doc/examples/gui-inst.py +++ b/doc/examples/gui-inst.py @@ -30,7 +30,5 @@ if __name__ == "__main__": else: cache["2vcard"].markInstall() progress.show_terminal(expanded=True) - cache.commit(progress.fetch, - progress.install) - + cache.commit(progress.fetch, progress.install) gtk.main() diff --git a/doc/examples/indexfile.py b/doc/examples/indexfile.py index d383fd61..22d0b635 100644 --- a/doc/examples/indexfile.py +++ b/doc/examples/indexfile.py @@ -10,7 +10,7 @@ cache = apt_pkg.GetCache() depcache = apt_pkg.GetDepCache(cache) pkg = cache["libimlib2"] cand = depcache.GetCandidateVer(pkg) -for (f,i) in cand.FileList: +for (f, i) in cand.FileList: index = sources.FindIndex(f) print index if index: diff --git a/doc/examples/inst.py b/doc/examples/inst.py index ff9d452c..a3a50356 100644 --- a/doc/examples/inst.py +++ b/doc/examples/inst.py @@ -2,27 +2,34 @@ # example how to deal with the depcache import apt -import sys, os +import sys +import os import copy import time from apt.progress import InstallProgress + class TextInstallProgress(InstallProgress): - def __init__(self): - apt.progress.InstallProgress.__init__(self) - self.last = 0.0 - def updateInterface(self): - InstallProgress.updateInterface(self) - if self.last >= self.percent: - return - sys.stdout.write("\r[%s] %s\n" %(self.percent, self.status)) - sys.stdout.flush() - self.last = self.percent - def conffile(self,current,new): - print "conffile prompt: %s %s" % (current,new) - def error(self, errorstr): - print "got dpkg error: '%s'" % errorstr + + def __init__(self): + apt.progress.InstallProgress.__init__(self) + self.last = 0.0 + + def updateInterface(self): + InstallProgress.updateInterface(self) + if self.last >= self.percent: + return + sys.stdout.write("\r[%s] %s\n" %(self.percent, self.status)) + sys.stdout.flush() + self.last = self.percent + + def conffile(self, current, new): + print "conffile prompt: %s %s" % (current, new) + + def error(self, errorstr): + print "got dpkg error: '%s'" % errorstr + cache = apt.Cache(apt.progress.OpTextProgress()) @@ -33,16 +40,12 @@ pkg = cache["3dchess"] # install or remove, the importend thing is to keep us busy :) if pkg.isInstalled: - print "Going to delete %s" % pkg.name - pkg.markDelete() + print "Going to delete %s" % pkg.name + pkg.markDelete() else: - print "Going to install %s" % pkg.name - pkg.markInstall() + print "Going to install %s" % pkg.name + pkg.markInstall() res = cache.commit(fprogress, iprogress) print res sys.exit(0) - - - - diff --git a/doc/examples/metaindex.py b/doc/examples/metaindex.py index 1bce0dba..f00a7e01 100644 --- a/doc/examples/metaindex.py +++ b/doc/examples/metaindex.py @@ -9,7 +9,7 @@ sources.ReadMainList() for metaindex in sources.List: print metaindex - print "URI: ",metaindex.URI - print "Dist: ",metaindex.Dist - print "IndexFiles: ","\n".join([str(i) for i in metaindex.IndexFiles]) + print "URI: ", metaindex.URI + print "Dist: ", metaindex.Dist + print "IndexFiles: ", "\n".join([str(i) for i in metaindex.IndexFiles]) print diff --git a/doc/examples/print_uris.py b/doc/examples/print_uris.py index c8a64223..3b678e83 100755 --- a/doc/examples/print_uris.py +++ b/doc/examples/print_uris.py @@ -12,11 +12,11 @@ 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 + 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/progress.py b/doc/examples/progress.py index b90253cb..c56734b7 100644 --- a/doc/examples/progress.py +++ b/doc/examples/progress.py @@ -4,7 +4,9 @@ import sys import time import string + class TextProgress(apt.OpProgress): + def __init__(self): self.last=0.0 @@ -21,6 +23,7 @@ class TextProgress(apt.OpProgress): class TextFetchProgress(apt.FetchProgress): + def __init__(self): pass @@ -31,27 +34,36 @@ class TextFetchProgress(apt.FetchProgress): pass def updateStatus(self, uri, descr, shortDescr, status): - print "UpdateStatus: '%s' '%s' '%s' '%i'" % (uri,descr,shortDescr, status) + print "UpdateStatus: '%s' '%s' '%s' '%i'" % ( + uri, descr, shortDescr, status) + def pulse(self): - print "Pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % (SizeToStr(self.currentCPS), SizeToStr(self.currentBytes), SizeToStr(self.totalBytes), self.currentItems, self.totalItems) + print "Pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % ( + SizeToStr(self.currentCPS), SizeToStr(self.currentBytes), + SizeToStr(self.totalBytes), self.currentItems, self.totalItems) return True def mediaChange(self, medium, drive): - print "Please insert medium %s in drive %s" % (medium, drive) - sys.stdin.readline() + print "Please insert medium %s in drive %s" % (medium, drive) + sys.stdin.readline() #return False class TextInstallProgress(apt.InstallProgress): + def __init__(self): apt.InstallProgress.__init__(self) pass + def startUpdate(self): print "StartUpdate" + def finishUpdate(self): print "FinishUpdate" + def statusChange(self, pkg, percent, status): print "[%s] %s: %s" % (percent, pkg, status) + def updateInterface(self): apt.InstallProgress.updateInterface(self) # usefull to e.g. redraw a GUI @@ -59,20 +71,25 @@ class TextInstallProgress(apt.InstallProgress): class TextCdromProgress(apt.CdromProgress): + def __init__(self): pass + # update is called regularly so that the gui can be redrawn + def update(self, text, step): # check if we actually have some text to display if text != "": print "Update: %s %s" % (string.strip(text), step) + def askCdromName(self): print "Please enter cd-name: ", cd_name = sys.stdin.readline() return (True, string.strip(cd_name)) + def changeCdrom(self): print "Please insert cdrom and press <ENTER>" - answer = sys.stdin.readline() + answer = sys.stdin.readline() return True diff --git a/doc/examples/recommends.py b/doc/examples/recommends.py index c1a7eb2e..f0b3b1be 100755 --- a/doc/examples/recommends.py +++ b/doc/examples/recommends.py @@ -5,37 +5,35 @@ apt_pkg.init() cache = apt_pkg.GetCache() + class Wanted: - def __init__(self, name): - self.name = name - self.recommended = [] - self.suggested = [] + def __init__(self, name): + self.name = name + self.recommended = [] + self.suggested = [] + wanted = {} for package in cache.Packages: - current = package.CurrentVer - if not current: - continue - depends = current.DependsList - for (key, attr) in (('Suggests', 'suggested'), - ('Recommends', 'recommended')): - list = depends.get(key, []) - for dependency in list: - name = dependency[0].TargetPkg.Name - dep = cache[name] - if dep.CurrentVer: - continue - getattr(wanted.setdefault(name, Wanted(name)), - attr).append(package.Name) + current = package.CurrentVer + if not current: + continue + depends = current.DependsList + for (key, attr) in (('Suggests', 'suggested'), + ('Recommends', 'recommended')): + list = depends.get(key, []) + for dependency in list: + name = dependency[0].TargetPkg.Name + dep = cache[name] + if dep.CurrentVer: + continue + getattr(wanted.setdefault(name, Wanted(name)), + attr).append(package.Name) ks = wanted.keys() ks.sort() for want in ks: - print want, wanted[want].recommended, wanted[want].suggested - - - - + print want, wanted[want].recommended, wanted[want].suggested diff --git a/doc/examples/records.py b/doc/examples/records.py index ef04b555..a7a87727 100755 --- a/doc/examples/records.py +++ b/doc/examples/records.py @@ -5,8 +5,9 @@ import apt cache = apt.Cache() for pkg in cache: - if not pkg.candidateRecord: - continue - if pkg.candidateRecord.has_key("Task"): - print "Pkg %s is part of '%s'" % (pkg.name, pkg.candidateRecord["Task"].split()) - #print pkg.candidateRecord + if not pkg.candidateRecord: + continue + if pkg.candidateRecord.has_key("Task"): + print "Pkg %s is part of '%s'" % ( + pkg.name, pkg.candidateRecord["Task"].split()) + #print pkg.candidateRecord diff --git a/doc/examples/sources.py b/doc/examples/sources.py index b48c0ba5..49652982 100644 --- a/doc/examples/sources.py +++ b/doc/examples/sources.py @@ -10,6 +10,7 @@ apt_pkg.init() 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.Index.ArchiveURI(sources.Files[0][2]) + print sources.Package, sources.Version, sources.Maintainer, \ + sources.Section, `sources.Binaries` + print sources.Files + print sources.Index.ArchiveURI(sources.Files[0][2]) diff --git a/doc/examples/tagfile.py b/doc/examples/tagfile.py index 653c0a71..4faf08ac 100755 --- a/doc/examples/tagfile.py +++ b/doc/examples/tagfile.py @@ -1,8 +1,8 @@ #!/usr/bin/env python import apt_pkg -Parse = apt_pkg.ParseTagFile(open("/var/lib/dpkg/status","r")); +Parse = apt_pkg.ParseTagFile(open("/var/lib/dpkg/status", "r")) while Parse.Step() == 1: - print Parse.Section.get("Package"); - print apt_pkg.ParseDepends(Parse.Section.get("Depends","")); + print Parse.Section.get("Package") + print apt_pkg.ParseDepends(Parse.Section.get("Depends", "")) diff --git a/doc/examples/update.py b/doc/examples/update.py index be7bb679..364fa1c9 100755 --- a/doc/examples/update.py +++ b/doc/examples/update.py @@ -9,5 +9,5 @@ if __name__ == "__main__": "touch /tmp/update-was-run") c = apt.Cache() res = c.update(apt.progress.TextFetchProgress()) - print "res: ",res + print "res: ", res assert(os.path.exists("/tmp/update-about-to-run")) diff --git a/doc/examples/versiontest.py b/doc/examples/versiontest.py index c4e5f44d..dd881f6b 100755 --- a/doc/examples/versiontest.py +++ b/doc/examples/versiontest.py @@ -1,36 +1,40 @@ #!/usr/bin/python # This is a simple clone of tests/versiontest.cc -import apt_pkg,sys,re,string; -apt_pkg.InitConfig(); -apt_pkg.InitSystem(); +import apt_pkg +import sys +import re +import string -TestFile = apt_pkg.ParseCommandLine(apt_pkg.Config,[],sys.argv); +apt_pkg.InitConfig() +apt_pkg.InitSystem() + +TestFile = apt_pkg.ParseCommandLine(apt_pkg.Config, [], sys.argv) if len(TestFile) != 1: - print "Must have exactly 1 file name"; - sys.exit(0); + print "Must have exactly 1 file name" + sys.exit(0) # Go over the file.. -List = open(TestFile[0],"r"); -CurLine = 0; +List = open(TestFile[0], "r") +CurLine = 0 while(1): - Line = List.readline(); - CurLine = CurLine + 1; - if Line == "": - break; - Line = string.strip(Line); - if len(Line) == 0 or Line[0] == '#': - continue; + Line = List.readline() + CurLine = CurLine + 1 + if Line == "": + break + Line = string.strip(Line) + if len(Line) == 0 or Line[0] == '#': + continue - Split = re.split("[ \n]",Line); + Split = re.split("[ \n]", Line) - # Check forward - if apt_pkg.VersionCompare(Split[0],Split[1]) != int(Split[2]): - print "Comparision failed on line %u. '%s' ? '%s' %i != %i"%(CurLine, - Split[0],Split[1],apt_pkg.VersionCompare(Split[0],Split[1]), - int(Split[2])); - # Check reverse - if apt_pkg.VersionCompare(Split[1],Split[0]) != -1*int(Split[2]): - print "Comparision failed on line %u. '%s' ? '%s' %i != %i"%(CurLine, - Split[1],Split[0],apt_pkg.VersionCompare(Split[1],Split[0]), - -1*int(Split[2])); + # Check forward + if apt_pkg.VersionCompare(Split[0], Split[1]) != int(Split[2]): + print "Comparision failed on line %u. '%s' ? '%s' %i != %i" % (CurLine, + Split[0], Split[1], apt_pkg.VersionCompare(Split[0], Split[1]), + int(Split[2])) + # Check reverse + if apt_pkg.VersionCompare(Split[1], Split[0]) != -1 * int(Split[2]): + print "Comparision failed on line %u. '%s' ? '%s' %i != %i" % (CurLine, + Split[1], Split[0], apt_pkg.VersionCompare(Split[1], Split[0]), + -1 * int(Split[2])) |
