diff options
author | Vikraman Choudhury <vikraman.choudhury@gmail.com> | 2011-06-23 20:42:33 +0530 |
---|---|---|
committer | Vikraman Choudhury <vikraman.choudhury@gmail.com> | 2011-06-23 20:42:33 +0530 |
commit | ee168db7e81a1787630638eea8f1fbe859befd30 (patch) | |
tree | e9617499656e76bcec01b4c85da92be1ff0f8670 /client/gentoostats-send | |
parent | update ebuild (diff) | |
download | gentoostats-ee168db7e81a1787630638eea8f1fbe859befd30.tar.gz gentoostats-ee168db7e81a1787630638eea8f1fbe859befd30.tar.bz2 gentoostats-ee168db7e81a1787630638eea8f1fbe859befd30.zip |
add cmdline options to client
Diffstat (limited to 'client/gentoostats-send')
-rwxr-xr-x | client/gentoostats-send | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/client/gentoostats-send b/client/gentoostats-send index b118e94..ecc0be8 100755 --- a/client/gentoostats-send +++ b/client/gentoostats-send @@ -1,15 +1,16 @@ #!/usr/bin/env python -from gentoostats.payload import Payload -import ConfigParser import sys import json +import argparse +import ConfigParser import urllib, httplib +from gentoostats.payload import Payload -def getAuthInfo(auth='/etc/gentoostats/auth.cfg'): +def getAuthInfo(auth): config = ConfigParser.ConfigParser() if len(config.read(auth)) == 0: - sys.stderr.write('Cannot read '+auth) + sys.stderr.write('Cannot read ' + auth) sys.exit(1) try: @@ -31,15 +32,31 @@ def serialize(object, human=False): return json.JSONEncoder(indent=indent, sort_keys=sort_keys).encode(object) def main(): - pl = Payload() + parser = argparse.ArgumentParser(description='Gentoostats client') + parser.add_argument('-s', '--server', default='soc.dev.gentoo.org') + parser.add_argument('-p', '--port', type = int, default=80) + 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) + post_data = pl.get() - post_data['AUTH'] = getAuthInfo() + 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_body = serialize(post_data,human=True) - post_headers = {"Content-type": "application/json"} - myuuid = getAuthInfo()['UUID'] - conn = httplib.HTTPConnection("127.0.0.1:8080") - conn.request('POST', '/host/' + myuuid, headers=post_headers, body=post_body) + post_headers = {'Content-type':'application/json'} + + conn = httplib.HTTPConnection(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 |