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>
|
2009-08-04 15:32:39 +02:00
|
|
|
# Michael Bienia <geser@ubuntu.com>
|
2008-05-22 16:50:05 +02:00
|
|
|
# Daniel Hahler <ubuntu@thequod.de>
|
2009-03-02 20:54:33 +00:00
|
|
|
# Iain Lane <laney@ubuntu.com>
|
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.
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +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.
|
|
|
|
#
|
|
|
|
# See file /usr/share/common-licenses/GPL-2 for more details.
|
|
|
|
#
|
|
|
|
# ##################################################################
|
2007-09-12 01:14:23 +10:00
|
|
|
|
2009-01-02 00:17:49 +00:00
|
|
|
from optparse import OptionParser
|
2010-12-21 17:02:36 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2010-06-08 19:09:40 +02:00
|
|
|
from debian.changelog import Version
|
2007-09-12 01:14:23 +10:00
|
|
|
|
2010-12-21 17:02:36 +02:00
|
|
|
from ubuntutools.config import UDTConfig, ubu_email
|
2011-01-21 19:20:04 +01:00
|
|
|
from ubuntutools.distro_info import UbuntuDistroInfo
|
2009-08-22 18:34:22 +02:00
|
|
|
from ubuntutools.lp import udtexceptions
|
2010-09-22 14:07:23 +02:00
|
|
|
from ubuntutools.requestsync.common import (edit_report, getDebianChangelog,
|
|
|
|
raw_input_exit_on_ctrlc)
|
2009-02-06 12:18:06 +01:00
|
|
|
|
2008-01-19 15:40:28 +01:00
|
|
|
#
|
|
|
|
# entry point
|
|
|
|
#
|
|
|
|
|
2010-12-27 16:54:23 +01:00
|
|
|
def main():
|
2010-12-22 23:04:29 +02:00
|
|
|
# Our usage options.
|
2010-12-23 00:01:39 +02:00
|
|
|
usage = ('Usage: %prog [options] '
|
|
|
|
'<source package> [<target release> [base version]]')
|
2010-12-27 20:06:23 +01:00
|
|
|
parser = OptionParser(usage)
|
|
|
|
|
|
|
|
parser.add_option('-d', type='string',
|
|
|
|
dest='dist', default='unstable',
|
|
|
|
help='Debian distribution to sync from.')
|
|
|
|
parser.add_option('-k', type='string',
|
|
|
|
dest='keyid', default=None,
|
|
|
|
help='GnuPG key ID to use for signing report '
|
|
|
|
'(only used when emailing the sync request).')
|
|
|
|
parser.add_option('-n', action='store_true',
|
|
|
|
dest='newpkg', default=False,
|
|
|
|
help='Whether package to sync is a new package in '
|
|
|
|
'Ubuntu.')
|
|
|
|
parser.add_option('--lp', action='store_true',
|
|
|
|
dest='lpapi', default=False,
|
|
|
|
help='Specify whether to use the LP API for filing '
|
|
|
|
'the sync request (recommended).')
|
|
|
|
parser.add_option('-l', '--lpinstance', metavar='INSTANCE',
|
|
|
|
dest='lpinstance', default=None,
|
|
|
|
help='Launchpad instance to connect to '
|
|
|
|
'(default: production).')
|
|
|
|
parser.add_option('-s', action='store_true',
|
|
|
|
dest='sponsorship', default=False,
|
|
|
|
help='Force sponsorship')
|
|
|
|
parser.add_option('-C', action='store_true',
|
|
|
|
dest='missing_changelog_ok', default=False,
|
|
|
|
help='Allow changelog to be manually filled in '
|
|
|
|
'when missing')
|
|
|
|
parser.add_option('-e', action='store_true',
|
|
|
|
dest='ffe', default=False,
|
|
|
|
help='Use this after FeatureFreeze for non-bug fix '
|
|
|
|
'syncs, changes default subscription to the '
|
|
|
|
'appropriate release team.')
|
|
|
|
parser.add_option('--no-conf', action='store_true',
|
|
|
|
dest='no_conf', default=False,
|
|
|
|
help="Don't read config files or environment variables")
|
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
if not len(args):
|
2010-12-27 20:06:23 +01:00
|
|
|
parser.print_help()
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
config = UDTConfig(options.no_conf)
|
|
|
|
if not options.lpapi:
|
|
|
|
options.lpapi = config.get_value('USE_LPAPI', default=False,
|
|
|
|
boolean=True)
|
|
|
|
if options.lpinstance is None:
|
|
|
|
options.lpinstance = config.get_value('LPINSTANCE')
|
2011-01-31 18:37:23 -05:00
|
|
|
|
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
mailserver_host = config.get_value('SMTP_SERVER',
|
2011-01-31 18:37:23 -05:00
|
|
|
default='',
|
|
|
|
compat_keys=['UBUSMTP', 'DEBSMTP'])
|
|
|
|
if not mailserver_host:
|
|
|
|
try:
|
|
|
|
import DNS
|
|
|
|
DNS.DiscoverNameServers()
|
|
|
|
mxlist = DNS.mxlookup('launchpad.net')
|
|
|
|
firstmx = mxlist[0]
|
|
|
|
mx1host = firstmx[1]
|
|
|
|
mailserver_host = config.get_value('SMTP_SERVER',
|
|
|
|
default=mx1host,
|
|
|
|
compat_keys=['UBUSMTP', 'DEBSMTP'])
|
|
|
|
except ImportError, x:
|
|
|
|
print "Please install python-dns to support Launchapd mail server lookup."
|
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
mailserver_port = config.get_value('SMTP_PORT', default=25,
|
2010-12-23 00:01:39 +02:00
|
|
|
compat_keys=['UBUSMTP_PORT',
|
|
|
|
'DEBSMTP_PORT'])
|
2010-12-22 23:04:29 +02:00
|
|
|
mailserver_user = config.get_value('SMTP_USER',
|
2010-12-23 00:01:39 +02:00
|
|
|
compat_keys=['UBUSMTP_USER',
|
|
|
|
'DEBSMTP_USER'])
|
2010-12-22 23:04:29 +02:00
|
|
|
mailserver_pass = config.get_value('SMTP_PASS',
|
2010-12-23 00:01:39 +02:00
|
|
|
compat_keys=['UBUSMTP_PASS',
|
|
|
|
'DEBSMTP_PASS'])
|
2010-12-21 17:02:36 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
# import the needed requestsync module
|
|
|
|
if options.lpapi:
|
|
|
|
from ubuntutools.requestsync.lp import (checkExistingReports,
|
|
|
|
getDebianSrcPkg,
|
|
|
|
getUbuntuSrcPkg,
|
|
|
|
needSponsorship, postBug)
|
|
|
|
from ubuntutools.lp.lpapicache import Distribution, Launchpad
|
2010-12-23 00:01:39 +02:00
|
|
|
# See if we have LP credentials and exit if we don't -
|
|
|
|
# cannot continue in this case
|
2010-05-03 23:28:00 +01:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
try:
|
|
|
|
Launchpad.login(service=options.lpinstance)
|
|
|
|
except IOError:
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
from ubuntutools.requestsync.mail import (checkExistingReports,
|
|
|
|
getDebianSrcPkg,
|
|
|
|
getUbuntuSrcPkg,
|
|
|
|
mailBug, needSponsorship)
|
|
|
|
if not any(x in os.environ for x in ('UBUMAIL', 'DEBEMAIL', 'EMAIL')):
|
|
|
|
print >> sys.stderr, (
|
|
|
|
'E: The environment variable UBUMAIL, DEBEMAIL or EMAIL needs '
|
|
|
|
'to be set to let this script mail the sync request.')
|
|
|
|
sys.exit(1)
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
newsource = options.newpkg
|
|
|
|
sponsorship = options.sponsorship
|
|
|
|
distro = options.dist
|
|
|
|
ffe = options.ffe
|
|
|
|
lpapi = options.lpapi
|
|
|
|
need_interaction = False
|
|
|
|
force_base_version = None
|
|
|
|
srcpkg = args[0]
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
if len(args) == 1:
|
|
|
|
if lpapi:
|
|
|
|
release = Distribution('ubuntu').getDevelopmentSeries().name
|
|
|
|
else:
|
2011-01-21 19:20:04 +01:00
|
|
|
release = UbuntuDistroInfo().devel()
|
2010-12-22 23:04:29 +02:00
|
|
|
print >> sys.stderr, 'W: Target release missing - assuming %s' % release
|
|
|
|
elif len(args) == 2:
|
|
|
|
release = args[1]
|
|
|
|
elif len(args) == 3:
|
|
|
|
release = args[1]
|
|
|
|
force_base_version = Version(args[2])
|
|
|
|
else:
|
|
|
|
print >> sys.stderr, 'E: Too many arguments.'
|
2010-12-27 20:06:23 +01:00
|
|
|
parser.print_help()
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
# Get the current Ubuntu source package
|
|
|
|
try:
|
|
|
|
ubuntu_srcpkg = getUbuntuSrcPkg(srcpkg, release)
|
|
|
|
ubuntu_version = Version(ubuntu_srcpkg.getVersion())
|
|
|
|
ubuntu_component = ubuntu_srcpkg.getComponent()
|
|
|
|
newsource = False # override the -n flag
|
|
|
|
except udtexceptions.PackageNotFoundException:
|
|
|
|
ubuntu_srcpkg = None
|
|
|
|
ubuntu_version = Version('~')
|
|
|
|
ubuntu_component = 'universe' # let's assume universe
|
|
|
|
if not newsource:
|
2010-12-23 00:01:39 +02:00
|
|
|
print ("'%s' doesn't exist in 'Ubuntu %s'.\n"
|
|
|
|
"Do you want to sync a new package?"
|
|
|
|
% (srcpkg, release))
|
|
|
|
raw_input_exit_on_ctrlc('Press [Enter] to continue '
|
|
|
|
'or [Ctrl-C] to abort. ')
|
2010-12-22 23:04:29 +02:00
|
|
|
newsource = True
|
2008-01-19 15:40:28 +01:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
# Get the requested Debian source package
|
|
|
|
try:
|
|
|
|
debian_srcpkg = getDebianSrcPkg(srcpkg, distro)
|
|
|
|
debian_version = Version(debian_srcpkg.getVersion())
|
|
|
|
debian_component = debian_srcpkg.getComponent()
|
2010-12-27 20:06:23 +01:00
|
|
|
except udtexceptions.PackageNotFoundException, error:
|
|
|
|
print >> sys.stderr, "E: %s" % error
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
2008-12-29 18:58:11 +00:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
# Stop if Ubuntu has already the version from Debian or a newer version
|
|
|
|
if (ubuntu_version >= debian_version) and options.lpapi:
|
|
|
|
# try rmadison
|
|
|
|
import ubuntutools.requestsync.mail
|
|
|
|
try:
|
2010-12-23 00:01:39 +02:00
|
|
|
debian_srcpkg = ubuntutools.requestsync.mail.getDebianSrcPkg(
|
|
|
|
srcpkg, distro)
|
2010-12-22 23:04:29 +02:00
|
|
|
debian_version = Version(debian_srcpkg.getVersion())
|
|
|
|
debian_component = debian_srcpkg.getComponent()
|
2010-12-27 20:06:23 +01:00
|
|
|
except udtexceptions.PackageNotFoundException, error:
|
|
|
|
print >> sys.stderr, "E: %s" % error
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
2010-05-03 23:28:00 +01:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
if ubuntu_version == debian_version:
|
2010-12-23 00:01:39 +02:00
|
|
|
print >> sys.stderr, ('E: The versions in Debian and Ubuntu are the '
|
|
|
|
'same already (%s). Aborting.'
|
|
|
|
% ubuntu_version)
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
|
|
|
if ubuntu_version > debian_version:
|
2010-12-23 00:01:39 +02:00
|
|
|
print >> sys.stderr, ('E: The version in Ubuntu (%s) is newer than '
|
|
|
|
'the version in Debian (%s). Aborting.'
|
|
|
|
% (ubuntu_version, debian_version))
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
2008-02-08 23:29:53 +01:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
# -s flag not specified - check if we do need sponsorship
|
|
|
|
if not sponsorship:
|
|
|
|
sponsorship = needSponsorship(srcpkg, ubuntu_component, release)
|
2009-01-02 00:17:49 +00:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
# Check for existing package reports
|
|
|
|
if not newsource:
|
|
|
|
checkExistingReports(srcpkg)
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
# Generate bug report
|
2010-12-23 00:01:39 +02:00
|
|
|
pkg_to_sync = ('%s %s (%s) from Debian %s (%s)'
|
|
|
|
% (srcpkg, debian_version, ubuntu_component,
|
|
|
|
distro, debian_component))
|
2010-12-22 23:04:29 +02:00
|
|
|
title = "Sync %s" % pkg_to_sync
|
|
|
|
if ffe:
|
|
|
|
title = "FFe: " + title
|
|
|
|
report = "Please sync %s\n\n" % pkg_to_sync
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
if 'ubuntu' in str(ubuntu_version):
|
|
|
|
need_interaction = True
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-23 00:01:39 +02:00
|
|
|
print ('Changes have been made to the package in Ubuntu.\n'
|
|
|
|
'Please edit the report and give an explanation.\n'
|
|
|
|
'Not saving the report file will abort the request.')
|
|
|
|
report += ('Explanation of the Ubuntu delta and why it can be '
|
|
|
|
'dropped:\n>>> ENTER_EXPLANATION_HERE <<<\n\n')
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
if ffe:
|
|
|
|
need_interaction = True
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-23 00:01:39 +02:00
|
|
|
print ('To approve FeatureFreeze exception, you need to state\n'
|
|
|
|
'the reason why you feel it is necessary.\n'
|
|
|
|
'Not saving the report file will abort the request.')
|
|
|
|
report += ('Explanation of FeatureFreeze exception:\n'
|
|
|
|
'>>> ENTER_EXPLANATION_HERE <<<\n\n')
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
if need_interaction:
|
2010-12-23 00:01:39 +02:00
|
|
|
raw_input_exit_on_ctrlc('Press [Enter] to continue.'
|
|
|
|
'Press [Ctrl-C] to abort now. ')
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
base_version = force_base_version or ubuntu_version
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
if newsource:
|
|
|
|
report += 'All changelog entries:\n\n'
|
|
|
|
else:
|
2010-12-23 00:01:39 +02:00
|
|
|
report += ('Changelog entries since current %s version %s:\n\n'
|
|
|
|
% (release, ubuntu_version))
|
2010-12-22 23:04:29 +02:00
|
|
|
changelog = getDebianChangelog(debian_srcpkg, base_version)
|
|
|
|
if not changelog:
|
|
|
|
if not options.missing_changelog_ok:
|
2010-12-23 00:01:39 +02:00
|
|
|
print >> sys.stderr, ("E: Did not retrieve any changelog entries. "
|
|
|
|
"Do you need to specify '-C'? "
|
|
|
|
"Was the package recently uploaded? (check "
|
|
|
|
"http://packages.debian.org/changelogs/)")
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
need_interaction = True
|
|
|
|
changelog = "XXX FIXME: add changelog here XXX"
|
|
|
|
report += changelog
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-23 00:01:39 +02:00
|
|
|
(title, report) = edit_report(title, report,
|
|
|
|
changes_required=need_interaction)
|
2010-12-22 23:04:29 +02:00
|
|
|
if 'XXX FIXME' in report:
|
2010-12-23 00:01:39 +02:00
|
|
|
print >> sys.stderr, ("E: changelog boilerplate found in report, "
|
|
|
|
"please manually add changelog when using '-C'")
|
2010-12-22 23:04:29 +02:00
|
|
|
sys.exit(1)
|
2009-08-22 18:34:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
# bug status and bug subscriber
|
|
|
|
status = 'confirmed'
|
|
|
|
subscribe = 'ubuntu-archive'
|
|
|
|
if sponsorship:
|
|
|
|
status = 'new'
|
|
|
|
subscribe = 'ubuntu-sponsors'
|
|
|
|
if ffe:
|
|
|
|
status = 'new'
|
|
|
|
subscribe = 'ubuntu-release'
|
2009-08-23 13:08:22 +02:00
|
|
|
|
2010-12-22 23:04:29 +02:00
|
|
|
srcpkg = not newsource and srcpkg or None
|
|
|
|
if lpapi:
|
|
|
|
# Map status to the values expected by LP API
|
|
|
|
mapping = {'new': 'New', 'confirmed': 'Confirmed'}
|
|
|
|
# Post sync request using LP API
|
|
|
|
postBug(srcpkg, subscribe, mapping[status], title, report)
|
|
|
|
else:
|
|
|
|
email_from = ubu_email(export=False)[1]
|
|
|
|
# Mail sync request
|
|
|
|
mailBug(srcpkg, subscribe, status, title, report, options.lpinstance,
|
|
|
|
options.keyid, email_from, mailserver_host, mailserver_port,
|
|
|
|
mailserver_user, mailserver_pass)
|
2010-12-27 16:54:23 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|