2007-09-12 01:14:23 +10:00
#!/usr/bin/python
2007-11-07 20:05:37 +01:00
# -*- coding: utf-8 -*-
2008-05-22 16:50:05 +02:00
#
2007-12-01 22:56:45 +01:00
# (C) 2007 Canonical Ltd., Steve Kowalik
2007-09-12 01:14:23 +10:00
# Authors:
2008-05-22 16:50:05 +02:00
# Martin Pitt <martin.pitt@ubuntu.com>
# Steve Kowalik <stevenk@ubuntu.com>
# Michael Bienia <geser@ubuntu.com> (python-launchpad-bugs support)
# Daniel Hahler <ubuntu@thequod.de>
2008-05-22 18:55:45 +01:00
# Iain Lane <iain@orangesquash.org.uk>
2008-12-29 18:58:11 +00:00
# Jonathan Davies <jpds@ubuntu.com>
2009-01-13 21:43:14 +00:00
# Markus Korn <thekorn@gmx.de> (python-launchpadlib support)
2008-01-19 15:40:28 +01:00
#
2008-08-11 20:06:35 +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; version 2.
#
# 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.
#
# See file /usr/share/common-licenses/GPL-2 for more details.
#
# ##################################################################
2007-09-12 01:14:23 +10:00
2008-08-12 13:52:05 +01:00
import os
import subprocess
import sys
import urllib
2008-08-18 12:07:45 +02:00
import urllib2
2008-02-09 18:29:09 +01:00
from debian_bundle.changelog import Version
2009-01-02 00:17:49 +00:00
from optparse import OptionParser
2009-01-02 13:18:53 +00:00
from time import sleep
2007-09-12 01:14:23 +10:00
2009-01-19 18:10:53 +00:00
# ubuntu-dev-tools modules.
2009-01-19 22:37:27 +00:00
import ubuntutools.lp.cookie as lp_cookie
import ubuntutools.lp.functions as lp_functions
import ubuntutools.lp.libsupport as lp_libsupport
import ubuntutools.lp.urlopener as lp_urlopener
2008-08-12 13:52:05 +01:00
2009-01-19 22:37:27 +00:00
launchpad_cookiefile = lp_cookie.prepareLaunchpadCookie()
2008-08-12 13:52:05 +01:00
2008-08-12 15:42:55 +01:00
def checkNeedsSponsorship(component):
2008-08-12 13:52:05 +01:00
"""
Check that the user has the appropriate permissions by checking what
Launchpad returns while authenticating with their cookie.
2008-04-16 02:05:58 +02:00
2008-08-12 13:52:05 +01:00
If they are an indirect or direct member of the ~ubuntu-dev team on
2008-08-12 15:42:55 +01:00
Launchpad - sponsorship is not required if the package is in the
universe / multiverse component.
If they are in the ~ubuntu-core-dev team, no sponsorship required.
2008-08-12 13:52:05 +01:00
The prepareLaunchpadCookie function above shall ensure that a cookie
file exists first.
"""
2009-01-07 09:37:41 +01:00
# TODO: use launchpadlib here
# Once LP: #313233 has been fixed this can be implemented by either:
# >>> me = launchpad.me
# >>> me.inTeam(<TEAM>) #or
# >>> me in <TEAM>
2009-01-19 22:37:27 +00:00
urlopener = lp_urlopener.setupLaunchpadUrlOpener(launchpad_cookiefile)
2008-08-12 18:18:11 +01:00
# Check where the package is and assign the appropriate variables.
2008-08-12 15:42:55 +01:00
if component in ['main', 'restricted']:
team = "ubuntu-core-dev"
sponsor = "ubuntu-main-sponsors"
else:
team = "ubuntu-dev"
sponsor = "ubuntu-universe-sponsors"
2008-08-12 15:46:44 +01:00
2008-08-28 19:21:45 +01:00
# Check if they are a member of the team.
2009-01-19 22:37:27 +00:00
teamMember = lp_functions.isLPTeamMember(team)
2008-08-28 19:21:45 +01:00
if not teamMember:
2008-08-12 15:46:44 +01:00
print "You are not a member (direct or indirect) of the '%s' " \
2008-08-12 15:42:55 +01:00
"team on Launchpad." % team
2008-08-12 13:52:05 +01:00
print "Your sync request shall require an approval by a member of " \
2008-08-12 18:18:11 +01:00
"the '%s'\nteam, who shall be subscribed to this bug report." % sponsor
print "This must be done before it can be processed by a member of " \
"the Ubuntu Archive team."
2008-11-07 16:58:22 +00:00
print "If the above is correct please press Enter, otherwise please " \
"press Ctrl-C to stop this script now\nand check the cookie file " \
"at:", launchpad_cookiefile
2009-01-02 00:17:49 +00:00
print "Logging into Launchpad, deleting the above and rerunning this " \
"script should be enough to generate the cookie."
2008-08-12 18:18:11 +01:00
raw_input_exit_on_ctrlc() # Abort if necessary.
2008-08-12 13:52:05 +01:00
return True # Sponsorship required.
2007-09-12 01:14:23 +10:00
2008-08-28 19:21:45 +01:00
# Is a team member, no sponsorship required.
return False
2008-09-01 22:29:32 +01:00
def checkExistingReports(package):
""" Check existing bug reports on Launchpad for a possible sync request.
If found ask for confirmation on filing a request.
"""
2009-01-05 08:49:12 +01:00
2009-01-17 14:33:29 +00:00
launchpad = None
2009-01-02 17:52:51 +01:00
try:
2009-01-19 22:37:27 +00:00
launchpad = lp_libsupport.get_launchpad("ubuntu-dev-tools")
2009-01-02 17:52:51 +01:00
except ImportError:
2009-01-05 08:49:12 +01:00
print >> sys.stderr, 'Importing launchpadlib failed. Is ' \
'python-launchpadlib installed?'
2009-01-17 11:14:40 +00:00
except IOError, msg:
# No credentials found.
print msg
2009-01-17 14:33:29 +00:00
# Failed to get Launchpad credentials.
if launchpad is None:
print >> sys.stderr, "Skipping existing report check, you should "\
"manually see if there are any at:"
print "- https://bugs.launchpad.net/ubuntu/+source/%s" % package
print ""
return False
2008-09-01 22:29:32 +01:00
2008-09-02 09:54:26 +01:00
# Fetch the package's bug list from Launchpad.
2009-01-07 10:11:06 +01:00
pkg = launchpad.distributions["ubuntu"].getSourcePackage(name=package)
2009-01-02 17:52:51 +01:00
pkgBugList = pkg.searchTasks()
2008-09-01 22:29:32 +01:00
2008-09-02 09:54:26 +01:00
# Search bug list for other sync requests.
2008-09-01 23:12:38 +01:00
matchingBugs = [bug for bug in pkgBugList if "Please sync %s" %
2009-01-02 17:52:51 +01:00
package in bug.title]
2008-09-01 23:12:38 +01:00
if len(matchingBugs) == 0:
return # No sync bugs found.
print "The following bugs could be possible duplicate sync bug(s) on Launchpad:"
for bug in matchingBugs:
2009-01-02 17:52:51 +01:00
print " *", bug.title
2009-01-19 22:37:27 +00:00
print " -", lp_libsupport.translate_api_web(bug.self_link)
2008-09-01 23:12:38 +01:00
2008-09-02 09:54:26 +01:00
print "Please check the above URLs to verify this before filing a " \
"possible duplicate report."
2008-09-01 23:12:38 +01:00
print "Press Ctrl-C to stop filing the bug report now, otherwise " \
"please press enter."
raw_input_exit_on_ctrlc()
2008-09-01 22:29:32 +01:00
2007-09-12 01:14:23 +10:00
def cur_version_component(sourcepkg, release):
2008-01-19 15:40:28 +01:00
'''Determine current package version in ubuntu.'''
2007-09-12 01:14:23 +10:00
madison = subprocess.Popen(['rmadison', '-u', 'ubuntu', '-a', 'source', \
2008-01-19 15:40:28 +01:00
'-s', release, sourcepkg], stdout=subprocess.PIPE)
2007-09-12 01:14:23 +10:00
out = madison.communicate()[0]
assert (madison.returncode == 0)
for l in out.splitlines():
2008-02-09 04:03:38 +01:00
(pkg, version, rel, builds) = l.split('|')
component = 'main'
if rel.find('/') != -1:
component = rel.split('/')[1]
return (version.strip(), component.strip())
2007-09-12 01:14:23 +10:00
print "%s doesn't appear to exist in %s, specify -n for a package not in Ubuntu." % (sourcepkg, release)
sys.exit(1)
2008-08-23 18:14:33 +02:00
def cur_deb_version(sourcepkg, distro):
'''Return the current debian version of a package in a Debian distro.'''
2007-10-05 14:20:22 +02:00
madison = subprocess.Popen(['rmadison', '-u', 'debian', '-a', 'source', \
2008-08-23 18:14:33 +02:00
'-s', distro, sourcepkg], \
2007-10-05 14:20:22 +02:00
stdout=subprocess.PIPE)
out = madison.communicate()[0]
assert (madison.returncode == 0)
try:
assert out
except AssertionError:
print "%s doesn't appear to exist in Debian." % sourcepkg
sys.exit(1)
2008-01-17 18:40:17 +01:00
# Work-around for a bug in Debians madison.php script not returning
# only the source line
for line in out.splitlines():
if line.find('source') > 0:
out = line
2007-10-05 14:20:22 +02:00
2007-12-30 17:07:35 +01:00
return out.split('|')[1].rstrip('[]''').strip()
2007-10-05 14:20:22 +02:00
2007-09-12 01:14:23 +10:00
def debian_changelog(sourcepkg, component, version):
'''Return the Debian changelog from the latest up to the given version
(exclusive).'''
2008-02-09 18:29:09 +01:00
base_version = Version(version)
2007-09-12 01:14:23 +10:00
ch = ''
subdir = sourcepkg[0]
2008-08-27 23:28:05 +01:00
2007-09-12 01:14:23 +10:00
if sourcepkg.startswith('lib'):
subdir = 'lib%s' % sourcepkg[3]
2008-08-27 23:28:05 +01:00
# Get the debian/changelog file from packages.debian.org.
try:
debianChangelogPage = urllib2.urlopen('http://packages.debian.org/changelogs/pool/%s/%s/%s/current/changelog.txt' % (component, subdir, sourcepkg))
except urllib2.HTTPError, error:
print >> sys.stderr, "Unable to connect to packages.debian.org. " \
"Received a %s." % error.code
sys.exit(1)
for l in debianChangelogPage:
2008-02-09 18:29:09 +01:00
if l.startswith(sourcepkg):
ch_version = l[ l.find("(")+1 : l.find(")") ]
if Version(ch_version) <= base_version:
break
2007-09-12 01:14:23 +10:00
ch += l
return ch
2008-08-23 18:14:33 +02:00
def debian_component(sourcepkg, distro):
2007-09-12 01:14:23 +10:00
'''Return the Debian component for the source package.'''
2008-08-23 18:14:33 +02:00
madison = subprocess.Popen(['rmadison', '-u', 'debian', '-a', 'source', '-s', distro, \
2007-09-12 01:14:23 +10:00
sourcepkg], stdout=subprocess.PIPE)
out = madison.communicate()[0]
assert (madison.returncode == 0)
try:
assert out
except AssertionError:
print "%s doesn't appear to exist in Debian." % sourcepkg
sys.exit(1)
2007-10-05 14:20:22 +02:00
raw_comp = out.split('|')[2].split('/')
2007-09-12 01:14:23 +10:00
component = 'main'
if len(raw_comp) == 2:
2007-12-30 17:07:35 +01:00
component = raw_comp[1].strip()
2007-09-12 01:14:23 +10:00
return component
2008-04-16 02:05:58 +02:00
def raw_input_exit_on_ctrlc(*args, **kwargs):
"""A wrapper around raw_input() to exit with a normalized message on Control-C"""
2008-02-09 02:52:22 +01:00
try:
2008-04-16 02:05:58 +02:00
return raw_input(*args, **kwargs)
2008-02-09 02:52:22 +01:00
except KeyboardInterrupt:
print 'Abort requested. No sync request filed.'
2008-02-09 04:03:38 +01:00
sys.exit(1)
2008-02-09 02:52:22 +01:00
2008-08-04 15:16:07 +02:00
def get_email_address():
'''Get the DEBEMAIL environment variable or give an error.'''
myemailaddr = os.getenv('DEBEMAIL')
if not myemailaddr:
print >> sys.stderr, 'The environment variable DEBEMAIL needs to be ' +\
' set to make use of this script, unless you use option --lp.'
return myemailaddr
2008-01-19 15:40:28 +01:00
def mail_bug(source_package, subscribe, status, bugtitle, bugtext, keyid = None):
'''Submit the sync request per email.
Return True if email successfully send, otherwise False.'''
import smtplib
2008-04-16 02:25:33 +02:00
import socket
2008-01-19 15:40:28 +01:00
to = 'new@bugs.launchpad.net'
2008-08-04 15:16:07 +02:00
myemailaddr = get_email_address()
2008-01-19 15:40:28 +01:00
if not myemailaddr:
return False
2008-04-16 14:44:30 +02:00
# generate initial mailbody
2008-01-19 15:40:28 +01:00
mailbody = ''
if source_package:
mailbody += ' affects ubuntu/%s\n' % source_package
else:
mailbody += ' affects ubuntu\n'
mailbody = mailbody + ' status %s\n importance wishlist\n subscribe %s\n\n%s' % (status, subscribe, bugtext)
2008-04-16 14:44:30 +02:00
# prepare sign_command
2008-01-19 15:40:28 +01:00
sign_command = 'gpg'
for cmd in ('gpg2', 'gnome-gpg'):
if os.access('/usr/bin/%s' % cmd, os.X_OK):
sign_command = cmd
gpg_command = [sign_command, '--clearsign']
if keyid:
gpg_command.extend(('-u', keyid))
2008-04-16 02:05:58 +02:00
in_confirm_loop = True
while in_confirm_loop:
# sign it
gpg = subprocess.Popen(gpg_command, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
signed_report = gpg.communicate(mailbody)[0]
assert gpg.returncode == 0
# generate email
mail = 'From: %s\nTo: %s\nSubject: %s\n\n%s' % (myemailaddr, to, bugtitle, signed_report)
# ask for confirmation and allow to edit:
print mail
print 'Do you want to edit the report before sending [y/N]? Press Control-C to abort.'
while 1:
val = raw_input_exit_on_ctrlc()
if val.lower() in ('y', 'yes'):
(bugtitle, mailbody) = edit_report(bugtitle, mailbody)
break
elif val.lower() in ('n', 'no', ''):
in_confirm_loop = False
break
else:
print "Invalid answer"
2008-01-19 15:40:28 +01:00
# get server address
mailserver = os.getenv('DEBSMTP')
if mailserver:
print 'Using custom SMTP server:', mailserver
else:
mailserver = 'fiordland.ubuntu.com'
# get server port
mailserver_port = os.getenv('DEBSMTP_PORT')
if mailserver_port:
print 'Using custom SMTP port:', mailserver_port
else:
mailserver_port = 25
# connect to the server
2008-04-16 02:25:33 +02:00
try:
s = smtplib.SMTP(mailserver, mailserver_port)
except socket.error, s:
2008-08-18 11:01:04 +01:00
print >> sys.stderr, "Could not connect to mailserver %s at port %s: %s (%i)" % \
2008-04-16 02:25:33 +02:00
(mailserver, mailserver_port, s[1], s[0])
2008-08-15 22:08:10 +01:00
print "The port %s may be firewalled. Please try using requestsync with" \
% mailserver_port
2009-01-02 17:52:51 +01:00
print "the '--lp' flag to file a sync request with the launchpadlib " \
2008-08-15 22:08:10 +01:00
"module."
2008-04-16 02:25:33 +02:00
return False
2008-01-19 15:40:28 +01:00
# authenticate to the server
mailserver_user = os.getenv('DEBSMTP_USER')
mailserver_pass = os.getenv('DEBSMTP_PASS')
if mailserver_user and mailserver_pass:
try:
2008-02-09 04:03:38 +01:00
s.login(mailserver_user, mailserver_pass)
2008-01-19 15:40:28 +01:00
except smtplib.SMTPAuthenticationError:
print 'Error authenticating to the server: invalid username and password.'
s.quit()
return False
except:
print 'Unknown SMTP error.'
s.quit()
return False
2007-09-12 01:14:23 +10:00
2008-01-19 15:40:28 +01:00
s.sendmail(myemailaddr, to, mail)
s.quit()
print 'Sync request mailed.'
return True
2008-02-09 04:00:46 +01:00
def post_bug(source_package, subscribe, status, bugtitle, bugtext):
2009-01-07 09:18:33 +01:00
'''Use python-launchpadlib to submit the sync request.
2008-04-16 02:05:58 +02:00
Return True if successfully posted, otherwise False.'''
2008-01-19 15:40:28 +01:00
import glob, os.path
try:
2009-01-19 22:37:27 +00:00
launchpad = lp_libsupport.get_launchpad("ubuntu-dev-tools")
2008-01-19 15:40:28 +01:00
except ImportError:
2009-01-02 17:52:51 +01:00
print >> sys.stderr, 'Importing launchpadlib failed. Is python-launchpadlib installed?'
2008-01-19 15:40:28 +01:00
return False
2009-01-17 11:14:40 +00:00
except IOError, msg:
# No credentials found.
print msg
sys.exit(1)
2008-01-19 15:40:28 +01:00
if source_package:
2009-01-02 17:52:51 +01:00
product_url = "%subuntu/+source/%s" %(launchpad._root_uri, source_package)
2007-09-12 01:14:23 +10:00
else:
2008-01-19 15:40:28 +01:00
# new source package
2009-01-02 17:52:51 +01:00
product_url = "%subuntu" %launchpad._root_uri
2008-04-16 02:05:58 +02:00
in_confirm_loop = True
while in_confirm_loop:
print 'Summary:\n%s\n\nDescription:\n%s' % (bugtitle, bugtext)
2007-09-12 01:14:23 +10:00
2008-04-16 02:05:58 +02:00
# ask for confirmation and allow to edit:
print 'Do you want to edit the report before sending [y/N]? Press Control-C to abort.'
while 1:
val = raw_input_exit_on_ctrlc()
if val.lower() in ('y', 'yes'):
(bugtitle, bugtext) = edit_report(bugtitle, bugtext)
break
elif val.lower() in ('n', 'no', ''):
in_confirm_loop = False
break
else:
2009-01-02 13:18:53 +00:00
print "Invalid answer."
2007-09-12 01:14:23 +10:00
2008-01-19 15:40:28 +01:00
# Create bug
2009-01-02 17:52:51 +01:00
bug = launchpad.bugs.createBug(description=bugtext, title=bugtitle, target=product_url)
#newly created bugreports have one task
task = bug.bug_tasks[0]
2009-01-25 00:15:06 +00:00
# Only members of ubuntu-bugs can set importance
if lp_functions.isLPTeamMember('ubuntu-bugs'):
task.transitionToImportance(importance='Wishlist')
2009-01-02 17:52:51 +01:00
task.transitionToStatus(status=status)
subscribe_url = "%s~%s" %(launchpad._root_uri, subscribe)
bug.subscribe(person=subscribe_url)
2007-09-12 01:14:23 +10:00
2009-01-19 18:13:28 +00:00
print 'Sync request filed as bug #%i: %s' % (bug.id,
2009-01-19 22:37:27 +00:00
lp_libsupport.translate_api_web(bug.self_link))
2008-01-19 15:40:28 +01:00
return True
2008-04-16 02:05:58 +02:00
def edit_report(subject, body, changes_required=False):
"""Edit a report (consisting of subject and body) in sensible-editor.
subject and body get decorated, before they are written to the temporary
file and undecorated after editing again.
If changes_required is True and the file has not been edited
(according to its mtime), an error is written to STDERR and the
program exits.
Returns (new_subject, new_body).
"""
2008-08-12 14:07:51 +01:00
import re
import string
2008-04-16 02:05:58 +02:00
report = "Summary (one line):\n%s\n\nDescription:\n%s" % (subject, body)
# Create tempfile and remember mtime
import tempfile
report_file = tempfile.NamedTemporaryFile( prefix='requestsync_' )
report_file.file.write(report)
report_file.file.flush()
mtime_before = os.stat( report_file.name ).st_mtime
# Launch editor
try:
editor = subprocess.check_call( ['sensible-editor', report_file.name] )
except subprocess.CalledProcessError, e:
print >> sys.stderr, 'Error calling sensible-editor: %s\nAborting.' % (e,)
sys.exit(1)
# Check if the tempfile has been changed
if changes_required:
report_file_info = os.stat( report_file.name )
if mtime_before == os.stat( report_file.name ).st_mtime:
print >> sys.stderr, 'The temporary file %s has not been changed, but you have\nto explain why the Ubuntu changes can be dropped. Aborting. [Press ENTER]' % (report_file.name,)
raw_input()
sys.exit(1)
report_file.file.seek(0)
report = report_file.file.read()
report_file.file.close()
# Undecorate report again:
(new_subject, new_body) = report.split("\nDescription:\n", 1)
# Remove prefix and whitespace for subject:
new_subject = string.rstrip( re.sub("\n", " ", re.sub("^Summary \(one line\):\s*", "", new_subject, 1)) )
return (new_subject, new_body)
2008-01-19 15:40:28 +01:00
#
# entry point
#
if __name__ == '__main__':
2009-01-02 00:17:49 +00:00
# Our usage options.
usage = "Usage: %prog [-d distro] [-k keyid] [-n] [--lp] [-s] <source "
usage += "package> <target release> [base version]"
optParser = OptionParser(usage)
optParser.add_option("-d", type = "string",
dest = "dist", default = "unstable",
help = "Debian distribution to sync from.")
optParser.add_option("-k", type = "string",
dest = "keyid", default = None,
help = "GnuPG key ID to use for signing report.")
optParser.add_option("-n", action = "store_true",
dest = "newpkg", default = False,
help = "Whether package to sync is a new package in Ubuntu.")
optParser.add_option("--lp", action = "store_true",
dest = "lpbugs", default = False,
2009-01-07 09:18:33 +01:00
help = "Specify whether to use the launchpadlib module for filing " \
2009-01-02 00:17:49 +00:00
"report.")
optParser.add_option("-s", action = "store_true",
dest = "sponsor", default = False,
help = "Force sponsorship requirement (shall be autodetected if not " \
"specified).")
(options, args) = optParser.parse_args()
newsource = options.newpkg
sponsorship = options.sponsor
keyid = options.keyid
use_lp_bugs = options.lpbugs
2008-02-09 02:52:22 +01:00
need_interaction = False
2009-01-02 00:17:49 +00:00
distro = options.dist
2008-08-12 13:52:05 +01:00
2008-01-19 15:40:28 +01:00
if len(args) not in (2, 3):
2009-01-02 00:17:49 +00:00
optParser.error("Source package / target release missing - please " \
"specify.")
2008-01-19 15:40:28 +01:00
2008-08-04 15:16:07 +02:00
if not use_lp_bugs and not get_email_address():
sys.exit(1)
2009-01-02 00:17:49 +00:00
srcpkg = args[0]
release = args[1]
2008-01-19 15:40:28 +01:00
force_base_ver = None
2009-01-02 00:17:49 +00:00
# Base version specified.
if len(args) == 3: force_base_ver = args[2]
2008-01-19 15:40:28 +01:00
(cur_ver, component) = ('0', 'universe') # Let's assume universe
2009-01-02 00:17:49 +00:00
# Find Ubuntu release's package version.
if not newsource: (cur_ver, component) = cur_version_component(srcpkg, release)
2008-01-19 15:40:28 +01:00
2008-08-23 18:14:33 +02:00
debiancomponent = debian_component(srcpkg, distro)
2009-01-02 00:17:49 +00:00
# Find Debian release's package version.
2008-08-23 18:14:33 +02:00
deb_version = cur_deb_version(srcpkg, distro)
2008-12-29 18:58:11 +00:00
2009-01-02 00:17:49 +00:00
# Debian and Ubuntu versions are the same - stop.
2008-02-08 23:29:53 +01:00
if deb_version == cur_ver:
print 'The versions in Debian and Ubuntu are the same already (%s). Aborting.' % (deb_version,)
sys.exit(1)
2009-01-02 00:17:49 +00:00
# -s flag not specified - check if we do need sponsorship.
if not sponsorship: sponsorship = checkNeedsSponsorship(component)
# Check for existing package reports.
2008-12-29 23:50:48 +00:00
if not newsource: checkExistingReports(srcpkg)
2008-09-01 22:29:32 +01:00
2009-01-02 00:17:49 +00:00
# Generate bug report.
2008-01-19 15:40:28 +01:00
subscribe = 'ubuntu-archive'
status = 'confirmed'
if sponsorship:
status = 'new'
if component in ['main', 'restricted']:
subscribe = 'ubuntu-main-sponsors'
else:
subscribe = 'ubuntu-universe-sponsors'
2008-08-23 18:14:33 +02:00
report = 'Please sync %s %s (%s) from Debian %s (%s).\n\n' % (srcpkg, deb_version, component, distro, debiancomponent)
2008-01-19 15:40:28 +01:00
title = report[:-2]
base_ver = cur_ver
uidx = base_ver.find('ubuntu')
if uidx > 0:
base_ver = base_ver[:uidx]
2008-02-09 02:52:22 +01:00
need_interaction = True
2008-01-19 15:40:28 +01:00
2008-04-16 02:05:58 +02:00
print 'Changes have been made to the package in Ubuntu.'
2008-02-09 02:52:22 +01:00
print 'Please edit the report and give an explanation.'
2008-04-16 02:05:58 +02:00
print 'Press ENTER to start your editor. Press Control-C to abort now.'
print 'Not saving the report file will abort the request, too.'
raw_input_exit_on_ctrlc()
report += 'Explanation of the Ubuntu delta and why it can be dropped:\n' + \
'>>> ENTER_EXPLANATION_HERE <<<\n\n'
2007-09-12 01:14:23 +10:00
uidx = base_ver.find('build')
if uidx > 0:
base_ver = base_ver[:uidx]
if force_base_ver:
base_ver = force_base_ver
report += 'Changelog since current %s version %s:\n\n' % (release, cur_ver)
report += debian_changelog(srcpkg, debiancomponent, base_ver) + '\n'
2008-02-09 02:52:22 +01:00
if need_interaction:
2008-07-03 19:26:25 +02:00
(_, report) = edit_report(title, report, changes_required=True)
2008-02-09 02:52:22 +01:00
2008-04-16 02:05:58 +02:00
# Post sync request using Launchpad interface:
2008-01-19 15:40:28 +01:00
srcpkg = not newsource and srcpkg or None
if use_lp_bugs:
# Map status to the values expected by lp-bugs
2008-02-09 04:03:38 +01:00
mapping = {'new': 'New', 'confirmed': 'Confirmed'}
2008-07-03 19:26:25 +02:00
if post_bug(srcpkg, subscribe, mapping[status], title, report):
2008-01-19 15:40:28 +01:00
sys.exit(0)
2008-04-16 02:05:58 +02:00
# Abort on error:
print 'Something went wrong. No sync request filed.'
sys.exit(1)
2007-09-12 01:14:23 +10:00
2008-04-16 02:05:58 +02:00
# Mail sync request:
2008-07-03 19:26:25 +02:00
if mail_bug(srcpkg, subscribe, status, title, report, keyid):
2008-02-09 04:03:38 +01:00
sys.exit(0)
2007-09-12 01:14:23 +10:00
2008-01-19 15:40:28 +01:00
print 'Something went wrong. No sync request filed.'
2007-09-12 01:14:23 +10:00
sys.exit(1)