summaryrefslogtreecommitdiff
path: root/doc/source/examples
diff options
context:
space:
mode:
Diffstat (limited to 'doc/source/examples')
-rw-r--r--doc/source/examples/apt-cdrom.py71
-rw-r--r--doc/source/examples/apt-gtk.py6
-rw-r--r--doc/source/examples/cache-packages.py18
-rw-r--r--doc/source/examples/cache-pkgfile.py16
-rw-r--r--doc/source/examples/dpkg-contents.py4
-rw-r--r--doc/source/examples/dpkg-extract.py2
-rw-r--r--doc/source/examples/dpkg-info.py4
-rw-r--r--doc/source/examples/missing-deps.py32
-rw-r--r--doc/source/examples/update-print-uris.py23
9 files changed, 135 insertions, 41 deletions
diff --git a/doc/source/examples/apt-cdrom.py b/doc/source/examples/apt-cdrom.py
new file mode 100644
index 00000000..cb23e97d
--- /dev/null
+++ b/doc/source/examples/apt-cdrom.py
@@ -0,0 +1,71 @@
+#!/usr/bin/python
+import sys
+
+import apt_pkg
+import apt
+
+
+def show_help():
+ print ("apt %s compiled on %s %s" % (apt_pkg.VERSION,
+ apt_pkg.DATE, apt_pkg.TIME))
+ if apt_pkg.config.find_b("version"):
+ return 0
+
+ # Copied from apt-cdrom
+ print ("Usage: apt-cdrom [options] command\n"
+ "\n"
+ "apt-cdrom is a tool to add CDROM's to APT's source list. The\n"
+ "CDROM mount point and device information is taken from apt.conf\n"
+ "and /etc/fstab.\n"
+ "\n"
+ "Commands:\n"
+ " add - Add a CDROM\n"
+ " ident - Report the identity of a CDROM\n"
+ "\n"
+ "Options:\n"
+ " -h This help text\n"
+ " -d CD-ROM mount point\n"
+ " -r Rename a recognized CD-ROM\n"
+ " -m No mounting\n"
+ " -f Fast mode, don't check package files\n"
+ " -a Thorough scan mode\n"
+ " -c=? Read this configuration file\n"
+ " -o=? Set an arbitrary configuration option, eg -o "
+ "dir::cache=/tmp\n"
+ "See fstab(5)")
+ return 0
+
+
+def main(args):
+ arguments = apt_pkg.parse_commandline(apt_pkg.config,
+ [('h', "help", "help"),
+ ('v', "version", "version"),
+ ('d', "cdrom", "Acquire::cdrom::mount", "HasArg"),
+ ('r', "rename", "APT::CDROM::Rename"),
+ ('m', "no-mount", "APT::CDROM::NoMount"),
+ ('f', "fast", "APT::CDROM::Fast"),
+ ('n', "just-print", "APT::CDROM::NoAct"),
+ ('n', "recon", "APT::CDROM::NoAct"),
+ ('n', "no-act", "APT::CDROM::NoAct"),
+ ('a', "thorough", "APT::CDROM::Thorough"),
+ ('c', "config-file", "", "ConfigFile"),
+ ('o', "option", "", "ArbItem")], args)
+
+ if apt_pkg.config.find_b("help") or apt_pkg.config.find_b("version"):
+ return show_help()
+
+ progress = apt.progress.text.CdromProgress()
+ cdrom = apt_pkg.Cdrom()
+
+ if not arguments:
+ return show_help()
+ elif arguments[0] == 'add':
+ cdrom.add(progress)
+ elif arguments[0] == 'ident':
+ cdrom.ident(progress)
+ else:
+ sys.stderr.write('E: Invalid operation %s\n' % arguments[0])
+ return 1
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
diff --git a/doc/source/examples/apt-gtk.py b/doc/source/examples/apt-gtk.py
index 835ea4ee..ad46454e 100644
--- a/doc/source/examples/apt-gtk.py
+++ b/doc/source/examples/apt-gtk.py
@@ -17,10 +17,10 @@ def main():
progress.show()
win.show()
cache = apt.cache.Cache(progress.open)
- if cache["xterm"].isInstalled:
- cache["xterm"].markDelete()
+ if cache["xterm"].is_installed:
+ cache["xterm"].mark_delete()
else:
- cache["xterm"].markInstall()
+ cache["xterm"].mark_install()
progress.show_terminal(expanded=True)
cache.commit(progress.fetch, progress.install)
gtk.main()
diff --git a/doc/source/examples/cache-packages.py b/doc/source/examples/cache-packages.py
index 1abe7cf2..72534303 100644
--- a/doc/source/examples/cache-packages.py
+++ b/doc/source/examples/cache-packages.py
@@ -6,17 +6,17 @@ import apt_pkg
def main():
"""Main."""
- apt_pkg.InitConfig()
- apt_pkg.InitSystem()
- cache = apt_pkg.GetCache()
+ apt_pkg.init_config()
+ apt_pkg.init_system()
+ cache = apt_pkg.Cache()
print "Essential packages:"
- for pkg in cache.Packages:
- if pkg.Essential:
- print " ", pkg.Name
+ for pkg in cache.packages:
+ if pkg.essential:
+ print " ", pkg.name
print "Important packages:"
- for pkg in cache.Packages:
- if pkg.Important:
- print " ", pkg.Name
+ for pkg in cache.packages:
+ if pkg.important:
+ print " ", pkg.name
if __name__ == "__main__":
main()
diff --git a/doc/source/examples/cache-pkgfile.py b/doc/source/examples/cache-pkgfile.py
index f25975d3..f4cc2e66 100644
--- a/doc/source/examples/cache-pkgfile.py
+++ b/doc/source/examples/cache-pkgfile.py
@@ -5,20 +5,20 @@ import apt_pkg
def main():
"""Example for PackageFile()"""
apt_pkg.init()
- cache = apt_pkg.GetCache()
- for pkgfile in cache.FileList:
- print 'Package-File:', pkgfile.FileName
- print 'Index-Type:', pkgfile.IndexType # 'Debian Package Index'
- if pkgfile.NotSource:
+ cache = apt_pkg.Cache()
+ for pkgfile in cache.file_list:
+ print 'Package-File:', pkgfile.filename
+ print 'Index-Type:', pkgfile.index_type # 'Debian Package Index'
+ if pkgfile.not_source:
print 'Source: None'
else:
- if pkgfile.Site:
+ if pkgfile.site:
# There is a source, and a site, print the site
- print 'Source:', pkgfile.Site
+ print 'Source:', pkgfile.site
else:
# It seems to be a local repository
print 'Source: Local package file'
- if pkgfile.NotAutomatic:
+ if pkgfile.not_automatic:
# The system won't be updated automatically (eg. experimental)
print 'Automatic: No'
else:
diff --git a/doc/source/examples/dpkg-contents.py b/doc/source/examples/dpkg-contents.py
index 99d1596f..24d7ce98 100644
--- a/doc/source/examples/dpkg-contents.py
+++ b/doc/source/examples/dpkg-contents.py
@@ -28,7 +28,7 @@ def format_mode(what, mode):
def callback(what, name, link, mode, uid, gid, size, mtime, major, minor):
- """callback for debExtract"""
+ """callback for deb_extract"""
s_mode = format_mode(what, mode)
s_owner = "%s/%s" % (pwd.getpwuid(uid)[0], grp.getgrgid(gid)[0])
s_size = "%9d" % size
@@ -47,7 +47,7 @@ def main():
fobj = open(sys.argv[1])
try:
- apt_inst.debExtract(fobj, callback, "data.tar.gz")
+ apt_inst.deb_extract(fobj, callback, "data.tar.gz")
finally:
fobj.close()
diff --git a/doc/source/examples/dpkg-extract.py b/doc/source/examples/dpkg-extract.py
index ced8652f..8d144029 100644
--- a/doc/source/examples/dpkg-extract.py
+++ b/doc/source/examples/dpkg-extract.py
@@ -17,7 +17,7 @@ def main():
fobj = open(sys.argv[1])
try:
- apt_inst.debExtractArchive(fobj, sys.argv[2])
+ apt_inst.deb_extract_archive(fobj, sys.argv[2])
finally:
fobj.close()
diff --git a/doc/source/examples/dpkg-info.py b/doc/source/examples/dpkg-info.py
index ff98d8b1..6be8595c 100644
--- a/doc/source/examples/dpkg-info.py
+++ b/doc/source/examples/dpkg-info.py
@@ -2,7 +2,7 @@
"""Emulate dpkg --info package.deb control-file"""
import sys
-from apt_inst import debExtractControl
+from apt_inst import deb_extract_control
def main():
@@ -12,7 +12,7 @@ def main():
sys.exit(0)
fobj = open(sys.argv[1])
try:
- print debExtractControl(fobj, sys.argv[2])
+ print deb_extract_control(fobj, sys.argv[2])
finally:
fobj.close()
diff --git a/doc/source/examples/missing-deps.py b/doc/source/examples/missing-deps.py
index 3ca16e45..7af18128 100644
--- a/doc/source/examples/missing-deps.py
+++ b/doc/source/examples/missing-deps.py
@@ -5,9 +5,9 @@ import apt_pkg
def fmt_dep(dep):
"""Format a Dependency object [of apt_pkg] as a string."""
- ret = dep.TargetPkg.Name
- if dep.TargetVer:
- ret += " (%s %s)" % (dep.CompType, dep.TargetVer)
+ ret = dep.target_pkg.name
+ if dep.target_ver:
+ ret += " (%s %s)" % (dep.comp_type, dep.target_ver)
return ret
@@ -15,15 +15,15 @@ def check_version(pkgver):
"""Check the version of the package"""
missing = []
- for or_group in pkgver.DependsList.get("Pre-Depends", []) + \
- pkgver.DependsList.get("Depends", []):
- if not any(dep.AllTargets() for dep in or_group):
+ for or_group in pkgver.depends_list.get("Pre-Depends", []) + \
+ pkgver.depends_list.get("Depends", []):
+ if not any(dep.all_targets() for dep in or_group):
# If none of the or-choices can be satisfied, add it to missing
missing.append(or_group)
if missing:
- print "Package:", pkgver.ParentPkg.Name
- print "Version:", pkgver.VerStr
+ print "Package:", pkgver.parent_pkg.name
+ print "Version:", pkgver.ver_str
print "Missing:",
print ", ".join(" | ".join(fmt_dep(dep) for dep in or_group)
for or_group in missing)
@@ -32,18 +32,18 @@ def check_version(pkgver):
def main():
"""The main function."""
- apt_pkg.InitConfig()
- apt_pkg.InitSystem()
+ apt_pkg.init_config()
+ apt_pkg.init_system()
- cache = apt_pkg.GetCache()
+ cache = apt_pkg.Cache()
- for pkg in sorted(cache.Packages, key=lambda pkg: pkg.Name):
+ for pkg in sorted(cache.packages, key=lambda pkg: pkg.name):
# pkg is from a list of packages, sorted by name.
- for version in pkg.VersionList:
+ for version in pkg.version_list:
# Check every version
- for pfile, _ in version.FileList:
- if (pfile.Origin == "Debian" and pfile.Component == "main" and
- pfile.Archive == "unstable"):
+ for pfile, _ in version.file_list:
+ if (pfile.origin == "Debian" and pfile.component == "main" and
+ pfile.archive == "unstable"):
# We only want packages from Debian unstable main.
check_version(version)
break
diff --git a/doc/source/examples/update-print-uris.py b/doc/source/examples/update-print-uris.py
new file mode 100644
index 00000000..dbe1dfde
--- /dev/null
+++ b/doc/source/examples/update-print-uris.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+"""Print out the URIs of all indexes files.
+
+This behaves somewhat like apt-get --print-uris update."""
+import apt_pkg
+
+
+def main():
+ apt_pkg.init_config()
+ apt_pkg.init_system()
+ acquire = apt_pkg.Acquire()
+ slist = apt_pkg.SourceList()
+ # Read the list
+ slist.read_main_list()
+ # Add all indexes to the fetcher.
+ slist.get_indexes(acquire, True)
+
+ # Now print the URI of every item.
+ for item in acquire.items:
+ print item.desc_uri
+
+if __name__ == '__main__':
+ main()