~xnox/ubuntu-archive-tools/sru-report-autopkgtest-vomit

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
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python

# Copyright (C) 2008, 2009, 2010, 2011, 2012  Canonical Ltd.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Adjust SRU bugs after accepting the corresponding update."""

from __future__ import print_function

from optparse import OptionParser
import re
import sys

import launchpadlib.errors
from launchpadlib.launchpad import Launchpad
from sru_workflow import process_bug


CONSUMER_KEY = "sru-accept"


def append_series(option, opt_str, value, parser):
    if value.endswith('-proposed'):
        value = value[:-9]
    parser.values.ensure_value(option.dest, []).append(value)


if __name__ == '__main__':
    parser = OptionParser(
        usage="Usage: %prog [options] -v version [options] bug [bug ...]")

    parser.add_option("-l", "--launchpad", dest="launchpad_instance",
                      default="production")
    parser.add_option('-s', action='callback', callback=append_series,
                      type='string', dest='targets',
                      help='accept for SUITE(-proposed) instead of current '
                           'stable release',
                      metavar='SUITE')
    parser.add_option('-p', dest='package',
                      help='only change tasks for a particular source package',
                      default=None,
                      metavar='SRCPACKAGE')
    parser.add_option('-v', dest='version',
                      help='the version of the package being accepted',
                      default=None,
                      metavar='VERSION')

    options, args = parser.parse_args()

    if not options.version:
        print('A package version (-v) was not provided.')
        sys.exit(1)

    launchpad = Launchpad.login_with(CONSUMER_KEY, options.launchpad_instance)
    if not options.targets:
        options.targets = [[
            series.name for series in launchpad.distributions["ubuntu"].series
            if series.status == "Current Stable Release"][0]]
    try:
        for num in args:
            for series in options.targets:
                process_bug(
                    launchpad, options.package, options.version, series, num)
    except launchpadlib.errors.HTTPError as err:
        print("There was an error:")
        print(err.content)