]> piware.de Git - bin.git/blob - requestsync
add fixbug
[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> [basever]
42
43 In some cases, the base version (fork point from Debian) cannot be determined
44 automatically, and you'll get a complete Debian changelog. Specify the correct
45 base version in that case.'''
46     sys.exit (1)
47
48 (srcpkg, release) = sys.argv[1:3]
49 force_base_ver = None
50 if len(sys.argv) >= 4:
51     force_base_ver = sys.argv[3]
52 (cur_ver, component) = cur_version_component(srcpkg, release)
53
54 # TODO: figure this out from packages.qa.debian.org; changelogs.d.n only works
55 # for main ATM anyway, though
56 debiancomponent = 'main'
57
58 # generate bug report
59 report = ''
60
61 report += ''' affects distros/ubuntu/%s
62  status confirmed
63  subscribe ubuntu-archive
64
65 ''' % srcpkg
66
67 report += 'Please sync %s (%s) from Debian unstable (%s).\n' % (srcpkg, component, debiancomponent)
68
69 ubuntuchanges = False
70 base_ver = cur_ver
71 uidx = base_ver.find('ubuntu')
72 if uidx > 0:
73     base_ver = base_ver[:uidx]
74     ubuntuchanges = True
75
76 if changelog:
77     uidx = base_ver.find('build')
78     if uidx > 0:
79         base_ver = base_ver[:uidx]
80
81     if force_base_ver:
82         base_ver = force_base_ver
83     
84     report += '\nChangelog since current %s version %s:\n\n' % (release, cur_ver)
85     report += debian_changelog(srcpkg, base_ver) + '\n'
86
87 # sign it
88 sign_command = 'gpg'
89 if os.access('/usr/bin/gnome-gpg', os.X_OK):
90     sign_command = 'gnome-gpg'
91
92 gpg = subprocess.Popen([sign_command, '--clearsign'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
93 signed_report = gpg.communicate(report)[0]
94 assert gpg.returncode == 0
95
96 # generate email
97 myemailaddr = os.getenv('DEBEMAIL')
98 assert myemailaddr
99 to = 'new@bugs.launchpad.net'
100
101 mail = '''From: %s
102 To: %s
103 Subject: Please sync %s (%s) from unstable (%s)
104
105 %s''' % (myemailaddr, to, srcpkg, component, debiancomponent, signed_report)
106
107 print mail
108
109 print 'Press enter to file this bug, Control-C to abort'
110 sys.stdin.readline()
111
112 s = smtplib.SMTP('fiordland.ubuntu.com')
113 s.sendmail(myemailaddr, to, mail)
114 s.quit()
115
116 if ubuntuchanges:
117     print 'You need to write a followup bug comment with some short explanation of the Ubuntu delta and why it can be dropped.'
118