diff options
author | 2011-06-23 20:42:33 +0530 | |
---|---|---|
committer | 2011-06-23 20:42:33 +0530 | |
commit | ee168db7e81a1787630638eea8f1fbe859befd30 (patch) | |
tree | e9617499656e76bcec01b4c85da92be1ff0f8670 | |
parent | update ebuild (diff) | |
download | gentoostats-ee168db7e81a1787630638eea8f1fbe859befd30.tar.gz gentoostats-ee168db7e81a1787630638eea8f1fbe859befd30.tar.bz2 gentoostats-ee168db7e81a1787630638eea8f1fbe859befd30.zip |
add cmdline options to client
-rwxr-xr-x | client/gentoostats-send | 37 | ||||
-rw-r--r-- | client/gentoostats/payload.py | 2 |
2 files changed, 28 insertions, 11 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 diff --git a/client/gentoostats/payload.py b/client/gentoostats/payload.py index 756496c..22f736e 100644 --- a/client/gentoostats/payload.py +++ b/client/gentoostats/payload.py @@ -8,7 +8,7 @@ from gentoostats.metadata import Metadata class Payload(object): - def __init__(self, configfile='/etc/gentoostats/payload.cfg'): + def __init__(self, configfile): self.config = ConfigParser.ConfigParser() if len(self.config.read(configfile)) == 0: sys.stderr.write('Cannot read ' + configfile) |