home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / python-apt / examples / deb_inspect.py < prev    next >
Encoding:
Python Source  |  2006-03-02  |  1.2 KB  |  48 lines

  1. #!/usr/bin/env python
  2. # some example for apt_inst
  3.  
  4. import apt_pkg
  5. import apt_inst
  6. import sys
  7. import os.path
  8.  
  9. def Callback(What,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor):
  10.     """ callback for debExtract """
  11.     
  12.     print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u"\
  13.           % (What,Name,Link,Mode,UID,GID,Size, MTime, Major, Minor);
  14.  
  15.  
  16. if __name__ == "__main__":
  17.     if len(sys.argv) < 2:
  18.         print "need filename argumnet"
  19.         sys.exit(1)
  20.     file = sys.argv[1]
  21.  
  22.     print "Working on: %s" % file
  23.     print "Displaying data.tar.gz:"
  24.     apt_inst.debExtract(open(file), Callback, "data.tar.gz")
  25.  
  26.     print "Now extracting the control file:"
  27.     control = apt_inst.debExtractControl(open(file))
  28.     sections = apt_pkg.ParseSection(control)
  29.  
  30.     print "Maintainer is: "
  31.     print sections["Maintainer"]
  32.  
  33.     print
  34.     print "DependsOn: "
  35.     depends = sections["Depends"]
  36.     print apt_pkg.ParseDepends(depends)
  37.  
  38.  
  39.     print "extracting archive"
  40.     dir = "/tmp/deb"
  41.     os.mkdir(dir)
  42.     apt_inst.debExtractArchive(open(file),dir)
  43.     def visit(arg, dirname, names):
  44.         print "%s/" % dirname
  45.         for file in names:
  46.             print "\t%s" % file
  47.     os.path.walk(dir, visit, None)
  48.