File: lp-bitesize

package info (click to toggle)
ubuntu-dev-tools 0.207
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,180 kB
  • sloc: python: 9,113; sh: 1,304; perl: 135; makefile: 10
file content (105 lines) | stat: -rwxr-xr-x 3,169 bytes parent folder | download | duplicates (3)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python3
"""Add 'bitesize' tag to bugs and add a comment."""

# Copyright (c) 2011 Canonical Ltd.
#
# bitesize 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; either version 3, or (at your option) any
# later version.
#
# bitesize 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 bitesize; see the file COPYING.  If not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Authors:
#  Daniel Holbach <daniel.holbach@canonical.com>

import argparse
import sys

from launchpadlib.errors import HTTPError
from launchpadlib.launchpad import Launchpad

from ubuntutools import getLogger
from ubuntutools.config import UDTConfig

Logger = getLogger()


def error_out(msg, *args):
    Logger.error(msg, *args)
    sys.exit(1)


def save_entry(entry):
    try:
        entry.lp_save()
    except HTTPError as error:
        error_out("%s", error.content)


def tag_bug(bug):
    bug.tags = bug.tags + ["bitesize"]  # LP: #254901 workaround
    save_entry(bug)


def main():
    parser = argparse.ArgumentParser(usage="%(prog)s [options] <bug number>")
    parser.add_argument(
        "-l",
        "--lpinstance",
        metavar="INSTANCE",
        help="Launchpad instance to connect to (default: production)",
        dest="lpinstance",
        default=None,
    )
    parser.add_argument(
        "--no-conf",
        help="Don't read config files or environment variables.",
        dest="no_conf",
        default=False,
        action="store_true",
    )
    parser.add_argument("bug_number", help=argparse.SUPPRESS)
    args = parser.parse_args()
    config = UDTConfig(args.no_conf)
    if args.lpinstance is None:
        args.lpinstance = config.get_value("LPINSTANCE")

    launchpad = Launchpad.login_with("ubuntu-dev-tools", args.lpinstance)
    if launchpad is None:
        error_out("Couldn't authenticate to Launchpad.")

    # check that the new main bug isn't a duplicate
    try:
        bug = launchpad.bugs[args.bug_number]
    except HTTPError as error:
        if error.response.status == 401:
            error_out(
                "Don't have enough permissions to access bug %s. %s",
                args.bug_number,
                error.content,
            )
        else:
            raise
    if "bitesize" in bug.tags:
        error_out("Bug is already marked as 'bitesize'.")
    bug.newMessage(
        content="I'm marking this bug as 'bitesize' as it looks "
        "like an issue that is easy to fix and suitable "
        "for newcomers in Ubuntu development. If you need "
        "any help with fixing it, talk to me about it."
    )
    bug.subscribe(person=launchpad.me)
    tag_bug(launchpad.bugs[bug.id])  # fresh bug object, LP: #336866 workaround


if __name__ == "__main__":
    main()