Commit 9b2e18e4 authored by Julian Andres Klode's avatar Julian Andres Klode

doc/examples/*.py: Update examples to the new API

Closes: #639022
parent 8a672192
......@@ -28,6 +28,8 @@ python-apt (0.9.0) UNRELEASED; urgency=low
Closes: #717859. Closes: #717861.
* doc/source/examples/dpkg-info.py:
- Use apt_inst.DebFile (Closes: #671784)
* doc/examples/*.py:
- Update examples to the new API (Closes: #639022)
[ Jeremy Bicha ]
* data/templates/Ubuntu.info.in: add 'devel' series (Closes: #722961)
......
......@@ -16,9 +16,9 @@ def get_file(fetcher, uri, destfile):
apt_pkg.init()
#apt_pkg.Config.Set("Debug::pkgDPkgPM","1");
#apt_pkg.Config.Set("Debug::pkgPackageManager","1");
#apt_pkg.Config.Set("Debug::pkgDPkgProgressReporting","1");
#apt_pkg.config.set("Debug::pkgDPkgPM","1");
#apt_pkg.config.set("Debug::pkgPackageManager","1");
#apt_pkg.config.set("Debug::pkgDPkgProgressReporting","1");
cache = apt_pkg.Cache()
depcache = apt_pkg.DepCache(cache)
......
......@@ -62,8 +62,8 @@ for dep in depends["Depends"]: # FIXME: do we need to consider PreDepends?
continue
srcrec = srcrecords.lookup(srcpkg_name)
if srcrec:
#print srcrecords.Package
#print srcrecords.Binaries
#print srcrecords.package
#print srcrecords.binaries
bd = srcrecords.build_depends
#print "%s: %s " % (srcpkg_name, bd)
for b in bd:
......
......@@ -45,8 +45,8 @@ for or_dep in depends:
continue
srcrec = srcrecords.lookup(srcpkg_name)
if srcrec:
#print srcrecords.Package
#print srcrecords.Binaries
#print srcrecords.package
#print srcrecords.binaries
bd = srcrecords.build_depends
#print "%s: %s " % (srcpkg_name, bd)
for b in bd:
......
......@@ -18,14 +18,14 @@ 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
# 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.Configuration()
print "Command line is", sys.argv
# Load the default configuration file, InitConfig() does this better..
# Load the default configuration file, init_config() does this better..
Cnf.set("config-file", "/etc/apt/apt.conf") # or Cnf["config-file"] = ".."
if posixpath.exists(Cnf.find_file("config-file")):
apt_pkg.read_config_file(Cnf, "/etc/apt/apt.conf")
......
......@@ -11,7 +11,7 @@
import apt_pkg
import sys
ConfigFile = apt_pkg.parse_commandLine(apt_pkg.config, [], sys.argv)
ConfigFile = apt_pkg.parse_commandline(apt_pkg.config, [], sys.argv)
if len(ConfigFile) != 1:
print "Must have exactly 1 file name"
......
......@@ -10,7 +10,7 @@ apt_pkg.init()
progress = TextProgress()
cache = apt_pkg.Cache(progress)
print "Available packages: %s " % cache.PackageCount
print "Available packages: %s " % cache.package_count
iter = cache["base-config"]
print "example package iter: %s" % iter
......@@ -18,90 +18,90 @@ print "example package iter: %s" % iter
# get depcache
print "\n\n depcache"
depcache = apt_pkg.DepCache(cache)
depcache.ReadPinFile()
depcache.read_pinfile()
# init is needed after the creation/pin file reading
depcache.Init(progress)
depcache.init(progress)
print "got a depcache: %s " % depcache
print "Marked for install: %s " % depcache.InstCount
print "Marked for install: %s " % depcache.inst_count
print "\n\n Reinit"
depcache.Init(progress)
depcache.init(progress)
#sys.exit()
# get a canidate version
ver= depcache.GetCandidateVer(iter)
ver= depcache.get_candidate_ver(iter)
print "Candidate version: %s " % ver
print "\n\nQuerry interface"
print "%s.IsUpgradable(): %s" % (iter.Name, depcache.IsUpgradable(iter))
print "%s.is_upgradable(): %s" % (iter.name, depcache.is_upgradable(iter))
print "\nMarking interface"
print "Marking '%s' for install" % iter.Name
depcache.MarkInstall(iter)
print "Install count: %s " % depcache.InstCount
print "%s.MarkedInstall(): %s" % (iter.Name, depcache.MarkedInstall(iter))
print "%s.MarkedUpgrade(): %s" % (iter.Name, depcache.MarkedUpgrade(iter))
print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter))
print "Marking '%s' for install" % iter.name
depcache.mark_install(iter)
print "Install count: %s " % depcache.inst_count
print "%s.marked_install(): %s" % (iter.name, depcache.marked_install(iter))
print "%s.marked_upgrade(): %s" % (iter.name, depcache.marked_upgrade(iter))
print "%s.marked_delete(): %s" % (iter.name, depcache.marked_delete(iter))
print "Marking %s for delete" % iter.Name
depcache.MarkDelete(iter)
print "DelCount: %s " % depcache.DelCount
print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter))
print "Marking %s for delete" % iter.name
depcache.mark_delete(iter)
print "del_count: %s " % depcache.del_count
print "%s.marked_delete(): %s" % (iter.name, depcache.marked_delete(iter))
iter = cache["3dchess"]
print "\nMarking '%s' for install" % iter.Name
depcache.MarkInstall(iter)
print "Install count: %s " % depcache.InstCount
print "%s.MarkedInstall(): %s" % (iter.Name, depcache.MarkedInstall(iter))
print "%s.MarkedUpgrade(): %s" % (iter.Name, depcache.MarkedUpgrade(iter))
print "%s.MarkedDelete(): %s" % (iter.Name, depcache.MarkedDelete(iter))
print "\nMarking '%s' for install" % iter.name
depcache.mark_install(iter)
print "Install count: %s " % depcache.inst_count
print "%s.marked_install(): %s" % (iter.name, depcache.marked_install(iter))
print "%s.marked_upgrade(): %s" % (iter.name, depcache.marked_upgrade(iter))
print "%s.marked_delete(): %s" % (iter.name, depcache.marked_delete(iter))
print "Marking %s for keep" % iter.Name
depcache.MarkKeep(iter)
print "Install: %s " % depcache.InstCount
print "Marking %s for keep" % iter.name
depcache.mark_keep(iter)
print "Install: %s " % depcache.inst_count
iter = cache["synaptic"]
print "\nMarking '%s' for install" % iter.Name
depcache.MarkInstall(iter)
print "Install: %s " % depcache.InstCount
print "Broken count: %s" % depcache.BrokenCount
print "FixBroken() "
depcache.FixBroken()
print "Broken count: %s" % depcache.BrokenCount
print "\nPerforming Upgrade"
depcache.Upgrade()
print "Keep: %s " % depcache.KeepCount
print "Install: %s " % depcache.InstCount
print "Delete: %s " % depcache.DelCount
print "UsrSize: %s " % apt_pkg.SizeToStr(depcache.UsrSize)
print "DebSize: %s " % apt_pkg.SizeToStr(depcache.DebSize)
for pkg in cache.Packages:
if pkg.CurrentVer is not None and not depcache.MarkedInstall(pkg) \
and depcache.IsUpgradable(pkg):
print "Upgrade didn't upgrade (kept): %s" % pkg.Name
print "\nMarking '%s' for install" % iter.name
depcache.mark_install(iter)
print "Install: %s " % depcache.inst_count
print "Broken count: %s" % depcache.broken_count
print "fix_broken() "
depcache.fix_broken()
print "Broken count: %s" % depcache.broken_count
print "\nPerforming upgrade"
depcache.upgrade()
print "Keep: %s " % depcache.keep_count
print "Install: %s " % depcache.inst_count
print "Delete: %s " % depcache.del_count
print "usr_size: %s " % apt_pkg.size_to_str(depcache.usr_size)
print "deb_size: %s " % apt_pkg.size_to_str(depcache.deb_size)
for pkg in cache.packages:
if pkg.current_ver is not None and not depcache.marked_install(pkg) \
and depcache.is_upgradable(pkg):
print "upgrade didn't upgrade (kept): %s" % pkg.name
print "\nPerforming DistUpgrade"
depcache.Upgrade(True)
print "Keep: %s " % depcache.KeepCount
print "Install: %s " % depcache.InstCount
print "Delete: %s " % depcache.DelCount
print "UsrSize: %s " % apt_pkg.SizeToStr(depcache.UsrSize)
print "DebSize: %s " % apt_pkg.SizeToStr(depcache.DebSize)
depcache.upgrade(True)
print "Keep: %s " % depcache.keep_count
print "Install: %s " % depcache.inst_count
print "Delete: %s " % depcache.del_count
print "usr_size: %s " % apt_pkg.size_to_str(depcache.usr_size)
print "deb_size: %s " % apt_pkg.size_to_str(depcache.deb_size)
# overview about what would happen
for pkg in cache.Packages:
if depcache.MarkedInstall(pkg):
if pkg.CurrentVer is not None:
print "Marked upgrade: %s " % pkg.Name
for pkg in cache.packages:
if depcache.marked_install(pkg):
if pkg.current_ver is not None:
print "Marked upgrade: %s " % pkg.name
else:
print "Marked install: %s" % pkg.Name
elif depcache.MarkedDelete(pkg):
print "Marked delete: %s" % pkg.Name
elif depcache.MarkedKeep(pkg):
print "Marked keep: %s" % pkg.Name
print "Marked install: %s" % pkg.name
elif depcache.marked_delete(pkg):
print "Marked delete: %s" % pkg.name
elif depcache.marked_keep(pkg):
print "Marked keep: %s" % pkg.name
......@@ -6,27 +6,27 @@ import sys
pkgs = set()
cache = apt.Cache()
for pkg in cache:
candver = cache._depcache.GetCandidateVer(pkg._pkg)
candver = cache._depcache.get_candidate_ver(pkg._pkg)
if candver is None:
continue
dependslist = candver.DependsList
dependslist = candver.depends_list
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:
for tpkg in z.all_targets():
if sys.argv[1] == tpkg.parent_pkg.name:
pkgs.add(pkg.name)
main = set()
universe = set()
for pkg in pkgs:
if "universe" in cache[pkg].section:
universe.add(cache[pkg].sourcePackageName)
universe.add(cache[pkg].source_name)
else:
main.add(cache[pkg].sourcePackageName)
main.add(cache[pkg].source_name)
print "main:"
print "\n".join(main)
......
......@@ -4,22 +4,22 @@ 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.Cache()
depcache = apt_pkg.DepCache(cache)
pkg = cache["gcc"]
cand = depcache.GetCandidateVer(pkg)
cand = depcache.get_candidate_ver(pkg)
print cand
desc = cand.TranslatedDescription
print desc
print desc.FileList
(f, index) = desc.FileList.pop(0)
print desc.file_list
(f, index) = desc.file_list.pop(0)
records = apt_pkg.PackageRecords(cache)
records.Lookup((f, index))
desc = records.LongDesc
records.lookup((f, index))
desc = records.long_desc
print len(desc)
print desc
......@@ -18,10 +18,10 @@ if __name__ == "__main__":
win.show()
cache = apt.cache.Cache(progress.open)
if cache["2vcard"].isInstalled:
cache["2vcard"].markDelete()
if cache["2vcard"].is_installed:
cache["2vcard"].mark_delete()
else:
cache["2vcard"].markInstall()
cache["2vcard"].mark_install()
progress.show_terminal(expanded=True)
cache.commit(progress.fetch, progress.install)
gtk.main()
......@@ -5,18 +5,18 @@ import apt_pkg
apt_pkg.init()
sources = apt_pkg.SourceList()
sources.ReadMainList()
sources.read_main_list()
cache = apt_pkg.Cache()
depcache = apt_pkg.DepCache(cache)
pkg = cache["libimlib2"]
cand = depcache.GetCandidateVer(pkg)
for (f, i) in cand.FileList:
index = sources.FindIndex(f)
cand = depcache.get_candidate_ver(pkg)
for (f, i) in cand.file_list:
index = sources.find_index(f)
print index
if index:
print index.Size
print index.IsTrusted
print index.Exists
print index.HasPackages
print index.ArchiveURI("some/path")
print index.size
print index.is_trusted
print index.exists
print index.Haspackages
print index.archive_uri("some/path")
......@@ -36,12 +36,12 @@ iprogress = TextInstallProgress()
pkg = cache["3dchess"]
# install or remove, the importend thing is to keep us busy :)
if pkg.isInstalled:
if pkg.is_installed:
print "Going to delete %s" % pkg.name
pkg.markDelete()
pkg.mark_delete()
else:
print "Going to install %s" % pkg.name
pkg.markInstall()
pkg.mark_install()
res = cache.commit(fprogress, iprogress)
print res
......
......@@ -5,12 +5,12 @@ import apt_pkg
apt_pkg.init()
sources = apt_pkg.SourceList()
sources.ReadMainList()
sources.read_main_list()
for metaindex in sources.List:
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 "index_files: ", "\n".join([str(i) for i in metaindex.index_files])
print
......@@ -8,15 +8,15 @@ import apt_pkg
cache = apt.Cache()
upgradable = filter(lambda p: p.isUpgradable, cache)
upgradable = filter(lambda p: p.is_upgradable, cache)
for pkg in upgradable:
pkg._lookupRecord(True)
path = apt_pkg.TagSection(pkg._records.Record)["Filename"]
cand = pkg._depcache.GetCandidateVer(pkg._pkg)
for (packagefile, i) in cand.FileList:
indexfile = cache._list.FindIndex(packagefile)
path = apt_pkg.TagSection(pkg._records.record)["Filename"]
cand = pkg._depcache.get_candidate_ver(pkg._pkg)
for (packagefile, i) in cand.file_list:
indexfile = cache._list.find_index(packagefile)
if indexfile:
uri = indexfile.ArchiveURI(path)
uri = indexfile.archive_uri(path)
print uri
......@@ -3,10 +3,12 @@
import sys
import time
import apt_pkg
import apt
import apt.progress.base
class TextProgress(apt.OpProgress):
class TextProgress(apt.progress.base.OpProgress):
def __init__(self):
self.last=0.0
......@@ -23,7 +25,7 @@ class TextProgress(apt.OpProgress):
print "\rDone "
class TextFetchProgress(apt.FetchProgress):
class TextFetchProgress(apt.progress.base.AcquireProgress):
def __init__(self):
pass
......@@ -34,60 +36,49 @@ class TextFetchProgress(apt.FetchProgress):
def stop(self):
pass
def updateStatus(self, uri, descr, shortDescr, status):
print "UpdateStatus: '%s' '%s' '%s' '%i' " % (
uri, descr, shortDescr, status)
def fail(self, item):
print 'fail', item
def update_status_full(self, uri, descr, shortDescr, status, fileSize,
partialSize):
print "update_status_full: '%s' '%s' '%s' '%i' '%d/%d'" % (
uri, descr, shortDescr, status, partialSize, fileSize)
def fetch(self, item):
print 'fetch', item
def pulse(self):
print "Pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % (
apt.SizeToStr(self.currentCPS), apt.SizeToStr(self.currentBytes),
apt.SizeToStr(self.totalBytes), self.currentItems, self.totalItems)
return True
def ims_hit(self, item):
print 'ims_hit', item
def pulse_items(self, items):
print "Pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % (
apt.SizeToStr(self.currentCPS), apt.SizeToStr(self.currentBytes),
apt.SizeToStr(self.totalBytes), self.currentItems, self.totalItems)
print "Pulse-Items: "
for itm in items:
uri, descr, shortDescr, fileSize, partialSize = itm
print " - '%s' '%s' '%s' '%d/%d'" % (
uri, descr, shortDescr, partialSize, fileSize)
def pulse(self, owner):
print "pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % (
apt_pkg.size_to_str(self.current_cps), apt_pkg.size_to_str(self.current_bytes),
apt_pkg.size_to_str(self.total_bytes), self.current_items, self.total_items)
return True
def mediaChange(self, medium, drive):
def media_change(self, medium, drive):
print "Please insert medium %s in drive %s" % (medium, drive)
sys.stdin.readline()
#return False
class TextInstallProgress(apt.InstallProgress):
class TextInstallProgress(apt.progress.base.InstallProgress):
def __init__(self):
apt.InstallProgress.__init__(self)
apt.progress.base.InstallProgress.__init__(self)
pass
def startUpdate(self):
print "StartUpdate"
def start_update(self):
print "start_update"
def finishUpdate(self):
print "FinishUpdate"
def finish_update(self):
print "finish_update"
def statusChange(self, pkg, percent, status):
def status_change(self, pkg, percent, status):
print "[%s] %s: %s" % (percent, pkg, status)
def updateInterface(self):
apt.InstallProgress.updateInterface(self)
def update_interface(self):
apt.progress.base.InstallProgress.update_interface(self)
# usefull to e.g. redraw a GUI
time.sleep(0.1)
class TextCdromProgress(apt.CdromProgress):
class TextCdromProgress(apt.progress.base.CdromProgress):
def __init__(self):
pass
......@@ -99,12 +90,12 @@ class TextCdromProgress(apt.CdromProgress):
if text != "":
print "Update: %s %s" % (text.strip(), step)
def askCdromName(self):
def ask_cdrom_name(self):
print "Please enter cd-name: ",
cd_name = sys.stdin.readline()
return (True, cd_name.strip())
def changeCdrom(self):
def change_cdrom(self):
print "Please insert cdrom and press <ENTER>"
answer = sys.stdin.readline()
return True
......@@ -113,10 +104,10 @@ class TextCdromProgress(apt.CdromProgress):
if __name__ == "__main__":
c = apt.Cache()
pkg = c["3dchess"]
if pkg.isInstalled:
pkg.markDelete()
if pkg.is_installed:
pkg.mark_delete()
else:
pkg.markInstall()
pkg.mark_install()
res = c.commit(TextFetchProgress(), TextInstallProgress())
......
......@@ -16,21 +16,21 @@ class Wanted:
wanted = {}
for package in cache.Packages:
current = package.CurrentVer
for package in cache.packages:
current = package.current_ver
if not current:
continue
depends = current.DependsList
depends = current.depends_list
for (key, attr) in (('Suggests', 'suggested'),
('Recommends', 'recommended')):
list = depends.get(key, [])
for dependency in list:
name = dependency[0].TargetPkg.Name
name = dependency[0].target_pkg.name
dep = cache[name]
if dep.CurrentVer:
if dep.current_ver:
continue
getattr(wanted.setdefault(name, Wanted(name)),
attr).append(package.Name)
attr).append(package.name)
ks = wanted.keys()
ks.sort()
......
......@@ -8,9 +8,9 @@ apt_pkg.init()
#sources = apt_pkg.SourceRecords(cache)
sources = apt_pkg.SourceRecords()
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])
sources.restart()
while sources.lookup('hello'):
print sources.package, sources.version, sources.maintainer, \
sources.section, `sources.binaries`
print sources.files
print sources.index.archive_uri(sources.files[0][2])
......@@ -3,6 +3,6 @@ import apt_pkg
Parse = apt_pkg.TagFile(open("/var/lib/dpkg/status", "r"))
while Parse.Step() == 1:
print Parse.Section.get("Package")
print apt_pkg.ParseDepends(Parse.Section.get("Depends", ""))
while Parse.step() == 1:
print Parse.section.get("Package")
print apt_pkg.parse_depends(Parse.section.get("Depends", ""))
......@@ -4,9 +4,9 @@ import apt_pkg
import os.path
if __name__ == "__main__":
apt_pkg.Config.Set("APT::Update::Pre-Invoke::",
apt_pkg.config.set("APT::Update::Pre-Invoke::",
"touch /tmp/update-about-to-run")
apt_pkg.Config.Set("APT::Update::Post-Invoke::",
apt_pkg.config.set("APT::Update::Post-Invoke::",
"touch /tmp/update-was-run")
c = apt.Cache()
res = c.update(apt.progress.TextFetchProgress())
......
......@@ -5,19 +5,19 @@ import apt_pkg
import sys
import re
apt_pkg.InitConfig()
apt_pkg.InitSystem()
apt_pkg.init_config()
apt_pkg.init_system()
TestFile = apt_pkg.ParseCommandLine(apt_pkg.Config, [], sys.argv)
TestFile = apt_pkg.parse_commandline(apt_pkg.config, [], sys.argv)
if len(TestFile) != 1:
print "Must have exactly 1 file name"
sys.exit(0)
# Go over the file..
List = open(TestFile[0], "r")
list = open(TestFile[0], "r")
CurLine = 0
while(1):
Line = List.readline()
Line = list.readline()
CurLine = CurLine + 1
if Line == "":
break
......@@ -28,12 +28,12 @@ while(1):
Split = re.split("[ \n]", Line)
# Check forward
if apt_pkg.VersionCompare(Split[0], Split[1]) != int(Split[2]):
if apt_pkg.version_compare(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]),
Split[0], Split[1], apt_pkg.version_compare(Split[0], Split[1]),
int(Split[2]))
# Check reverse
if apt_pkg.VersionCompare(Split[1], Split[0]) != -1 * int(Split[2]):
if apt_pkg.version_compare(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]),
Split[1], Split[0], apt_pkg.version_compare(Split[1], Split[0]),
-1 * int(Split[2]))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment