Run harvest as part of sponsor-patch (LP: #833699).

This commit is contained in:
Benjamin Drung 2011-09-06 13:11:42 +02:00
commit 37917959fc
5 changed files with 79 additions and 35 deletions

1
debian/changelog vendored
View File

@ -29,6 +29,7 @@ ubuntu-dev-tools (0.129) UNRELEASED; urgency=low
* ubuntutools.archive: Don't write .dsc files until we pull the entire
source package, just hold it in memory. Avoids littering the current
directory (LP: #838361)
* Run harvest as part of sponsor-patch (LP: #833699)
[ Julian Taylor ]
* requestsync: omit dups when checking for duplicate requests (LP: #842217)

1
debian/copyright vendored
View File

@ -95,6 +95,7 @@ Files: ack-sync
merge-changelog
setup-packaging-environment
syncpackage
ubuntutools/harvest.py
Copyright: 2010, Benjamin Drung <bdrung@ubuntu.com>
2007-2011, Canonical Ltd.
2008, Jonathan Patrick Davies <jpds@ubuntu.com>

42
harvest
View File

@ -26,52 +26,26 @@
# (c) 2011 Canonical
from optparse import OptionParser
import urllib2
import json
import sys
BASE_URL = "http://harvest.ubuntu.com/"
URL_STUB = BASE_URL + "opportunities/json/"
from devscripts.logger import Logger
def opportunity_summary(data):
l = []
for key in filter(lambda a: a != "total", data.keys()):
l += ["%s (%s)" % (key, data[key])]
return ", ".join(l)
from ubuntutools.harvest import Harvest
def main():
usage = "usage: %prog source-package-name"
opt_parser = OptionParser(usage)
(options, args) = opt_parser.parse_args()
if not args:
args = opt_parser.parse_args()[1]
if len(args) != 1:
opt_parser.print_help()
sys.exit(1)
pkg = sys.argv[1]
url = URL_STUB + pkg.strip()
try:
sock = urllib2.urlopen(url)
except IOError, e:
try:
urllib2.urlopen(BASE_URL)
except urllib2.URLError, _e:
print >> sys.stderr, "Harvest is down."
sys.exit(1)
print "There is no information in Harvest about package '%s'." % pkg
sys.exit(1)
response = sock.read()
sock.close()
data = json.loads(response)
print >> sys.stdout, \
"""%s has %s opportunities: %s
Find out more: %sopportunities/package/%s""" % (pkg,
data["total"],
opportunity_summary(data),
BASE_URL,
pkg)
pkg = args[0].strip()
print Harvest(pkg).report()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print >> sys.stderr, "Aborted."
Logger.error("Aborted.")
sys.exit(1)

62
ubuntutools/harvest.py Normal file
View File

@ -0,0 +1,62 @@
# Copyright (C) 2011 Canonical Ltd., Daniel Holbach, Stefano Rivera
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# See file /usr/share/common-licenses/GPL-3 for more details.
import json
import os.path
import sys
import urllib2
from devscripts.logger import Logger
BASE_URL = "http://harvest.ubuntu.com/"
class Harvest(object):
"""The harvest data for a package"""
def __init__(self, package):
self.package = package
self.human_url = os.path.join(BASE_URL, "opportunities", "package",
package)
self.data_url = os.path.join(BASE_URL, "opportunities", "json", package)
self.data = self._get_data()
def _get_data(self):
try:
sock = urllib2.urlopen(self.data_url)
except IOError:
try:
urllib2.urlopen(BASE_URL)
except urllib2.URLError:
Logger.error("Harvest is down.")
sys.exit(1)
return None
response = sock.read()
sock.close()
return json.loads(response)
def opportunity_summary(self):
l = []
for key in filter(lambda a: a != "total", self.data.keys()):
l += ["%s (%s)" % (key, self.data[key])]
return ", ".join(l)
def report(self):
if self.data is None:
return ("There is no information in Harvest about package '%s'."
% self.package)
return ("%s has %s opportunities: %s\n"
"Find out more: %s"
% (self.package,
self.data["total"],
self.opportunity_summary(),
self.human_url))

View File

@ -28,6 +28,7 @@ import launchpadlib.launchpad
from devscripts.logger import Logger
from ubuntutools import subprocess
from ubuntutools.harvest import Harvest
from ubuntutools.update_maintainer import update_maintainer
from ubuntutools.question import Question, YesNoQuestion, input_number
@ -481,11 +482,16 @@ def sponsor_patch(bug_number, build, builder, edit, keyid, lpinstance, update,
# Upload package
if upload:
print "Please check %s %s carefully:\nfile://%s\nfile://%s" % \
print "\nPlease check %s %s carefully:\nfile://%s\nfile://%s" % \
(task.package, new_version, debdiff_filename,
lintian_filename)
if build_log:
print "file://%s" % build_log
harvest = Harvest(task.package)
if harvest.data:
print harvest.report()
if upload == "ubuntu":
target = "the official Ubuntu archive"
else: