Debian Codegraph @

bin/lp-bug-dupe-properties

raw
1 #!/usr/bin/python3
2 #
3 # Copyright (C) 2012, Canonical Ltd.
4 # Written by Brian Murray
5 #
6 # ##################################################################
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; version 3.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # See file /usr/share/common-licenses/GPL-3 for more details.
18 #
19 # ##################################################################
20
21 from lptools import config
22 from datetime import datetime
23
24 import argparse
25 import sys
26
27 release_tags = []
28
29 def check_duplicate(bug, prop, key):
30 if prop == 'reporter':
31 return bug.owner.name
32 if prop == 'month':
33 return datetime.strftime(bug.date_created, '%Y-%m')
34 if prop == 'day':
35 return datetime.strftime(bug.date_created, '%Y-%m-%d')
36 if prop == 'tags':
37 return ' '.join(bug.tags)
38 if prop == 'rtags':
39 rtags = set(release_tags).intersection(bug.tags)
40 return ' '.join(list(rtags))
41 if prop == 'desc':
42 APPORT_TAGS = ['apport-crash', 'apport-bug', 'apport-kerneloops', 'apport-package']
43 if not set(APPORT_TAGS).intersection(bug.tags):
44 return
45 description = bug.description
46 if key not in description:
47 return
48 for line in description.splitlines():
49 if not line.startswith(key):
50 continue
51 if key == line.split(': ')[0]:
52 value = line.split(': ')[-1]
53 return value
54
55
56 def main():
57 parser = argparse.ArgumentParser(prog='lp-bug-dupe-properties')
58 group = parser.add_mutually_exclusive_group()
59 group.add_argument('-r', '--reporter', default=False,
60 action='store_true', help='Display reporter of duplicates')
61 group.add_argument('-m', '--month', default=False,
62 action='store_true', help='Display month duplicates were reported')
63 group.add_argument('-d', '--day', default=False,
64 action='store_true', help='Display day duplicates were reported')
65 group.add_argument('-t', '--tags', default=False,
66 action='store_true', help='Display tags of duplicates')
67 group.add_argument('-rt', '--rtags', default=False,
68 action='store_true', help='Display Ubuntu release tags of duplicates')
69 group.add_argument('-D', '--desc', default=False, type=str,
70 help='Search apport bug description for this key e.g. Package')
71 parser.add_argument('-b', '--bug', type=int,
72 help='Bug number of which to check the duplicates')
73
74 opts = parser.parse_args()
75 launchpad = config.get_launchpad("bug-dupe-properties")
76
77 bug_number = opts.bug
78 bug = launchpad.bugs[bug_number]
79
80 dupe_props = {}
81
82 if opts.reporter:
83 search = 'reporter'
84 if opts.month:
85 search = 'month'
86 if opts.day:
87 search = 'day'
88 if opts.tags:
89 search = 'tags'
90 if opts.rtags:
91 search = 'rtags'
92 ubuntu = launchpad.distributions['ubuntu']
93 for series in ubuntu.series:
94 release_tags.append(series.name)
95 if opts.desc:
96 search = 'desc'
97 key = opts.desc
98 else:
99 key = None
100
101 if bug.number_of_duplicates == 0:
102 print(('LP: #%s has no duplicates!' % bug_number))
103 sys.exit(1)
104
105 for dupe in bug.duplicates:
106 dupe_num = dupe.id
107 prop = check_duplicate(dupe, search, key)
108 if prop in list(dupe_props.keys()):
109 dupe_props[prop].append(str(dupe_num))
110 else:
111 dupe_props[prop] = [str(dupe_num)]
112
113 dupe_count = bug.number_of_duplicates
114 if dupe_count > 1:
115 print(('LP: #%s has %s duplicates' % (bug_number, dupe_count)))
116 elif dupe_count == 1:
117 print(('LP: #%s has %s duplicate' % (bug_number, dupe_count)))
118
119 for prop, bugs in sorted(dupe_props.items()):
120 print((' %s: %s' % (prop, ' '.join(bugs))))
121
122
123 if __name__ == '__main__':
124 main()