File: deb_inspect.py

package info (click to toggle)
python-apt 0.7.7.1%2Bnmu1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,276 kB
  • ctags: 930
  • sloc: cpp: 4,126; python: 3,108; makefile: 52
file content (47 lines) | stat: -rwxr-xr-x 1,195 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# some example for apt_inst

import apt_pkg
import apt_inst
import sys
import os.path

def Callback(What,Name,Link,Mode,UID,GID,Size,MTime,Major,Minor):
    """ callback for debExtract """
    
    print "%s '%s','%s',%u,%u,%u,%u,%u,%u,%u"\
          % (What,Name,Link,Mode,UID,GID,Size, MTime, Major, Minor);


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "need filename argumnet"
        sys.exit(1)
    file = sys.argv[1]

    print "Working on: %s" % file
    print "Displaying data.tar.gz:"
    apt_inst.debExtract(open(file), Callback, "data.tar.gz")

    print "Now extracting the control file:"
    control = apt_inst.debExtractControl(open(file))
    sections = apt_pkg.ParseSection(control)

    print "Maintainer is: "
    print sections["Maintainer"]

    print
    print "DependsOn: "
    depends = sections["Depends"]
    print apt_pkg.ParseDepends(depends)


    print "extracting archive"
    dir = "/tmp/deb"
    os.mkdir(dir)
    apt_inst.debExtractArchive(open(file),dir)
    def visit(arg, dirname, names):
        print "%s/" % dirname
        for file in names:
            print "\t%s" % file
    os.path.walk(dir, visit, None)