3 import os, sys, subprocess, smtplib, re
9 if len(sys.argv) > 2 or len(sys.argv) == 1 and sys.stdin.isatty():
10 print '''Usage: requestsponsor [<debdiff>]
12 File a sponsoring request bug with the given debdiff. If a debdiff is not
13 specified as command line argument, it reads stdin.'''
16 if len(sys.argv) == 1:
18 diff = sys.stdin.read()
20 diff = open(sys.argv[1]).read()
22 # parse diff for source package name
23 changelog_header_re = re.compile('^\+([\w.-]+) \([\w.:+-]+\) ([\w-]+); urgency')
27 for l in diff.splitlines():
28 if l.startswith('+++ '):
29 in_changelog = l.endswith('/debian/changelog')
31 m = changelog_header_re.match(l)
40 # strip pocket from release
41 release = release.split('-')[0]
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'
48 team = 'ubuntu-universe-sponsors'
50 print 'Filing bug against package', package, 'to team', team
53 mailbody = ''' affects distros/ubuntu/%s
57 ''' % (package, team, diff)
61 if os.access('/usr/bin/gnome-gpg', os.X_OK):
62 sign_command = 'gnome-gpg'
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
69 myemailaddr = os.getenv('DEBEMAIL')
71 to = 'new@bugs.launchpad.net'
75 Subject: Please sponsor %s upload
77 %s''' % (myemailaddr, to, package, signed_mailbody)
81 s.sendmail(myemailaddr, to, mail)