153 lines
3.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python
#
# Copyright 2007, Canonical
#
# GPL 3
#
#
# Notes: needs dput, python-launchpad-bugs (>= 0.2.4)
#
import re
import os
import sys
import string
try:
import launchpadbugs.connector as Connector
except:
print >> sys.stderr, \
"You need python-launchpad-bugs (>= 0.2.4) installed to use revuput."
sys.exit(1)
#try:
# import apt
#except:
# print >> sys.stderr, "You need python-apt installed to use revuput."
# sys.exit(1)
USAGE = 'Usage: revuput <location> [<debuild options>]'
def dput_check():
if not os.path.exists("/usr/bin/dput"):
print >> sys.stderr, "You need to install the dput package."
sys.exit(1)
def find_fixed_launchpad_bug(changesfile):
changes = open(changesfile).readlines()
for line in changes:
if line.startswith("Launchpad-Bugs-Fixed"):
return line.split(":")[1].split()
return []
def call_dput(location, changes):
dput_check()
return os.system("dput %s %s" % (location, changes)) == 0
def lookup_dput_host(host):
dput_check()
(dummy, output, dummy) = os.popen3("dput -H | grep ^%s" % host)
text = output.read()
if text:
return text.split()[2]
return ""
def call_debuild(options):
return os.system("debuild -S -k%s %s" % \
(os.getenv("DEBEMAIL"), \
string.join(options, " "))) == 0
def get_name_and_version():
changelogfile = "debian/changelog"
if not os.path.exists(changelogfile):
print >> sys.stderr, "%s not found." % changelogfile
sys.exit(1)
head = open(changelogfile).readline()
return re.findall(r'^(.*)\ \((.*)\).*', head)
def assemble_bug_comment_text(host, sourcepackage, version):
return """A new version of %s was uploaded to fix this bug.
To review the current version, please run
dget -x http://%s/%s_%s.dsc
""" % (sourcepackage, host, sourcepackage, version)
def deal_with_bugreport(bugnumbers, host, sourcepackage, version):
if not os.path.exists(os.path.expanduser("~/.lpcookie")):
print >> sys.stderr, \
"You need your Launchpad Cookie to be stored in ~/.lpcookie"
sys.exit(1)
#print apt.Cache()[sourcepackage].section.split("/")[0].count("verse")
(dummy, output, dummy) = os.popen3(
"apt-cache showsrc %s | grep Directory | cut -d' ' -f2 | cut -d'/' -f2" % \
sourcepackage)
component = output.read()
Bug = Connector.ConnectBug()
Bug.authentication = os.path.expanduser("~/.lpcookie")
for bugnumber in bugnumbers:
bug = Bug(int(bugnumber))
# FIXME: should really be subscribers
# if component in ["main", "restricted"] and \
# bug.assignee != 'ubuntu-main-sponsors':
# bug.assignee = 'ubuntu-main-sponsors'
# if component in ["universe", "multiverse"] and \
# bug.assignee != 'ubuntu-universe-sponsors':
# bug.assignee = 'ubuntu-universe-sponsors'
# FIXME: does not work yet
# comment = Bug.NewComment(text=assemble_bug_comment_text(host,
# sourcepackage, version))
# bug.comments.add(comment)
bug.status = "Fix Committed"
bug.commit()
def main():
location = ""
options = []
if len(sys.argv)<2:
print >> sys.stderr, USAGE
sys.exit(1)
location = sys.argv[1]
if len(sys.argv) > 2:
options = sys.argv[2:]
if not call_debuild(options):
sys.exit(1)
(sourcepackage, version) = get_name_and_version()[0]
changesfile = "../%s_%s_source.changes" % (sourcepackage, version)
if not os.path.exists(os.path.expanduser(changesfile)):
print >> sys.stderr, "%s does not exist." % \
os.path.expanduser(changesfile)
sys.exit(1)
fixed_lp_bugs = find_fixed_launchpad_bug(changesfile)
host = lookup_dput_host(location)
if(fixed_lp_bugs):
deal_with_bugreport(fixed_lp_bugs, host, sourcepackage, version)
#if not call_dput(location, changesfile):
# sys.exit(1)
if __name__ == '__main__':
main()