2007-09-12 01:14:23 +10:00
|
|
|
#!/usr/bin/python
|
2007-11-07 20:05:37 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-09-12 01:14:23 +10:00
|
|
|
|
2007-12-01 22:56:45 +01:00
|
|
|
# (C) 2007 Canonical Ltd., Steve Kowalik
|
2007-09-12 01:14:23 +10:00
|
|
|
# Authors:
|
|
|
|
# Martin Pitt <martin.pitt@ubuntu.com>
|
|
|
|
# Steve Kowalik <stevenk@ubuntu.com>
|
2008-01-19 15:40:28 +01:00
|
|
|
# Michael Bienia <geser@ubuntu.com> (python-launchpad-bugs support)
|
|
|
|
#
|
2007-12-01 22:56:45 +01:00
|
|
|
# License: GPLv2, see /usr/share/common-licenses/GPL
|
2007-09-12 01:14:23 +10:00
|
|
|
|
2008-01-19 16:19:55 +01:00
|
|
|
import os, sys, urllib, subprocess, getopt, readline
|
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():
|
|
|
|
(pkg, version, rel, builds) = l.split('|')
|
|
|
|
component = 'main'
|
|
|
|
if rel.find('/') != -1:
|
|
|
|
component = rel.split('/')[1]
|
|
|
|
return (version.strip(), component.strip())
|
|
|
|
|
|
|
|
print "%s doesn't appear to exist in %s, specify -n for a package not in Ubuntu." % (sourcepkg, release)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2007-10-05 14:20:22 +02:00
|
|
|
def cur_deb_version(sourcepkg):
|
2008-01-19 15:40:28 +01:00
|
|
|
'''Return the current debian version of a package in unstable.'''
|
2007-10-05 14:20:22 +02:00
|
|
|
madison = subprocess.Popen(['rmadison', '-u', 'debian', '-a', 'source', \
|
|
|
|
'-s', 'unstable', 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)
|
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).'''
|
|
|
|
|
|
|
|
ch = ''
|
|
|
|
subdir = sourcepkg[0]
|
|
|
|
if sourcepkg.startswith('lib'):
|
|
|
|
subdir = 'lib%s' % sourcepkg[3]
|
|
|
|
for l in urllib.urlopen('http://packages.debian.org/changelogs/pool/%s/%s/%s/current/changelog.txt' % (component, subdir, sourcepkg)):
|
|
|
|
if l.startswith(sourcepkg) and l.find(version + ')') > 0:
|
|
|
|
break
|
|
|
|
ch += l
|
|
|
|
|
|
|
|
return ch
|
|
|
|
|
|
|
|
def debian_component(sourcepkg):
|
|
|
|
'''Return the Debian component for the source package.'''
|
2007-11-15 21:12:38 +01:00
|
|
|
madison = subprocess.Popen(['rmadison', '-u', 'debian', '-a', 'source', '-s', 'unstable', \
|
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
|
|
|
|
|
|
|
|
def usage():
|
2008-01-19 15:40:28 +01:00
|
|
|
print '''Usage: requestsync [-h|-n|-s|-k <keyid>|--lp] <source package> <target release> [basever]
|
2007-09-12 01:14:23 +10:00
|
|
|
|
|
|
|
In some cases, the base version (fork point from Debian) cannot be determined
|
|
|
|
automatically, and you'll get a complete Debian changelog. Specify the correct
|
2008-01-19 15:40:28 +01:00
|
|
|
base version of the package in Ubuntu.
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-h print this help
|
|
|
|
-n new source package (doesn't exist yet in Ubuntu)
|
|
|
|
-s request sponsoring (through ubuntu-{main,universe}-sponsors)
|
|
|
|
-k <keyid> sign email with <keyid> (only used when submitting per email)
|
|
|
|
--lp use python-launchpad-bugs instead of email for bug submitting
|
|
|
|
'''
|
2007-09-12 01:14:23 +10:00
|
|
|
sys.exit(1)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
to = 'new@bugs.launchpad.net'
|
|
|
|
|
|
|
|
myemailaddr = os.getenv('DEBEMAIL')
|
|
|
|
if not myemailaddr:
|
|
|
|
print >> sys.stderr, 'The environment variable DEBEMAIL needs to be set to make use of this script.'
|
|
|
|
return False
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
# sign it
|
|
|
|
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))
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
print mail
|
|
|
|
|
|
|
|
print 'Press enter to file this bug, Control-C to abort.'
|
|
|
|
try:
|
2008-01-19 16:19:55 +01:00
|
|
|
raw_input()
|
2008-01-19 15:40:28 +01:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print 'Abort requested. No sync request filed.'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# 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
|
|
|
|
s = smtplib.SMTP(mailserver, mailserver_port)
|
|
|
|
|
|
|
|
# authenticate to the server
|
|
|
|
mailserver_user = os.getenv('DEBSMTP_USER')
|
|
|
|
mailserver_pass = os.getenv('DEBSMTP_PASS')
|
|
|
|
if mailserver_user and mailserver_pass:
|
|
|
|
try:
|
|
|
|
s.login(mailserver_user, mailserver_pass)
|
|
|
|
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
|
|
|
|
|
|
|
|
def post_bug(source_package, subscibe, status, bugtitle, bugtext):
|
|
|
|
'''Use python-launchpad-bugs to submit the sync request.
|
|
|
|
Return True if email successfully send, otherwise False.'''
|
|
|
|
|
|
|
|
import glob, os.path
|
|
|
|
|
|
|
|
try:
|
|
|
|
import launchpadbugs.connector
|
|
|
|
except ImportError:
|
|
|
|
print >> sys.stderr, 'Importing launchpadbugs failed. Is python-launchpad-bugs installed?'
|
|
|
|
print >> sys.stderr, 'Falling back to submitting per email.'
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Search cookiefile (for authentication to lp)
|
|
|
|
try:
|
|
|
|
cookiefile = glob.glob(os.path.expanduser('~/.mozilla/*/*/cookies.txt'))[0]
|
|
|
|
except IndexError:
|
|
|
|
print >> sys.stderr, 'Could not find Firefox cookie file'
|
|
|
|
return False
|
|
|
|
|
|
|
|
if source_package:
|
|
|
|
product = {'name': source_package, 'target': 'ubuntu'}
|
2007-09-12 01:14:23 +10:00
|
|
|
else:
|
2008-01-19 15:40:28 +01:00
|
|
|
# new source package
|
|
|
|
product = {'name': 'ubuntu'}
|
|
|
|
|
|
|
|
print 'Summary:\n%s\n\nDescription:\n%s' % (bugtitle, bugtext)
|
2007-09-12 01:14:23 +10:00
|
|
|
|
2008-01-19 15:40:28 +01:00
|
|
|
print 'Press enter to file this bug, Control-C to abort.'
|
|
|
|
try:
|
2008-01-19 16:19:55 +01:00
|
|
|
raw_input()
|
2008-01-19 15:40:28 +01:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print 'Abort requested. No sync request filed.'
|
|
|
|
sys.exit(1)
|
2007-09-12 01:14:23 +10:00
|
|
|
|
2008-01-19 15:40:28 +01:00
|
|
|
# Create bug
|
|
|
|
Bug = launchpadbugs.connector.ConnectBug()
|
|
|
|
Bug.authentication = cookiefile
|
2007-09-12 01:14:23 +10:00
|
|
|
|
2008-01-19 15:40:28 +01:00
|
|
|
bug = Bug.New(product = product, summary = bugtitle, description = bugtext)
|
|
|
|
bug.importance = 'Wishlist'
|
|
|
|
bug.status = status
|
|
|
|
bug.subscriptions.add(subscribe)
|
|
|
|
bug.commit()
|
2007-09-12 01:14:23 +10:00
|
|
|
|
2008-01-19 15:40:28 +01:00
|
|
|
print 'Sync request filed as bug #%i: https://launchpad.net/bugs/%i' % (bug.bugnumber, bug.bugnumber)
|
2007-09-12 01:14:23 +10:00
|
|
|
|
2008-01-19 15:40:28 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
#
|
|
|
|
# entry point
|
|
|
|
#
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
newsource = False
|
|
|
|
sponsorship = False
|
|
|
|
keyid = None
|
|
|
|
use_lp_bugs = False
|
|
|
|
|
|
|
|
try:
|
|
|
|
opts, args = getopt.gnu_getopt(sys.argv[1:], 'hnsk:', ('lp'))
|
|
|
|
except getopt.GetoptError:
|
|
|
|
usage()
|
|
|
|
for o, a in opts:
|
|
|
|
if o == '-h': usage()
|
|
|
|
if o == '-n': newsource = True
|
|
|
|
if o == '-s': sponsorship = True
|
|
|
|
if o == '-k': keyid = a
|
|
|
|
if o == '--lp': use_lp_bugs = True
|
|
|
|
|
|
|
|
if len(args) not in (2, 3):
|
|
|
|
usage()
|
|
|
|
|
|
|
|
(srcpkg, release) = args[:2]
|
|
|
|
force_base_ver = None
|
|
|
|
if len(args) == 3:
|
|
|
|
force_base_ver = args[2]
|
|
|
|
(cur_ver, component) = ('0', 'universe') # Let's assume universe
|
|
|
|
if not newsource:
|
|
|
|
(cur_ver, component) = cur_version_component(srcpkg, release)
|
|
|
|
|
|
|
|
debiancomponent = debian_component(srcpkg)
|
|
|
|
deb_version = cur_deb_version(srcpkg)
|
|
|
|
|
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)
|
|
|
|
|
2008-01-19 15:40:28 +01:00
|
|
|
# generate bug report
|
|
|
|
subscribe = 'ubuntu-archive'
|
|
|
|
status = 'confirmed'
|
|
|
|
if sponsorship:
|
|
|
|
status = 'new'
|
|
|
|
if component in ['main', 'restricted']:
|
|
|
|
subscribe = 'ubuntu-main-sponsors'
|
|
|
|
else:
|
|
|
|
subscribe = 'ubuntu-universe-sponsors'
|
|
|
|
|
|
|
|
report = '''Please sync %s %s (%s) from Debian unstable (%s).
|
|
|
|
''' % (srcpkg, deb_version, component, debiancomponent)
|
|
|
|
title = report[:-2]
|
|
|
|
|
|
|
|
base_ver = cur_ver
|
|
|
|
uidx = base_ver.find('ubuntu')
|
|
|
|
if uidx > 0:
|
|
|
|
base_ver = base_ver[:uidx]
|
|
|
|
|
|
|
|
print 'Explanation of the Ubuntu delta and why it can be dropped:'
|
|
|
|
explanation = '\nExplanation of the Ubuntu delta and why it can be dropped:\n'
|
|
|
|
while (explanation[-2:] != '\n\n'):
|
2008-01-19 16:19:55 +01:00
|
|
|
try:
|
|
|
|
explanation += raw_input() + '\n'
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print 'Abort requested. No sync request filed.'
|
|
|
|
sys.exit(1)
|
|
|
|
report += explanation
|
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-01-19 15:40:28 +01:00
|
|
|
# mail or post the sync request
|
|
|
|
srcpkg = not newsource and srcpkg or None
|
|
|
|
if use_lp_bugs:
|
|
|
|
# Map status to the values expected by lp-bugs
|
|
|
|
mapping = {'new': 'New', 'confirmed': 'Confirmed'}
|
|
|
|
if post_bug(srcpkg, subscribe, mapping[status], title, report):
|
|
|
|
sys.exit(0)
|
2007-09-12 01:14:23 +10:00
|
|
|
|
2008-01-19 15:40:28 +01:00
|
|
|
if mail_bug(srcpkg, subscribe, status, title, report, keyid):
|
|
|
|
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)
|