2007-09-03 10:53:11 +02:00
|
|
|
#!/usr/bin/python
|
2007-11-07 20:05:37 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-09-07 14:36:50 +02:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# submittodebian - tool to submit patches to Debian's BTS
|
2009-12-11 13:46:28 -08:00
|
|
|
# Copyright (C) 2007, 2009 Canonical Ltd.
|
|
|
|
# Author: Soren Hansen <soren@ubuntu.com>,
|
|
|
|
# Steve Langasek <slangasek@canonical.com>
|
2007-09-07 14:36:50 +02:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# ##################################################################
|
2007-09-07 14:36:50 +02: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; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
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.
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# See file /usr/share/common-licenses/GPL for more details.
|
2007-09-07 14:36:50 +02:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# ##################################################################
|
2007-09-07 14:36:50 +02:00
|
|
|
|
2007-09-03 10:53:11 +02:00
|
|
|
import re, os, sys
|
|
|
|
from tempfile import mkstemp
|
|
|
|
|
2011-01-21 19:20:04 +01:00
|
|
|
from ubuntutools.distro_info import UbuntuDistroInfo
|
|
|
|
|
2007-11-07 20:05:37 +01:00
|
|
|
try:
|
2010-12-22 01:28:00 +01:00
|
|
|
from debian.changelog import Changelog
|
2007-11-07 20:05:37 +01:00
|
|
|
except ImportError:
|
2010-12-27 14:21:01 +01:00
|
|
|
print ('This utility requires modules from the «python-debian» package, '
|
|
|
|
'which isn\'t currently installed.')
|
2010-12-22 01:28:00 +01:00
|
|
|
sys.exit(1)
|
2007-11-07 20:05:37 +01:00
|
|
|
|
2008-02-17 23:39:10 +01:00
|
|
|
if not os.path.exists('/usr/bin/reportbug'):
|
2010-12-27 14:21:01 +01:00
|
|
|
print ('This utility requires the «reportbug» package, which isn\'t '
|
|
|
|
'currently installed.')
|
2010-12-22 01:28:00 +01:00
|
|
|
sys.exit(1)
|
2008-02-17 23:39:10 +01:00
|
|
|
|
2007-09-03 10:53:11 +02:00
|
|
|
def get_most_recent_debian_version(changelog):
|
2010-12-27 20:02:11 +01:00
|
|
|
for version in changelog.get_versions():
|
|
|
|
if not re.search('(ubuntu|build)', version.full_version):
|
|
|
|
return version.full_version
|
2007-09-03 10:53:11 +02:00
|
|
|
|
|
|
|
def get_bug_body(changelog):
|
2010-12-27 14:21:01 +01:00
|
|
|
msg = """In Ubuntu, the attached patch was applied to achieve the following:
|
2010-11-30 11:56:36 +01:00
|
|
|
|
|
|
|
## ---------------- REPLACE THIS WITH ACTUAL INFORMATION ---------------------
|
2010-12-01 16:51:09 +00:00
|
|
|
## Please add all necessary information about why the change needed to go in
|
2010-11-30 11:56:36 +01:00
|
|
|
## Ubuntu, quote policy, spec or any other background material and why it can
|
2010-12-01 16:51:09 +00:00
|
|
|
## and should be used in Debian too. If the patch is composed of multiple
|
|
|
|
## independent pieces, please send them as separate bug reports.
|
2010-11-30 11:56:36 +01:00
|
|
|
## ---------------- REPLACE THIS WITH ACTUAL INFORMATION ---------------------
|
|
|
|
|
2007-09-03 10:53:11 +02:00
|
|
|
%s
|
2010-11-30 11:56:36 +01:00
|
|
|
|
|
|
|
Thanks for considering the patch.
|
2010-12-27 14:21:01 +01:00
|
|
|
""" % ("\n".join([a for a in changelog._blocks[0].changes()]))
|
|
|
|
return msg
|
2007-09-03 10:53:11 +02:00
|
|
|
|
|
|
|
def gen_debdiff(changelog):
|
2010-12-22 01:28:00 +01:00
|
|
|
pkg = changelog.package
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-22 01:28:00 +01:00
|
|
|
oldver = changelog._blocks[1].version
|
|
|
|
newver = changelog._blocks[0].version
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-22 01:28:00 +01:00
|
|
|
(fd, debdiff) = mkstemp()
|
|
|
|
os.close(fd)
|
2009-12-27 12:58:05 -08:00
|
|
|
|
2010-12-22 01:28:00 +01:00
|
|
|
if os.system('bzr diff -r tag:%s > /dev/null 2>&1' % oldver) == 256:
|
|
|
|
print "Extracting bzr diff between %s and %s" % (oldver, newver)
|
2010-12-27 14:21:01 +01:00
|
|
|
cmd = 'bzr diff -r tag:%s | filterdiff -x "*changelog*" > %s' % \
|
|
|
|
(oldver, debdiff)
|
2010-12-22 01:28:00 +01:00
|
|
|
run_cmd(cmd)
|
|
|
|
else:
|
|
|
|
if oldver.epoch is not None:
|
|
|
|
oldver = str(oldver)[str(oldver).index(":")+1:]
|
|
|
|
if newver.epoch is not None:
|
|
|
|
newver = str(newver)[str(newver).index(":")+1:]
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-22 01:28:00 +01:00
|
|
|
olddsc = '../%s_%s.dsc' % (pkg, oldver)
|
|
|
|
newdsc = '../%s_%s.dsc' % (pkg, newver)
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-22 01:28:00 +01:00
|
|
|
check_file(olddsc)
|
|
|
|
check_file(newdsc)
|
2009-12-11 13:46:28 -08:00
|
|
|
|
2010-12-22 01:28:00 +01:00
|
|
|
print "Generating debdiff between %s and %s" % (oldver, newver)
|
2010-12-27 14:21:01 +01:00
|
|
|
cmd = 'debdiff %s %s | filterdiff -x "*changelog*" > %s' % \
|
|
|
|
(olddsc, newdsc, debdiff)
|
2010-12-22 01:28:00 +01:00
|
|
|
run_cmd(cmd)
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-22 01:28:00 +01:00
|
|
|
return debdiff
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2007-11-07 20:05:37 +01:00
|
|
|
def check_file(fname, critical = True):
|
2010-12-22 01:28:00 +01:00
|
|
|
if os.path.exists(fname):
|
|
|
|
return fname
|
|
|
|
else:
|
2010-12-27 20:02:11 +01:00
|
|
|
if not critical:
|
|
|
|
return False
|
2010-12-22 01:28:00 +01:00
|
|
|
print "Couldn't find «%s».\n" % fname
|
|
|
|
sys.exit(1)
|
2007-11-07 20:05:37 +01:00
|
|
|
|
2007-09-03 10:53:11 +02:00
|
|
|
def edit_debdiff(debdiff):
|
2010-12-22 01:28:00 +01:00
|
|
|
cmd = 'sensible-editor %s' % (debdiff)
|
|
|
|
run_cmd(cmd)
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-27 20:02:11 +01:00
|
|
|
def submit_bugreport(body, debdiff, deb_version, changelog):
|
2010-12-27 14:21:01 +01:00
|
|
|
cmd = ('reportbug -P "User: ubuntu-devel@lists.ubuntu.com" '
|
2011-01-21 19:20:04 +01:00
|
|
|
'-P "Usertags: origin-ubuntu %s ubuntu-patch" -T patch -A %s '
|
2010-12-27 14:21:01 +01:00
|
|
|
'-B debian -i %s -V %s %s') % \
|
2011-01-21 19:20:04 +01:00
|
|
|
(UbuntuDistroInfo().devel(), debdiff, body, deb_version,
|
|
|
|
changelog.package)
|
2010-12-22 01:28:00 +01:00
|
|
|
run_cmd(cmd)
|
2007-09-03 10:53:11 +02:00
|
|
|
|
|
|
|
def run_cmd(cmd):
|
2010-12-22 01:28:00 +01:00
|
|
|
if os.getenv('DEBUG'):
|
|
|
|
print "%s\n" % cmd
|
|
|
|
os.system(cmd)
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-27 20:02:11 +01:00
|
|
|
def main():
|
|
|
|
changelog_file = (check_file('debian/changelog', critical = False) or
|
|
|
|
check_file('../debian/changelog'))
|
|
|
|
changelog = Changelog(file(changelog_file).read())
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-27 20:02:11 +01:00
|
|
|
deb_version = get_most_recent_debian_version(changelog)
|
|
|
|
bug_body = get_bug_body(changelog)
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-27 20:02:11 +01:00
|
|
|
fd, body = mkstemp()
|
|
|
|
fp = os.fdopen(fd, 'w')
|
|
|
|
fp.write(bug_body)
|
|
|
|
fp.close()
|
2007-09-03 10:53:11 +02:00
|
|
|
|
2010-12-27 20:02:11 +01:00
|
|
|
debdiff = gen_debdiff(changelog)
|
|
|
|
edit_debdiff(debdiff)
|
|
|
|
submit_bugreport(body, debdiff, deb_version, changelog)
|
|
|
|
os.unlink(body)
|
|
|
|
os.unlink(debdiff)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|