File: lp-list-bugs

package info (click to toggle)
lptools 0.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 400 kB
  • sloc: python: 1,550; makefile: 6
file content (60 lines) | stat: -rwxr-xr-x 1,971 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
#! /usr/bin/python3
# -*- coding: UTF-8 -*-
"""Briefly list status of Launchpad bugs."""

# Copyright (c) 2010 Canonical Ltd.
#
# lp-set-dup 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.
#
# lp-set-dup 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 lp-set-dup; see the file COPYING.  If not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Authors:
#  Colin Watson <cjwatson@ubuntu.com>

import sys
from optparse import OptionParser

from lptools import config

from launchpadlib.errors import HTTPError


def main():
    usage = "Usage: %prog <bug> [...]"
    parser = OptionParser(usage)
    args = parser.parse_args()[1]
    if len(args) < 1:
        parser.error("Need at least one bug number")

    launchpad = config.get_launchpad("list-bugs")

    for bugnum in args:
        try:
            bug = launchpad.bugs[bugnum]
            print("Bug %s: %s" % (bugnum, bug.title))
            for task in bug.bug_tasks:
                print("  %s: %s" % (task.bug_target_name, task.status))
        except HTTPError as error:
            if error.response.status == 401:
                print(("E: Don't have enough permissions to access bug %s" %
                     bugnum), file=sys.stderr)
                print(error.content, file=sys.stderr)
                continue
            elif error.response.status == 404:
                print("E: Bug %s not found" % bugnum, file=sys.stderr)
            else:
                raise

if __name__ == '__main__':
    main()