2019-09-04 18:27:03 -03:00
|
|
|
#!/usr/bin/python3
|
2010-07-29 00:00:33 +02:00
|
|
|
# -*- coding: UTF-8 -*-
|
2010-07-11 18:43:19 +02:00
|
|
|
|
2010-12-21 23:41:55 +02:00
|
|
|
# Copyright © 2009 James Westby <james.westby@ubuntu.com>,
|
2011-09-08 23:47:38 +02:00
|
|
|
# 2010, 2011 Stefano Rivera <stefanor@ubuntu.com>
|
2010-07-11 20:30:08 +02:00
|
|
|
#
|
|
|
|
# ##################################################################
|
|
|
|
#
|
|
|
|
# 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; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2010-07-11 20:30:08 +02:00
|
|
|
# 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, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# ##################################################################
|
|
|
|
|
2010-12-21 23:41:55 +02:00
|
|
|
from optparse import OptionParser, SUPPRESS_HELP
|
2010-07-11 18:43:19 +02:00
|
|
|
import re
|
|
|
|
import sys
|
2011-09-08 23:47:38 +02:00
|
|
|
import webbrowser
|
2010-12-21 23:41:55 +02:00
|
|
|
|
2013-03-19 00:43:31 +01:00
|
|
|
from launchpadlib.launchpad import Launchpad
|
|
|
|
|
|
|
|
from ubuntutools.config import UDTConfig
|
|
|
|
from ubuntutools.logger import Logger
|
|
|
|
|
2011-02-12 23:13:44 +01:00
|
|
|
try:
|
2019-09-04 18:27:03 -03:00
|
|
|
import debianbts
|
2011-02-12 23:13:44 +01:00
|
|
|
except ImportError:
|
2019-09-04 18:27:03 -03:00
|
|
|
Logger.error("Please install 'python3-debianbts' in order to use this utility.")
|
2011-02-12 23:13:44 +01:00
|
|
|
sys.exit(1)
|
2010-12-21 23:41:55 +02:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
def main():
|
|
|
|
bug_re = re.compile(r"bug=(\d+)")
|
|
|
|
|
|
|
|
parser = OptionParser(usage="%prog [option] bug ...")
|
|
|
|
parser.add_option("-b", "--browserless",
|
|
|
|
help="Don't open the bug in the browser at the end",
|
|
|
|
dest="browserless", action="store_true")
|
|
|
|
parser.add_option("-l", "--lpinstance", metavar="INSTANCE",
|
|
|
|
help="Launchpad instance to connect to "
|
|
|
|
"(default: production)",
|
|
|
|
dest="lpinstance", default=None)
|
|
|
|
parser.add_option("-n", "--dry-run",
|
|
|
|
help=SUPPRESS_HELP,
|
|
|
|
dest="lpinstance", action="store_const", const="staging")
|
2011-01-04 22:24:06 +02:00
|
|
|
parser.add_option("-p", "--package", metavar="PACKAGE",
|
|
|
|
help="Launchpad package to file bug against "
|
|
|
|
"(default: Same as Debian)",
|
|
|
|
dest="package", default=None)
|
2010-12-27 21:54:31 +01:00
|
|
|
parser.add_option("--no-conf", dest="no_conf", default=False,
|
|
|
|
help="Don't read config files or environment variables.",
|
|
|
|
action="store_true")
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
|
|
|
config = UDTConfig(options.no_conf)
|
|
|
|
if options.lpinstance is None:
|
|
|
|
options.lpinstance = config.get_value("LPINSTANCE")
|
|
|
|
|
2011-09-08 23:47:38 +02:00
|
|
|
launchpad = Launchpad.login_with("ubuntu-dev-tools", options.lpinstance)
|
2010-12-27 21:54:31 +01:00
|
|
|
|
|
|
|
debian = launchpad.distributions['debian']
|
|
|
|
ubuntu = launchpad.distributions['ubuntu']
|
|
|
|
lp_debbugs = launchpad.bug_trackers.getByName(name='debbugs')
|
|
|
|
|
|
|
|
bug_nums = []
|
|
|
|
|
|
|
|
for bug_num in args:
|
|
|
|
if bug_num.startswith("http"):
|
|
|
|
# bug URL
|
|
|
|
match = bug_re.search(bug_num)
|
|
|
|
if match is None:
|
2011-09-08 23:47:38 +02:00
|
|
|
Logger.error("Can't determine bug number from %s", bug_num)
|
|
|
|
sys.exit(1)
|
2010-12-27 21:54:31 +01:00
|
|
|
bug_num = match.groups()[0]
|
|
|
|
bug_num = bug_num.lstrip("#")
|
|
|
|
bug_num = int(bug_num)
|
|
|
|
bug_nums.append(bug_num)
|
|
|
|
|
2019-09-04 18:27:03 -03:00
|
|
|
bugs = debianbts.get_status(*bug_nums)
|
2010-12-27 21:54:31 +01:00
|
|
|
|
|
|
|
if len(bug_nums) > 1:
|
|
|
|
bugs = bugs[0]
|
|
|
|
|
2011-09-08 23:47:38 +02:00
|
|
|
if not bugs:
|
|
|
|
Logger.error("Cannot find any of the listed bugs")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
for bug in bugs:
|
2011-09-08 23:47:38 +02:00
|
|
|
ubupackage = package = bug.source
|
2011-01-04 22:24:06 +02:00
|
|
|
if options.package:
|
|
|
|
ubupackage = options.package
|
2010-12-27 21:54:31 +01:00
|
|
|
bug_num = bug.bug_num
|
|
|
|
subject = bug.subject
|
2019-09-04 18:27:03 -03:00
|
|
|
summary = bug.summary
|
|
|
|
log = debianbts.get_bug_log(bug_num)
|
|
|
|
summary = log[0]['body']
|
2011-01-04 22:24:06 +02:00
|
|
|
target = ubuntu.getSourcePackage(name=ubupackage)
|
2011-09-08 23:47:38 +02:00
|
|
|
if target is None:
|
|
|
|
Logger.error("Source package '%s' is not in Ubuntu. Please specify "
|
|
|
|
"the destination source package with --package",
|
|
|
|
ubupackage)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
u_bug = launchpad.bugs.createBug(
|
|
|
|
target=target, title=subject,
|
|
|
|
description='Imported from Debian bug http://bugs.debian.org/%d:\n\n%s' %
|
|
|
|
(bug_num, summary))
|
2011-01-04 22:24:06 +02:00
|
|
|
d_sp = debian.getSourcePackage(name=package)
|
|
|
|
if d_sp is None and options.package:
|
|
|
|
d_sp = debian.getSourcePackage(name=options.package)
|
|
|
|
d_task = u_bug.addTask(target=d_sp)
|
2010-12-27 21:54:31 +01:00
|
|
|
d_watch = u_bug.addWatch(remote_bug=bug_num, bug_tracker=lp_debbugs)
|
|
|
|
d_task.bug_watch = d_watch
|
|
|
|
d_task.lp_save()
|
2011-09-08 23:47:38 +02:00
|
|
|
Logger.normal("Opened %s", u_bug.web_link)
|
2010-12-27 21:54:31 +01:00
|
|
|
if not options.browserless:
|
2011-09-08 23:47:38 +02:00
|
|
|
webbrowser.open(u_bug.web_link)
|
2010-12-27 21:54:31 +01:00
|
|
|
|
2017-05-01 00:20:03 +02:00
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|