3 import os, os.path, sys, urllib, subprocess, smtplib
7 def cur_version_component(sourcepkg, release):
8 madison = subprocess.Popen(['apt-cache', 'madison', sourcepkg], stdout=subprocess.PIPE)
9 out = madison.communicate()[0]
10 assert (madison.returncode == 0)
12 for l in out.splitlines():
13 (pkg, version, aptsrc) = l.split('|')
14 if aptsrc.endswith('Sources') and aptsrc.find(release) > 0:
16 for w in aptsrc.split():
17 if w.startswith(release):
18 component = w.split('/')[1]
19 assert component != ''
20 return (version.strip(), component)
22 raise Exception('apt-cache madison does not contain %s/%s' % (sourcepkg, release))
24 def debian_changelog(sourcepkg, version):
25 '''Return the Debian changelog from the latest up to the given version
29 for l in urllib.urlopen('http://changelogs.debian.net/' + sourcepkg):
30 if l.startswith(sourcepkg) and l.find(version + ')') > 0:
40 if len(sys.argv) != 3:
41 print 'Usage: requestsync <source package> <target release>'
44 (srcpkg, release) = sys.argv[1:]
45 (cur_ver, component) = cur_version_component(srcpkg, release)
51 report += ''' affects distros/ubuntu/%s
53 subscribe ubuntu-archive
57 report += 'Please sync %s (%s) from Debian unstable.\n' % (srcpkg, component)
60 uidx = base_ver.find('ubuntu')
62 base_ver = base_ver[:uidx]
63 report += '\nOverriding Ubuntu changes is ok.\n'
66 uidx = base_ver.find('build')
68 base_ver = base_ver[:uidx]
70 report += '\nChangelog since current %s version %s:\n\n' % (release, cur_ver)
71 report += debian_changelog(srcpkg, base_ver) + '\n'
75 if os.access('/usr/bin/gnome-gpg', os.X_OK):
76 sign_command = 'gnome-gpg'
78 gpg = subprocess.Popen([sign_command, '--clearsign'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
79 signed_report = gpg.communicate(report)[0]
80 assert gpg.returncode == 0
83 myemailaddr = os.getenv('DEBEMAIL')
85 to = 'new@bugs.launchpad.net'
89 Subject: Please sync %s (%s) from unstable
91 %s''' % (myemailaddr, to, srcpkg, component, signed_report)
94 print 'Press enter to file this bug, Control-C to abort'
99 s.sendmail(myemailaddr, to, mail)