]> piware.de Git - bin.git/blob - requestsponsor
initial checkin
[bin.git] / requestsponsor
1 #!/usr/bin/python
2
3 import os, sys, subprocess, smtplib, re
4
5 #
6 # entry point
7 #
8
9 if len(sys.argv) > 2 or len(sys.argv) == 1 and sys.stdin.isatty():
10     print '''Usage: requestsponsor [<debdiff>]
11
12 File a sponsoring request bug with the given debdiff. If a debdiff is not
13 specified as command line argument, it reads stdin.'''
14     sys.exit (1)
15
16 if len(sys.argv) == 1:
17     # read stdin
18     diff = sys.stdin.read()
19 else:
20     diff = open(sys.argv[1]).read()
21
22 # parse diff for source package name
23 changelog_header_re = re.compile('^\+([\w.-]+) \([\w.:+-]+\) ([\w-]+); urgency')
24 in_changelog = False
25 package = None
26 release = None
27 for l in diff.splitlines():
28     if l.startswith('+++ '):
29         in_changelog = l.endswith('/debian/changelog')
30     if in_changelog:
31         m = changelog_header_re.match(l)
32         if m:
33             package = m.group(1)
34             release = m.group(2)
35             break
36
37 assert package
38 assert release
39
40 # strip pocket from  release
41 release = release.split('-')[0]
42
43 # determine team (main/universe)
44 if subprocess.call('apt-cache madison %s | \
45     egrep -q "%s/(main|restricted).*Sources"' % (package, release), shell=True) == 0:
46     team = 'ubuntu-main-sponsors'
47 else:
48     team = 'ubuntu-universe-sponsors'
49
50 print 'Filing bug against package', package, 'to team', team
51
52 # generate bug report
53 mailbody = ''' affects distros/ubuntu/%s
54  subscribe %s
55
56 %s
57 ''' % (package, team, diff)
58
59 # sign it
60 sign_command = 'gpg'
61 if os.access('/usr/bin/gnome-gpg', os.X_OK):
62     sign_command = 'gnome-gpg'
63
64 gpg = subprocess.Popen([sign_command, '--clearsign'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
65 signed_mailbody = gpg.communicate(mailbody)[0]
66 assert gpg.returncode == 0
67
68 # generate email
69 myemailaddr = os.getenv('DEBEMAIL')
70 assert myemailaddr
71 to = 'new@bugs.launchpad.net'
72
73 mail = '''From: %s
74 To: %s
75 Subject: Please sponsor %s upload
76
77 %s''' % (myemailaddr, to, package, signed_mailbody)
78
79 s = smtplib.SMTP()
80 s.connect()
81 s.sendmail(myemailaddr, to, mail)
82 s.close()