summaryrefslogtreecommitdiffstats
path: root/doc/examples/deb_inspect.py
blob: 72050e3427a17d6317450b8cd7849ac8fd74d5a7 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python3
# some example for apt_inst

import os.path
import sys

import apt_inst
import apt_pkg


def Callback(member, data):
    """callback for debExtract"""
    print(
        "'%s','%s',%u,%u,%u,%u,%u,%u,%u"
        % (
            member.name,
            member.linkname,
            member.mode,
            member.uid,
            member.gid,
            member.size,
            member.mtime,
            member.major,
            member.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.DebFile(open(file)).data.go(Callback)

    print("Now extracting the control file:")
    control = apt_inst.DebFile(open(file)).control.extractdata("control")
    sections = apt_pkg.TagSection(control)

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

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

    print("extracting archive")
    dir = "/tmp/deb"
    os.mkdir(dir)
    apt_inst.DebFile(open(file)).data.extractall(dir)

    def visit(arg, dirname, names):
        print("%s/" % dirname)
        for file in names:
            print("\t%s" % file)

    os.path.walk(dir, visit, None)