Merge lp:~stefanor/ubuntu-dev-tools/sponsor-patch-harvest-833699 into lp:~ubuntu-dev/ubuntu-dev-tools/trunk

Proposed by Stefano Rivera
Status: Merged
Merged at revision: 1135
Proposed branch: lp:~stefanor/ubuntu-dev-tools/sponsor-patch-harvest-833699
Merge into: lp:~ubuntu-dev/ubuntu-dev-tools/trunk
Diff against target: 172 lines (+77/-34)
4 files modified
debian/copyright (+1/-0)
harvest (+7/-33)
ubuntutools/harvest.py (+62/-0)
ubuntutools/sponsor_patch/sponsor_patch.py (+7/-1)
To merge this branch: bzr merge lp:~stefanor/ubuntu-dev-tools/sponsor-patch-harvest-833699
Reviewer Review Type Date Requested Status
Ubuntu Development Team Pending
Review via email: mp+73977@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/copyright'
2--- debian/copyright 2011-09-02 11:52:26 +0000
3+++ debian/copyright 2011-09-03 23:11:01 +0000
4@@ -95,6 +95,7 @@
5 merge-changelog
6 setup-packaging-environment
7 syncpackage
8+ ubuntutools/harvest.py
9 Copyright: 2010, Benjamin Drung <bdrung@ubuntu.com>
10 2007-2011, Canonical Ltd.
11 2008, Jonathan Patrick Davies <jpds@ubuntu.com>
12
13=== modified file 'harvest'
14--- harvest 2011-05-23 21:44:45 +0000
15+++ harvest 2011-09-03 23:11:01 +0000
16@@ -26,52 +26,26 @@
17 # (c) 2011 Canonical
18
19 from optparse import OptionParser
20-import urllib2
21-import json
22 import sys
23
24-BASE_URL = "http://harvest.ubuntu.com/"
25-URL_STUB = BASE_URL + "opportunities/json/"
26+from devscripts.logger import Logger
27
28-def opportunity_summary(data):
29- l = []
30- for key in filter(lambda a: a != "total", data.keys()):
31- l += ["%s (%s)" % (key, data[key])]
32- return ", ".join(l)
33+from ubuntutools.harvest import Harvest
34
35 def main():
36 usage = "usage: %prog source-package-name"
37 opt_parser = OptionParser(usage)
38 (options, args) = opt_parser.parse_args()
39- if not args:
40+ if len(args) != 1:
41 opt_parser.print_help()
42 sys.exit(1)
43- pkg = sys.argv[1]
44- url = URL_STUB + pkg.strip()
45- try:
46- sock = urllib2.urlopen(url)
47- except IOError, e:
48- try:
49- urllib2.urlopen(BASE_URL)
50- except urllib2.URLError, _e:
51- print >> sys.stderr, "Harvest is down."
52- sys.exit(1)
53- print "There is no information in Harvest about package '%s'." % pkg
54- sys.exit(1)
55- response = sock.read()
56- sock.close()
57- data = json.loads(response)
58- print >> sys.stdout, \
59-"""%s has %s opportunities: %s
60-Find out more: %sopportunities/package/%s""" % (pkg,
61- data["total"],
62- opportunity_summary(data),
63- BASE_URL,
64- pkg)
65+ pkg = args[0].strip()
66+
67+ print Harvest(pkg).report()
68
69 if __name__ == '__main__':
70 try:
71 main()
72 except KeyboardInterrupt:
73- print >> sys.stderr, "Aborted."
74+ Logger.error("Aborted.")
75 sys.exit(1)
76
77=== added file 'ubuntutools/harvest.py'
78--- ubuntutools/harvest.py 1970-01-01 00:00:00 +0000
79+++ ubuntutools/harvest.py 2011-09-03 23:11:01 +0000
80@@ -0,0 +1,62 @@
81+# Copyright (C) 2011 Canonical Ltd., Daniel Holbach, Stefano Rivera
82+#
83+# This program is free software; you can redistribute it and/or
84+# modify it under the terms of the GNU General Public License
85+# as published by the Free Software Foundation; version 3.
86+#
87+# This program is distributed in the hope that it will be useful,
88+# but WITHOUT ANY WARRANTY; without even the implied warranty of
89+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90+# GNU General Public License for more details.
91+#
92+# See file /usr/share/common-licenses/GPL-3 for more details.
93+
94+import json
95+import os.path
96+import sys
97+import urllib2
98+
99+from devscripts.logger import Logger
100+
101+BASE_URL = "http://harvest.ubuntu.com/"
102+
103+class Harvest(object):
104+ """The harvest data for a package"""
105+
106+ def __init__(self, package):
107+ self.package = package
108+ self.human_url = os.path.join(BASE_URL, "opportunities", "package",
109+ package)
110+ self.data_url = os.path.join(BASE_URL, "opportunities", "json", package)
111+ self.data = self._get_data()
112+
113+ def _get_data(self):
114+ try:
115+ sock = urllib2.urlopen(self.data_url)
116+ except IOError:
117+ try:
118+ urllib2.urlopen(BASE_URL)
119+ except urllib2.URLError:
120+ Logger.error("Harvest is down.")
121+ sys.exit(1)
122+ return None
123+ response = sock.read()
124+ sock.close()
125+ return json.loads(response)
126+
127+ def opportunity_summary(self):
128+ l = []
129+ for key in filter(lambda a: a != "total", self.data.keys()):
130+ l += ["%s (%s)" % (key, self.data[key])]
131+ return ", ".join(l)
132+
133+ def report(self):
134+ if self.data is None:
135+ return ("There is no information in Harvest about package '%s'."
136+ % self.package)
137+ return ("%s has %s opportunities: %s\n"
138+ "Find out more: %s"
139+ % (self.package,
140+ self.data["total"],
141+ self.opportunity_summary(),
142+ self.human_url))
143
144=== modified file 'ubuntutools/sponsor_patch/sponsor_patch.py'
145--- ubuntutools/sponsor_patch/sponsor_patch.py 2011-06-24 14:32:07 +0000
146+++ ubuntutools/sponsor_patch/sponsor_patch.py 2011-09-03 23:11:01 +0000
147@@ -28,6 +28,7 @@
148 from devscripts.logger import Logger
149
150 from ubuntutools import subprocess
151+from ubuntutools.harvest import Harvest
152 from ubuntutools.update_maintainer import update_maintainer
153 from ubuntutools.question import Question, YesNoQuestion, input_number
154
155@@ -481,11 +482,16 @@
156
157 # Upload package
158 if upload:
159- print "Please check %s %s carefully:\nfile://%s\nfile://%s" % \
160+ print "\nPlease check %s %s carefully:\nfile://%s\nfile://%s" % \
161 (task.package, new_version, debdiff_filename,
162 lintian_filename)
163 if build_log:
164 print "file://%s" % build_log
165+
166+ harvest = Harvest(task.package)
167+ if harvest.data:
168+ print harvest.report()
169+
170 if upload == "ubuntu":
171 target = "the official Ubuntu archive"
172 else:

Subscribers

People subscribed via source and target branches

to status/vote changes: