home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-debian / examples / debfile / dpkg-info < prev    next >
Encoding:
Text File  |  2008-08-09  |  1.8 KB  |  55 lines

  1. #!/usr/bin/python
  2.  
  3. # dpkg-info - DebFile's implementation of "dpkg --info"
  4. # Copyright (C) 2007 Stefano Zacchiroli <zack@debian.org>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10.  
  11.  
  12. """ (An approximation of) a 'dpkg --info' implementation relying on DebFile
  13. class. """
  14.  
  15. import os
  16. import stat
  17. import string
  18. import sys
  19.  
  20. from debian_bundle import debfile
  21.  
  22. if __name__ == '__main__':
  23.     if len(sys.argv) != 2:
  24.         print "Usage: dpkg-info DEB"
  25.         sys.exit(1)
  26.     fname = sys.argv[1]
  27.  
  28.     deb = debfile.DebFile(fname)
  29.     if deb.version == '2.0':
  30.         print ' new debian package, version %s.' % deb.version
  31.     print ' size %d bytes: control archive= %d bytes.' % (
  32.             os.stat(fname)[stat.ST_SIZE], deb['control.tar.gz'].size)
  33.     for fname in deb.control:   # print info about control part contents
  34.         content = deb.control[fname]
  35.         if not content:
  36.             continue
  37.         lines = content.split('\n')
  38.         ftype = ''
  39.         try:
  40.             if lines[0].startswith('#!'):
  41.                 ftype = lines[0].split()[0]
  42.         except IndexError:
  43.             pass
  44.         print '  %d bytes, %d lines, %s, %s' % (len(content), len(lines),
  45.                 fname, ftype)
  46.     for n, v in deb.debcontrol().iteritems(): # print DEBIAN/control fields
  47.         if n.lower() == 'description':  # increase indentation of long dsc
  48.             lines = v.split('\n')
  49.             shortDsc = lines[0]
  50.             longDsc = string.join(map(lambda l: ' ' + l, lines[1:]), '\n')
  51.             print ' %s: %s\n%s' % (n, shortDsc, longDsc)
  52.         else:
  53.             print ' %s: %s' % (n, v)
  54.  
  55.