2007-09-05 16:04:37 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# Copyright 2007, Canonical
|
|
|
|
#
|
|
|
|
# GPL 3
|
|
|
|
#
|
|
|
|
#
|
2007-09-06 17:50:26 +02:00
|
|
|
# Notes:
|
2007-09-07 11:47:06 +02:00
|
|
|
# - needs dput, python-launchpad-bugs (>= 0.2.9)
|
2007-09-06 17:50:26 +02:00
|
|
|
# - needs http://launchpad.net/bugs/137767 to get fixed
|
2007-09-05 18:15:23 +02:00
|
|
|
#
|
2007-09-05 16:04:37 +02:00
|
|
|
|
|
|
|
import re
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import string
|
|
|
|
|
2007-09-05 18:15:23 +02:00
|
|
|
try:
|
|
|
|
import launchpadbugs.connector as Connector
|
|
|
|
except:
|
|
|
|
print >> sys.stderr, \
|
2007-09-07 11:47:06 +02:00
|
|
|
"You need python-launchpad-bugs (>= 0.2.9) installed to use revuput."
|
2007-09-05 18:15:23 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
#try:
|
|
|
|
# import apt
|
|
|
|
#except:
|
|
|
|
# print >> sys.stderr, "You need python-apt installed to use revuput."
|
|
|
|
# sys.exit(1)
|
|
|
|
|
|
|
|
|
2007-09-07 11:47:06 +02:00
|
|
|
USAGE = 'Usage: revuput [-n] [<location>] [<debuild options>]'
|
2007-09-05 18:15:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
def dput_check():
|
|
|
|
if not os.path.exists("/usr/bin/dput"):
|
|
|
|
print >> sys.stderr, "You need to install the dput package."
|
|
|
|
sys.exit(1)
|
|
|
|
|
2007-09-05 16:04:37 +02:00
|
|
|
|
|
|
|
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):
|
2007-09-05 18:15:23 +02:00
|
|
|
dput_check()
|
2007-09-06 17:44:31 +02:00
|
|
|
|
|
|
|
incoming = ""
|
|
|
|
res = False
|
|
|
|
|
|
|
|
(dummy, output, dummy) = os.popen3("dput --debug %s %s" % (location, changes))
|
|
|
|
text = output.readlines()
|
|
|
|
for line in text:
|
|
|
|
if line.startswith("D: Incoming: "):
|
|
|
|
incoming = line.split("D: Incoming: ")[1].strip()
|
|
|
|
if incoming[-1] == "/":
|
|
|
|
incoming = incoming[:-1]
|
|
|
|
if line.startswith("Successfully uploaded packages."):
|
|
|
|
res = True
|
|
|
|
return (res, incoming)
|
2007-09-05 16:04:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def lookup_dput_host(host):
|
2007-09-05 18:15:23 +02:00
|
|
|
dput_check()
|
2007-09-05 16:04:37 +02:00
|
|
|
(dummy, output, dummy) = os.popen3("dput -H | grep ^%s" % host)
|
|
|
|
text = output.read()
|
|
|
|
if text:
|
|
|
|
return text.split()[2]
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
|
|
def call_debuild(options):
|
2007-09-06 17:44:31 +02:00
|
|
|
# FIXME: this requires magic, that figures out when to use --native --working,
|
|
|
|
# etc.
|
|
|
|
# if os.path.exists(".bzr") and os.path.exists("/usr/bin/bzr-buildpackage"):
|
|
|
|
# return os.system("bzr bd -S --builder='-k%s %s'" % \
|
|
|
|
# (os.getenv("DEBEMAIL"), \
|
|
|
|
# string.join(options, " "))) == 0
|
|
|
|
# else:
|
2007-09-05 16:04:37 +02:00
|
|
|
return os.system("debuild -S -k%s %s" % \
|
|
|
|
(os.getenv("DEBEMAIL"), \
|
2007-09-06 17:44:31 +02:00
|
|
|
string.join(options, " "))) == 0
|
2007-09-05 16:04:37 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2007-09-06 17:44:31 +02:00
|
|
|
def assemble_bug_comment_text(host, incoming, sourcepackage, version):
|
|
|
|
if host == "ppa.launchpad.net":
|
|
|
|
dsc_file_location = "http://%s/%s/pool/main/%s/%s/%s_%s.dsc" % \
|
|
|
|
(host, incoming[1:], sourcepackage[0], sourcepackage, \
|
|
|
|
sourcepackage, version)
|
|
|
|
else:
|
|
|
|
# FIXME: this needs to be much much cleverer at some stage
|
|
|
|
dsc_file_location = "http://%s/%s/pool/main/%s/%s/%s_%s.dsc" % \
|
|
|
|
(host, incoming, sourcepackage[0], sourcepackage, version)
|
|
|
|
"http://ppa.launchpad.net/dholbach/ubuntu/pool/main/h/hello/hello_2.2-2~ppa1.dsc"
|
2007-09-05 16:04:37 +02:00
|
|
|
return """A new version of %s was uploaded to fix this bug.
|
|
|
|
|
|
|
|
To review the current version, please run
|
|
|
|
|
2007-09-06 17:44:31 +02:00
|
|
|
dget -x %s
|
|
|
|
""" % (sourcepackage, dsc_file_location)
|
2007-09-05 16:04:37 +02:00
|
|
|
|
|
|
|
|
2007-09-06 17:44:31 +02:00
|
|
|
def deal_with_bugreport(bugnumbers, host, incoming, sourcepackage, version):
|
2007-09-05 18:15:23 +02:00
|
|
|
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)
|
2007-09-06 17:44:31 +02:00
|
|
|
component = output.read().strip()
|
2007-09-05 18:15:23 +02:00
|
|
|
|
|
|
|
Bug = Connector.ConnectBug()
|
|
|
|
Bug.authentication = os.path.expanduser("~/.lpcookie")
|
|
|
|
|
|
|
|
for bugnumber in bugnumbers:
|
|
|
|
bug = Bug(int(bugnumber))
|
2007-09-06 17:44:31 +02:00
|
|
|
if component in ["main", "restricted"] and \
|
|
|
|
'ubuntu-main-sponsors' not in [str(s) for s in bug.subscribers]:
|
|
|
|
bug.subscribers.add('ubuntu-main-sponsors')
|
|
|
|
if component in ["universe", "multiverse"] and \
|
|
|
|
'ubuntu-universe-sponsors' not in [str(s) for s in bug.subscribers]:
|
|
|
|
bug.subscribers.add('ubuntu-universe-sponsors')
|
|
|
|
|
|
|
|
comment = Bug.NewComment(text=assemble_bug_comment_text(host, incoming,
|
|
|
|
sourcepackage, version),
|
|
|
|
subject="Fix in %s (%s)" % \
|
|
|
|
(sourcepackage, version))
|
|
|
|
bug.comments.add(comment)
|
|
|
|
|
|
|
|
if bug.status != "Fix Committed":
|
|
|
|
bug.status = "Fix Committed"
|
2007-09-05 18:15:23 +02:00
|
|
|
bug.commit()
|
|
|
|
|
2007-09-05 16:04:37 +02:00
|
|
|
|
2007-09-07 11:47:06 +02:00
|
|
|
def check_arguments(args):
|
|
|
|
new_bug = False
|
|
|
|
location = 'default'
|
|
|
|
debuild_args = list()
|
2007-09-05 16:04:37 +02:00
|
|
|
|
2007-09-07 11:47:06 +02:00
|
|
|
if len(sys.argv) == 1:
|
|
|
|
return (new_bug, location, debuild_args)
|
2007-09-05 16:04:37 +02:00
|
|
|
|
2007-09-07 11:47:06 +02:00
|
|
|
if sys.argv[1] == "-n":
|
|
|
|
new_bug = True
|
|
|
|
if len(sys.argv)>2:
|
|
|
|
if sys.argv[2].startswith("-"):
|
|
|
|
debuild_args = sys.argv[2:]
|
|
|
|
else:
|
|
|
|
location = sys.argv[2]
|
|
|
|
if len(sys.argv)>3:
|
|
|
|
debuild_args = sys.argv[3:]
|
|
|
|
else:
|
|
|
|
if sys.argv[1].startswith("-"):
|
|
|
|
debuild_args.append(sys.argv[1:])
|
|
|
|
else:
|
|
|
|
location = sys.argv[1]
|
|
|
|
if len(sys.argv)>2:
|
|
|
|
debuild_args = sys.argv[2:]
|
|
|
|
|
|
|
|
return (new_bug, location, debuild_args)
|
|
|
|
|
|
|
|
|
|
|
|
def file_bug(sourcepackage, version):
|
|
|
|
Bug = Connector.ConnectBug()
|
|
|
|
Bug.authentication = os.path.expanduser("~/.lpcookie")
|
2007-09-05 16:04:37 +02:00
|
|
|
|
2007-09-07 11:47:06 +02:00
|
|
|
bug = Bug.New(product={"name": sourcepackage, "target": "ubuntu"},
|
|
|
|
summary="Please sponsor %s %s" % (sourcepackage, version),
|
|
|
|
description=\
|
|
|
|
"The new package will be uploaded to PPA shortly.")
|
|
|
|
return bug.bugnumber
|
|
|
|
|
2007-09-05 16:04:37 +02:00
|
|
|
|
2007-09-07 11:47:06 +02:00
|
|
|
def main():
|
|
|
|
(new_bug, location, debuild_args) = check_arguments(sys.argv)
|
|
|
|
(sourcepackage, version) = get_name_and_version()[0]
|
|
|
|
|
|
|
|
if new_bug:
|
|
|
|
bugnumber = file_bug(sourcepackage, version)
|
|
|
|
os.system("dch -a 'Fixes (LP: #%s)'" % bugnumber)
|
|
|
|
if not call_debuild(debuild_args):
|
2007-09-05 16:04:37 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2007-09-07 11:47:06 +02:00
|
|
|
host = lookup_dput_host(location)
|
2007-09-06 17:44:31 +02:00
|
|
|
(dput_res, incoming) = call_dput(location, changesfile)
|
|
|
|
if not dput_res:
|
|
|
|
sys.exit(1)
|
2007-09-05 16:04:37 +02:00
|
|
|
|
2007-09-06 17:44:31 +02:00
|
|
|
fixed_lp_bugs = find_fixed_launchpad_bug(changesfile)
|
2007-09-05 18:15:23 +02:00
|
|
|
if(fixed_lp_bugs):
|
2007-09-06 17:44:31 +02:00
|
|
|
deal_with_bugreport(fixed_lp_bugs, host, incoming, sourcepackage,
|
|
|
|
version)
|
2007-09-05 16:04:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|