2011-05-09 14:48:54 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
"""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
|
2011-05-09 14:57:28 +02:00
|
|
|
# along with bitesize; see the file COPYING. If not, write to the Free
|
2011-05-09 14:48:54 +02:00
|
|
|
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
# 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Daniel Holbach <daniel.holbach@canonical.com>
|
|
|
|
|
|
|
|
import sys
|
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
from launchpadlib.launchpad import Launchpad
|
|
|
|
from launchpadlib.errors import HTTPError
|
|
|
|
|
2011-05-09 15:35:23 +02:00
|
|
|
from ubuntutools.config import UDTConfig
|
2013-03-19 00:18:02 +01:00
|
|
|
from ubuntutools.logger import Logger
|
2011-05-09 15:35:23 +02:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2011-05-09 15:35:23 +02:00
|
|
|
def error_out(msg):
|
|
|
|
Logger.error(msg)
|
2011-05-09 14:48:54 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2011-05-23 15:49:06 +02:00
|
|
|
def save_entry(entry):
|
|
|
|
try:
|
|
|
|
entry.lp_save()
|
|
|
|
except HTTPError, error:
|
2011-05-23 17:51:18 +02:00
|
|
|
error_out(error.content)
|
2011-05-23 15:49:06 +02:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2011-05-23 15:49:06 +02:00
|
|
|
def tag_bug(bug):
|
2017-05-01 00:20:03 +02:00
|
|
|
bug.tags = bug.tags + ['bitesize'] # LP: #254901 workaround
|
2011-05-23 15:49:06 +02:00
|
|
|
save_entry(bug)
|
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2011-05-09 14:48:54 +02:00
|
|
|
def main():
|
|
|
|
usage = "Usage: %prog <bug number>"
|
|
|
|
opt_parser = OptionParser(usage)
|
2011-05-09 15:35:23 +02:00
|
|
|
opt_parser.add_option("-l", "--lpinstance", metavar="INSTANCE",
|
|
|
|
help="Launchpad instance to connect to "
|
|
|
|
"(default: production)",
|
|
|
|
dest="lpinstance", default=None)
|
|
|
|
opt_parser.add_option("--no-conf",
|
|
|
|
help="Don't read config files or "
|
|
|
|
"environment variables.",
|
|
|
|
dest="no_conf", default=False, action="store_true")
|
2011-05-09 14:48:54 +02:00
|
|
|
(options, args) = opt_parser.parse_args()
|
2011-05-09 15:35:23 +02:00
|
|
|
config = UDTConfig(options.no_conf)
|
|
|
|
if options.lpinstance is None:
|
|
|
|
options.lpinstance = config.get_value("LPINSTANCE")
|
2011-05-09 14:48:54 +02:00
|
|
|
if len(args) < 1:
|
|
|
|
opt_parser.error("Need at least one bug number.")
|
|
|
|
|
2011-05-09 15:35:23 +02:00
|
|
|
launchpad = Launchpad.login_with("ubuntu-dev-tools", options.lpinstance)
|
2011-05-09 14:48:54 +02:00
|
|
|
if launchpad is None:
|
2011-05-09 15:35:23 +02:00
|
|
|
error_out("Couldn't authenticate to Launchpad.")
|
2011-05-09 14:48:54 +02:00
|
|
|
|
|
|
|
# check that the new main bug isn't a duplicate
|
|
|
|
try:
|
|
|
|
bug = launchpad.bugs[args[0]]
|
|
|
|
except HTTPError, error:
|
|
|
|
if error.response.status == 401:
|
2017-05-01 00:20:03 +02:00
|
|
|
error_out("Don't have enough permissions to access bug %s. %s" %
|
2011-05-23 23:41:30 +02:00
|
|
|
(args[0], error.content))
|
2011-05-09 14:48:54 +02:00
|
|
|
else:
|
|
|
|
raise
|
2011-05-23 15:49:06 +02:00
|
|
|
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)
|
2017-05-01 00:20:03 +02:00
|
|
|
tag_bug(launchpad.bugs[bug.id]) # fresh bug object, LP: #336866 workaround
|
|
|
|
|
2011-05-09 14:48:54 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|