summaryrefslogtreecommitdiff
path: root/doc/source/examples
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-01-09 21:52:07 +0100
committerJulian Andres Klode <jak@debian.org>2009-01-09 21:52:07 +0100
commit6a806f0570599e8f5e9438c9623d496df75571d4 (patch)
tree8551d041ba84fabb51d452d9e24edf732fd677f8 /doc/source/examples
parentdb05cdcf94ca8e746eb4e89cd81725b607f2ccbf (diff)
downloadpython-apt-6a806f0570599e8f5e9438c9623d496df75571d4.tar.gz
* Introduce the new documentation and add 0.7.9~exp2 to changelog.
The new documentation is built using sphinx (>= 0.5) [other versions may work too, but let's be safe].
Diffstat (limited to 'doc/source/examples')
-rw-r--r--doc/source/examples/apt-gtk.py29
-rw-r--r--doc/source/examples/dpkg-contents.py55
-rw-r--r--doc/source/examples/dpkg-extract.py25
-rw-r--r--doc/source/examples/dpkg-info.py20
4 files changed, 129 insertions, 0 deletions
diff --git a/doc/source/examples/apt-gtk.py b/doc/source/examples/apt-gtk.py
new file mode 100644
index 00000000..c3bb09d5
--- /dev/null
+++ b/doc/source/examples/apt-gtk.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+"""Example for gtk widgets"""
+import pygtk
+pygtk.require("2.0")
+import gtk
+
+import apt.gtk.widgets
+
+
+def main():
+ """Main function."""
+ win = gtk.Window()
+ win.connect("destroy", gtk.main_quit)
+ progress = apt.gtk.widgets.GtkAptProgress()
+ win.set_title("GtkAptProgress Demo")
+ win.add(progress)
+ progress.show()
+ win.show()
+ cache = apt.cache.Cache(progress.open)
+ if cache["xterm"].isInstalled:
+ cache["xterm"].markDelete()
+ else:
+ cache["xterm"].markInstall()
+ progress.show_terminal(expanded=True)
+ cache.commit(progress.fetch, progress.install)
+ gtk.main()
+
+if __name__ == "__main__":
+ main()
diff --git a/doc/source/examples/dpkg-contents.py b/doc/source/examples/dpkg-contents.py
new file mode 100644
index 00000000..99d1596f
--- /dev/null
+++ b/doc/source/examples/dpkg-contents.py
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+"""Emulate dpkg --contents"""
+
+import grp
+import pwd
+import stat
+import sys
+import time
+
+import apt_inst
+
+
+def format_mode(what, mode):
+ """Return the symbolic mode"""
+ s_mode = dict(DIR="d", HARDLINK="h", FILE="-").get(what)
+ s_mode += ((mode & stat.S_IRUSR) and "r" or "-")
+ s_mode += ((mode & stat.S_IWUSR) and "w" or "-")
+ s_mode += ((mode & stat.S_IXUSR) and (mode & stat.S_ISUID and "s" or "x")
+ or (mode & stat.S_ISUID and "S" or "-"))
+ s_mode += ((mode & stat.S_IRGRP) and "r" or "-")
+ s_mode += ((mode & stat.S_IWGRP) and "w" or "-")
+ s_mode += ((mode & stat.S_IXGRP) and (mode & stat.S_ISGID and "s" or "x")
+ or (mode & stat.S_ISGID and "S" or "-"))
+ s_mode += ((mode & stat.S_IROTH) and "r" or "-")
+ s_mode += ((mode & stat.S_IWOTH) and "w" or "-")
+ s_mode += ((mode & stat.S_IXOTH) and "x" or "-")
+ return s_mode
+
+
+def callback(what, name, link, mode, uid, gid, size, mtime, major, minor):
+ """callback for debExtract"""
+ s_mode = format_mode(what, mode)
+ s_owner = "%s/%s" % (pwd.getpwuid(uid)[0], grp.getgrgid(gid)[0])
+ s_size = "%9d" % size
+ s_time = time.strftime("%Y-%m-%d %H:%M", time.localtime(mtime))
+ s_name = name.startswith(".") and name or ("./" + name)
+ if link:
+ s_name += " link to %s" % link
+ print s_mode, s_owner, s_size, s_time, s_name
+
+
+def main():
+ """Main function"""
+ if len(sys.argv) < 2:
+ print >> sys.stderr, "need filename argumnet"
+ sys.exit(1)
+
+ fobj = open(sys.argv[1])
+ try:
+ apt_inst.debExtract(fobj, callback, "data.tar.gz")
+ finally:
+ fobj.close()
+
+if __name__ == "__main__":
+ main()
diff --git a/doc/source/examples/dpkg-extract.py b/doc/source/examples/dpkg-extract.py
new file mode 100644
index 00000000..ced8652f
--- /dev/null
+++ b/doc/source/examples/dpkg-extract.py
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+"""Emulate dpkg --extract package.deb outdir"""
+import os
+import sys
+
+import apt_inst
+
+
+def main():
+ """Main function."""
+ if len(sys.argv) < 3:
+ print >> sys.stderr, "Usage:", __file__, "package.deb outdir"
+ sys.exit(1)
+ if not os.path.exists(sys.argv[2]):
+ print >> sys.stderr, "The directory %s does not exist" % sys.argv[2]
+ sys.exit(1)
+
+ fobj = open(sys.argv[1])
+ try:
+ apt_inst.debExtractArchive(fobj, sys.argv[2])
+ finally:
+ fobj.close()
+
+if __name__ == "__main__":
+ main()
diff --git a/doc/source/examples/dpkg-info.py b/doc/source/examples/dpkg-info.py
new file mode 100644
index 00000000..ff98d8b1
--- /dev/null
+++ b/doc/source/examples/dpkg-info.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+"""Emulate dpkg --info package.deb control-file"""
+import sys
+
+from apt_inst import debExtractControl
+
+
+def main():
+ """Main function."""
+ if len(sys.argv) < 3:
+ print >> sys.stderr, 'Usage: tool file.deb control-file'
+ sys.exit(0)
+ fobj = open(sys.argv[1])
+ try:
+ print debExtractControl(fobj, sys.argv[2])
+ finally:
+ fobj.close()
+
+if __name__ == '__main__':
+ main()