]> piware.de Git - bin.git/blob - requestsync
requestsync: remove "Ubuntu changes can be dropped" stanza, point out necessary bug...
[bin.git] / requestsync
1 #!/usr/bin/python
2
3 import os, os.path, sys, urllib, subprocess, smtplib
4
5 changelog = 1
6
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)
11
12     for l in out.splitlines():
13         (pkg, version, aptsrc) = l.split('|')
14         if aptsrc.endswith('Sources') and aptsrc.find(release) > 0:
15             component = ''
16             for w in aptsrc.split():
17                 if w.startswith(release):
18                     component = w.split('/')[1]
19             assert component != ''
20             return (version.strip(), component)
21
22     raise Exception('apt-cache madison does not contain %s/%s' % (sourcepkg, release))
23
24 def debian_changelog(sourcepkg, version):
25     '''Return the Debian changelog from the latest up to the given version
26     (exclusive).'''
27
28     ch = ''
29     for l in urllib.urlopen('http://changelogs.debian.net/' + sourcepkg):
30         if l.startswith(sourcepkg) and l.find(version + ')') > 0:
31             break
32         ch += l
33
34     return ch
35
36 #
37 # entry point
38 #
39
40 if len(sys.argv) != 3:
41     print 'Usage: requestsync <source package> <target release>'
42     sys.exit (1)
43
44 (srcpkg, release) = sys.argv[1:]
45 (cur_ver, component) = cur_version_component(srcpkg, release)
46
47
48 # generate bug report
49 report = ''
50
51 report += ''' affects distros/ubuntu/%s
52  status confirmed
53  subscribe ubuntu-archive
54
55 ''' % srcpkg
56
57 report += 'Please sync %s (%s) from Debian unstable.\n' % (srcpkg, component)
58
59 ubuntuchanges = False
60 base_ver = cur_ver
61 uidx = base_ver.find('ubuntu')
62 if uidx > 0:
63     base_ver = base_ver[:uidx]
64     ubuntuchanges = True
65
66 if changelog:
67     uidx = base_ver.find('build')
68     if uidx > 0:
69         base_ver = base_ver[:uidx]
70
71     report += '\nChangelog since current %s version %s:\n\n' % (release, cur_ver)
72     report += debian_changelog(srcpkg, base_ver) + '\n'
73
74 # sign it
75 sign_command = 'gpg'
76 if os.access('/usr/bin/gnome-gpg', os.X_OK):
77     sign_command = 'gnome-gpg'
78
79 gpg = subprocess.Popen([sign_command, '--clearsign'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
80 signed_report = gpg.communicate(report)[0]
81 assert gpg.returncode == 0
82
83 # generate email
84 myemailaddr = os.getenv('DEBEMAIL')
85 assert myemailaddr
86 to = 'new@bugs.launchpad.net'
87
88 mail = '''From: %s
89 To: %s
90 Subject: Please sync %s (%s) from unstable
91
92 %s''' % (myemailaddr, to, srcpkg, component, signed_report)
93
94 print mail
95
96 print 'Press enter to file this bug, Control-C to abort'
97 sys.stdin.readline()
98
99 s = smtplib.SMTP()
100 s.connect()
101 s.sendmail(myemailaddr, to, mail)
102 s.close()
103
104 if ubuntuchanges:
105     print 'You need to write a followup bug comment with some short explanation of the Ubuntu delta and why it can be dropped.'
106