~james-page/ubuntu-reports/ca-cloud-fix

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
67
#!/usr/bin/python

from datetime import datetime
from lpltk import LaunchpadService

import optparse
import simplejson as json


def process_tasks(most_tasks):
    #bugs = {number: date-created, ....}
    bugs = {}
    for task in most_tasks:
        master_bug_num = task.bug.id
        dupes = {}
        for dupe in task.bug.duplicates:
            dupes[dupe.date_created] = dupe.id
        bugs[master_bug_num] = {}
        bugs[master_bug_num]['dupes'] = sorted(dupes.items())[-5:]
        bugs[master_bug_num]['title'] = task.bug.title
        bugs[master_bug_num]['count_of_dupes'] = len(task.bug.duplicates)
    return bugs


if __name__ == '__main__':
    lp = LaunchpadService(config=
        {'read_only': False,
         'display_name': 'foundations-recent-package-bug-tasks'})
    ubuntu = lp.load_project('ubuntu')

    parser = optparse.OptionParser()
    parser.add_option("--team", help="Team name")

    (opt, args) = parser.parse_args()

    data = []

    json_filename = "%s-most-duplicate-bugs.json" % (opt.team)

    if opt.team:
        team = lp.launchpad.people[opt.team]

    most_tasks = ubuntu.searchTasks(
        status=['New', 'Incomplete', 'Incomplete (with response)',
            'Incomplete (without response)', 'Confirmed', 'Triaged',
            'In Progress', 'Fix Committed'],
        bug_supervisor=team, order_by='-number_of_duplicates')[:50]

    bug_freq = process_tasks(most_tasks)
    #bug_totals = {}
    #for master_bug in bug_freq.keys():
    #    bug_totals[master_bug] = bug_freq[master_bug]['dupes']

    #sorted_totals = sorted(bug_totals, reverse=True)

    for bug in bug_freq:
        #from ipdb import set_trace; set_trace()
        pretty_dupes = {}
        for k, v in bug_freq[bug]['dupes']:
            pretty_dupes[v] = datetime.strftime(k, '%Y/%m/%d')
        data.append({'master': bug, 'dupes': pretty_dupes,
            'title': bug_freq[bug]['title'],
            'count_of_dupes': bug_freq[bug]['count_of_dupes']})

    json_file = open(json_filename, 'w')
    json_file.write(json.dumps(data, indent=4))
    json_file.close()