Debian Codegraph @

examples/debfile/dpkg-info

raw
1 #!/usr/bin/python3
2
3 # dpkg-info - DebFile's implementation of "dpkg --info"
4 # Copyright (C) 2007 Stefano Zacchiroli <[email protected]>
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 sys
18
19 from debian import debfile
20
21 if __name__ == '__main__':
22 if len(sys.argv) != 2:
23 print("Usage: dpkg-info DEB")
24 sys.exit(1)
25 fname = sys.argv[1]
26
27 deb = debfile.DebFile(fname)
28 if deb.version == '2.0':
29 print(' new debian package, version %s.' % deb.version)
30 print(' size %d bytes: control archive= %d bytes.' % (
31 os.stat(fname)[stat.ST_SIZE], deb['control.tar.gz'].size))
32 for fname in deb.control: # print info about control part contents
33 content = deb.control[fname]
34 if not content:
35 continue
36 lines = content.split('\n')
37 ftype = ''
38 try:
39 if lines[0].startswith('#!'):
40 ftype = lines[0].split()[0]
41 except IndexError:
42 pass
43 print(' %d bytes, %d lines, %s, %s' % (len(content), len(lines),
44 fname, ftype))
45 for n, v in deb.debcontrol().items(): # print DEBIAN/control fields
46 if n.lower() == 'description': # increase indentation of long dsc
47 lines = v.split('\n')
48 short_dsc = lines[0]
49 long_dsc = '\n'.join(map(lambda l: ' ' + l, lines[1:]))
50 print(' %s: %s\n%s' % (n, short_dsc, long_dsc))
51 else:
52 print(' %s: %s' % (n, v))
53