~juju-qa/lp-release-manager-tools/trunk

« back to all changes in this revision

Viewing changes to lp_release_tools/Lower_fixed_bugs.py

  • Committer: Curtis Hovey
  • Date: 2014-10-10 08:42:31 UTC
  • Revision ID: curtis@hovey.name-20141010084231-q3zabxkrk21b06n8
Always omit duplicates.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
"""Lower the importance of fixed bugs that are unreleased."""
 
3
from __future__ import print_function
 
4
 
 
5
import os
 
6
import sys
 
7
 
 
8
from optparse import OptionParser
 
9
 
 
10
from launchpadlib.launchpad import Launchpad
 
11
 
 
12
 
 
13
FIX_COMMITTED = u'Fix Committed'
 
14
 
 
15
 
 
16
def get_option_parser():
 
17
    """Return the option parser for this program."""
 
18
    example = "eg. %prog my-project 0.5.1"
 
19
    usage = "usage: %%prog [options] project <release|NONE> \n%s" % example
 
20
    parser = OptionParser(usage=usage)
 
21
    parser.add_option(
 
22
        "-s", "--service", dest="service",
 
23
        help="The service to use.")
 
24
    parser.add_option(
 
25
        "-c", "--credentials-file", dest="credentials_file",
 
26
        help="The credentials to use instead of yourself.")
 
27
    parser.add_option(
 
28
        "-t", "--tags", dest="tags",
 
29
        help="Match bugs with any of the listed tags.")
 
30
    parser.set_defaults(
 
31
        service='https://api.launchpad.net',
 
32
        tags=None,
 
33
        credentials_file=None)
 
34
    return parser
 
35
 
 
36
 
 
37
def lower_fixed_bugtask(bug_task):
 
38
    print('Updating bug %s [%s]' % (
 
39
        bug_task.bug.id, bug_task.bug.title))
 
40
    bug_task.importance = u'High'
 
41
    #bug_task.lp_save()
 
42
 
 
43
 
 
44
def main(argv=None):
 
45
    """Mark fix committed bugs as released for the users."""
 
46
    if argv is None:
 
47
        argv = sys.argv
 
48
    parser = get_option_parser()
 
49
    (options, args_) = parser.parse_args(args=argv[1:])
 
50
    if len(args_) < 2:
 
51
        # There is not a project and release.
 
52
        print(parser.usage)
 
53
        sys.exit(1)
 
54
    project = args_[0]
 
55
    release = args_[1]
 
56
    lp_args = dict(service_root=options.service, version='devel')
 
57
    if options.credentials_file:
 
58
        credentials_file = os.path.expanduser(options.credentials_file)
 
59
        lp_args['credentials_file'] = credentials_file
 
60
    lp = Launchpad.login_with('close_released_bugs', **lp_args)
 
61
    project = lp.projects[project]
 
62
    if release == 'NONE':
 
63
        milestone = None
 
64
    else:
 
65
        milestone = project.getMilestone(name=release)
 
66
    if options.tags is not None:
 
67
        tags = options.tags.split()
 
68
    else:
 
69
        tags = None
 
70
 
 
71
    if milestone is None:
 
72
        fixed_bug_tasks = project.searchTasks(
 
73
            status=FIX_COMMITTED, milestone=milestone,
 
74
            tags=tags)
 
75
    else:
 
76
        fixed_bug_tasks = milestone.searchTasks(status=FIX_COMMITTED)
 
77
 
 
78
    for bug_task in fixed_bug_tasks:
 
79
        lower_fixed_bugtask(bug_task)
 
80
    return 0
 
81
 
 
82
 
 
83
if __name__ == '__main__':
 
84
    sys.exit(main())