diff --git a/debian/changelog b/debian/changelog index 942697f..ca1efa0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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) diff --git a/debian/copyright b/debian/copyright index 3ba1702..84445df 100644 --- a/debian/copyright +++ b/debian/copyright @@ -95,6 +95,7 @@ Files: ack-sync merge-changelog setup-packaging-environment syncpackage + ubuntutools/harvest.py Copyright: 2010, Benjamin Drung 2007-2011, Canonical Ltd. 2008, Jonathan Patrick Davies diff --git a/harvest b/harvest index 570c37e..d345719 100755 --- a/harvest +++ b/harvest @@ -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) diff --git a/ubuntutools/harvest.py b/ubuntutools/harvest.py new file mode 100644 index 0000000..3fc2d5e --- /dev/null +++ b/ubuntutools/harvest.py @@ -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)) diff --git a/ubuntutools/sponsor_patch/sponsor_patch.py b/ubuntutools/sponsor_patch/sponsor_patch.py index 5f3001d..dfb672c 100644 --- a/ubuntutools/sponsor_patch/sponsor_patch.py +++ b/ubuntutools/sponsor_patch/sponsor_patch.py @@ -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: