mirror of
				https://git.launchpad.net/ubuntu-dev-tools
				synced 2025-11-04 16:04:02 +00:00 
			
		
		
		
	harvest, setup.py: install tool that queries Harvest for information
about open opportunities for a given source package.
This commit is contained in:
		
							parent
							
								
									142fcc94a3
								
							
						
					
					
						commit
						ad837ae9cf
					
				
							
								
								
									
										7
									
								
								debian/changelog
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								debian/changelog
									
									
									
									
										vendored
									
									
								
							@ -1,3 +1,10 @@
 | 
			
		||||
ubuntu-dev-tools (0.115) UNRELEASED; urgency=low
 | 
			
		||||
 | 
			
		||||
  * harvest, setup.py: install tool that queries Harvest for information
 | 
			
		||||
    about open opportunities for a given source package.
 | 
			
		||||
 | 
			
		||||
 -- Daniel Holbach <daniel.holbach@ubuntu.com>  Wed, 26 Jan 2011 09:21:43 +0100
 | 
			
		||||
 | 
			
		||||
ubuntu-dev-tools (0.114) unstable; urgency=low
 | 
			
		||||
 | 
			
		||||
  [ Stefano Rivera ]
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										51
									
								
								harvest
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										51
									
								
								harvest
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,51 @@
 | 
			
		||||
#!/usr/bin/python
 | 
			
		||||
# Daniel Holbach 
 | 
			
		||||
# (c) 2011 Canonical
 | 
			
		||||
 | 
			
		||||
import urllib2
 | 
			
		||||
import json
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
BASE_URL = "http://harvest.ubuntu.com/"
 | 
			
		||||
URL_STUB = BASE_URL + "opportunities/json/"
 | 
			
		||||
 | 
			
		||||
def opportunity_summary(data):
 | 
			
		||||
    l = []
 | 
			
		||||
    for key in filter(lambda a: a != "total", data.keys()):
 | 
			
		||||
        l += ["%s (%s)" % (key, data[key])]
 | 
			
		||||
    return ", ".join(l)
 | 
			
		||||
 | 
			
		||||
def main():
 | 
			
		||||
    if len(sys.argv) == 1 or not sys.argv[1].strip() or \
 | 
			
		||||
       sys.argv[1].strip() in ["--help", "-h"]:
 | 
			
		||||
        print >> sys.stderr, "Usage: %s <source package name>" % sys.argv[0]
 | 
			
		||||
        sys.exit(0)
 | 
			
		||||
    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)
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    try:
 | 
			
		||||
        main()
 | 
			
		||||
    except KeyboardInterrupt:
 | 
			
		||||
        print >> sys.stderr, "Aborted."
 | 
			
		||||
        sys.exit(1)
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user