#!/usr/bin/python import os, sys, subprocess, smtplib, re # # entry point # if len(sys.argv) > 2 or len(sys.argv) == 1 and sys.stdin.isatty(): print '''Usage: requestsponsor [] File a sponsoring request bug with the given debdiff. If a debdiff is not specified as command line argument, it reads stdin.''' sys.exit (1) if len(sys.argv) == 1: # read stdin diff = sys.stdin.read() else: diff = open(sys.argv[1]).read() # parse diff for source package name changelog_header_re = re.compile('^\+([\w.-]+) \([\w.:+-]+\) ([\w-]+); urgency') in_changelog = False package = None release = None for l in diff.splitlines(): if l.startswith('+++ '): in_changelog = l.endswith('/debian/changelog') if in_changelog: m = changelog_header_re.match(l) if m: package = m.group(1) release = m.group(2) break assert package assert release # strip pocket from release release = release.split('-')[0] # determine team (main/universe) if subprocess.call('apt-cache madison %s | \ egrep -q "%s/(main|restricted).*Sources"' % (package, release), shell=True) == 0: team = 'ubuntu-main-sponsors' else: team = 'ubuntu-universe-sponsors' print 'Filing bug against package', package, 'to team', team # generate bug report mailbody = ''' affects ubuntu/%s subscribe %s %s ''' % (package, team, diff) # sign it sign_command = 'gpg' if os.access('/usr/bin/gnome-gpg', os.X_OK): sign_command = 'gnome-gpg' gpg = subprocess.Popen([sign_command, '--clearsign'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) signed_mailbody = gpg.communicate(mailbody)[0] assert gpg.returncode == 0 # generate email myemailaddr = os.getenv('DEBEMAIL') assert myemailaddr to = 'new@bugs.launchpad.net' mail = '''From: %s To: %s Subject: Please sponsor %s upload %s''' % (myemailaddr, to, package, signed_mailbody) s = smtplib.SMTP() s.connect() s.sendmail(myemailaddr, to, mail) s.close()