File: bugs.py

package info (click to toggle)
cruft-ng 0.9.72
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,400 kB
  • sloc: cpp: 1,737; sh: 796; python: 245; makefile: 108; ansic: 82; perl: 75
file content (66 lines) | stat: -rwxr-xr-x 2,299 bytes parent folder | download | duplicates (4)
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
62
63
64
65
66
#!/usr/bin/python3

import glob
import re
import sys

import debianbts as bts

# Shell: /bin/sh linked to /bin/dash
FALSE_POSITIVES = set(['/bin/sh', '/bin/dash',
                   '/usr/bin/sh', '/usr/bin/dash',
                   '/usr/sbin/piuparts',
                   '/usr/share/fonts',
                  ])

for dpkg_list in glob.glob('/var/lib/dpkg/info/*.list') + glob.glob('/var/lib/dpkg/info/*.conffiles'):
    with open(dpkg_list, 'r') as files:
        for file in files:
            FALSE_POSITIVES.add(file.rstrip('\n'))

# exclude "'" because it's added by dpkg in error messages
re_cruft = re.compile(r'/(?:bin|usr|etc|var|\.cache)/[A-Za-z0-9_\/\.\-]*')

# https://udd.debian.org/cgi-bin/bts-usertags.cgi?user=cruft-ng@packages.debian.org&tag=cruft
if len(sys.argv) > 1:
    bugs = [int(bug) for bug in sys.argv[1:]]
else:
    bugs = bts.get_usertag('cruft-ng@packages.debian.org', tags=['cruft'])['cruft']

cruft = dict()

todo: set[int] = set(bugs)
done: set[int] = set()

while todo:
    todo -= done
    for bug in bts.get_status(list(todo)):
        todo.update(set(bug.mergedwith))
        done.add(bug.bug_num)
        for match in re.findall(re_cruft, bug.subject):
            match = match.rstrip('./')
            if match in cruft:
                continue
            cruft[match] = (bug.bug_num, bug.source, bug.subject)
        for mail in bts.get_bug_log(bug.bug_num):
            for line in mail['body'].splitlines():
                if '---- missing: dpkg ----' in line:
                    # bug report contains cruft report, ignore from here
                    break
                for match in re.findall(re_cruft, line):
                    if match in FALSE_POSITIVES:
                        continue
                    if match.startswith('/var/lib/dpkg/'):
                        continue
                    if '  interest-noawait ' in line:
                        continue
                    match = match.rstrip('./')
                    if match in cruft:
                        # keep original bug report
                        continue
                    cruft[match] = (bug.bug_num, bug.source, line)

for path,data in sorted(cruft.items()):
    bug_nr, package, raw = data
    #print(raw)
    print('%s %s %s' % (path, bug_nr, package))