aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVikraman Choudhury <vikraman.choudhury@gmail.com>2011-07-11 02:58:35 +0530
committerVikraman Choudhury <vikraman.choudhury@gmail.com>2011-07-11 02:58:35 +0530
commit1cb6b9cc00ad839c47453ba3b554df1fb8508508 (patch)
tree2b963f322ea3d66fa7c2071c3cfe14621c1ff10a /client/gentoostats-send
parentper useflag stats (diff)
downloadgentoostats-1cb6b9cc00ad839c47453ba3b554df1fb8508508.tar.gz
gentoostats-1cb6b9cc00ad839c47453ba3b554df1fb8508508.tar.bz2
gentoostats-1cb6b9cc00ad839c47453ba3b554df1fb8508508.zip
fix tabs
Diffstat (limited to 'client/gentoostats-send')
-rwxr-xr-xclient/gentoostats-send86
1 files changed, 43 insertions, 43 deletions
diff --git a/client/gentoostats-send b/client/gentoostats-send
index 73d53a2..f2b7246 100755
--- a/client/gentoostats-send
+++ b/client/gentoostats-send
@@ -8,59 +8,59 @@ import urllib, httplib
from gentoostats.payload import Payload
def getAuthInfo(auth):
- config = ConfigParser.ConfigParser()
- if len(config.read(auth)) == 0:
- sys.stderr.write('Cannot read ' + auth)
- sys.exit(1)
+ config = ConfigParser.ConfigParser()
+ if len(config.read(auth)) == 0:
+ sys.stderr.write('Cannot read ' + auth)
+ sys.exit(1)
- try:
- uuid = config.get('AUTH', 'UUID')
- passwd = config.get('AUTH', 'PASSWD')
- auth_info = {'UUID' : uuid, 'PASSWD' : passwd}
- return auth_info
- except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
- sys.stderr.write('Malformed auth config')
- sys.exit(1)
+ try:
+ uuid = config.get('AUTH', 'UUID')
+ passwd = config.get('AUTH', 'PASSWD')
+ auth_info = {'UUID' : uuid, 'PASSWD' : passwd}
+ return auth_info
+ except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
+ sys.stderr.write('Malformed auth config')
+ sys.exit(1)
def serialize(object, human=False):
- if human:
- indent = 2
- sort_keys = True
- else:
- indent = None
- sort_keys = False
- return json.JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object)
+ if human:
+ indent = 2
+ sort_keys = True
+ else:
+ indent = None
+ sort_keys = False
+ return json.JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object)
def main():
- parser = argparse.ArgumentParser(description='Gentoostats client')
- parser.add_argument('-s', '--server', default='soc.dev.gentoo.org')
- parser.add_argument('-p', '--port', type = int, default=443)
- parser.add_argument('-u', '--url', default='/gentoostats')
- parser.add_argument('-a', '--auth', default='/etc/gentoostats/auth.cfg')
- parser.add_argument('-c', '--config', default='/etc/gentoostats/payload.cfg')
- args = vars(parser.parse_args())
+ parser = argparse.ArgumentParser(description='Gentoostats client')
+ parser.add_argument('-s', '--server', default='soc.dev.gentoo.org')
+ parser.add_argument('-p', '--port', type = int, default=443)
+ parser.add_argument('-u', '--url', default='/gentoostats')
+ parser.add_argument('-a', '--auth', default='/etc/gentoostats/auth.cfg')
+ parser.add_argument('-c', '--config', default='/etc/gentoostats/payload.cfg')
+ args = vars(parser.parse_args())
- pl = Payload(configfile=args['config'])
- pl.dump(human=True)
+ pl = Payload(configfile=args['config'])
+ pl.dump(human=True)
- post_data = pl.get()
- post_data['AUTH'] = getAuthInfo(auth=args['auth'])
+ post_data = pl.get()
+ post_data['AUTH'] = getAuthInfo(auth=args['auth'])
- post_url = args['url'].strip('/')
- if not len(post_url) == 0:
- post_url = '/' + post_url
- post_url = post_url + '/host/' + post_data['AUTH']['UUID']
+ post_url = args['url'].strip('/')
+ if not len(post_url) == 0:
+ post_url = '/' + post_url
+ post_url = post_url + '/host/' + post_data['AUTH']['UUID']
- post_body = serialize(post_data,human=True)
- post_headers = {'Content-type':'application/json'}
+ 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)
+ 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()
+ #TODO: Handle exceptions
+ response = conn.getresponse()
+ print response.status, response.reason
+ print 'Server response: ' + response.read()
if __name__ == "__main__":
- main()
+ main()