From 015b806f241c76d31611c7bcf565c89c6af84bfc Mon Sep 17 00:00:00 2001 From: Vikraman Choudhury Date: Mon, 22 Aug 2011 04:32:27 +0530 Subject: fix exceptions --- client/gentoostats-send | 18 ++++++++++-------- client/gentoostats/list.py | 6 ++---- client/gentoostats/search.py | 6 ++---- 3 files changed, 14 insertions(+), 16 deletions(-) (limited to 'client') diff --git a/client/gentoostats-send b/client/gentoostats-send index 49dcb83..324b2bc 100755 --- a/client/gentoostats-send +++ b/client/gentoostats-send @@ -4,7 +4,7 @@ import sys import json import argparse import ConfigParser -import urllib, httplib +import httplib from gentoostats.payload import Payload def getAuthInfo(auth): @@ -63,13 +63,15 @@ def main(): post_body = serialize(post_data, human=True) post_headers = {'Content-type':'application/json'} - conn = httplib.HTTPSConnection(args['server'] + ':' + str(args['port'])) - conn.request('POST', url=post_url, headers=post_headers, body=post_body) - - #TODO: Handle exceptions - response = conn.getresponse() - print response.status, response.reason - print 'Server response: ' + response.read() + try: + conn = httplib.HTTPSConnection(args['server'] + ':' + str(args['port'])) + conn.request('POST', url=post_url, headers=post_headers, body=post_body) + response = conn.getresponse() + print response.status, response.reason + print 'Server response: ' + response.read() + except httplib.HTTPException: + sys.stderr.write('Something went wrong') + sys.exit(1) if __name__ == "__main__": main() diff --git a/client/gentoostats/list.py b/client/gentoostats/list.py index 78ec0e4..3140041 100644 --- a/client/gentoostats/list.py +++ b/client/gentoostats/list.py @@ -1,20 +1,18 @@ +import pprint as pp from gentoostats import utils def pprint(title, object): """ Pretty printer for the decoded json data """ - # TODO: write a custom pretty printer here - import pprint print title - pprint.pprint(object) + pp.pprint(object) def add_parser(subparsers): """ Setup argparse parsers """ - # TODO: add help and descriptions for all opts list_parser = subparsers.add_parser('list') list_subparsers = list_parser.add_subparsers() diff --git a/client/gentoostats/search.py b/client/gentoostats/search.py index dfc4b29..c77c119 100644 --- a/client/gentoostats/search.py +++ b/client/gentoostats/search.py @@ -1,20 +1,18 @@ +import pprint as pp from gentoostats import utils def pprint(title, object): """ Pretty printer for the decoded json data """ - # TODO: write a custom pretty printer here - import pprint print title - pprint.pprint(object) + pp.pprint(object) def add_parser(subparsers): """ Setup argparse parsers """ - # TODO: add help and descriptions for all opts search_parser = subparsers.add_parser('search') search_parser.add_argument('-c', '--category') search_parser.add_argument('-p', '--package') -- cgit v1.2.3-65-gdbad