diff options
author | 2011-07-25 18:05:20 +0530 | |
---|---|---|
committer | 2011-07-25 18:05:20 +0530 | |
commit | bce6d47cdd40c24d26b8241a882263c602b166df (patch) | |
tree | be1e8577078199c637ccab475dbe408e8d2d1460 | |
parent | export json from server (diff) | |
download | gentoostats-bce6d47cdd40c24d26b8241a882263c602b166df.tar.gz gentoostats-bce6d47cdd40c24d26b8241a882263c602b166df.tar.bz2 gentoostats-bce6d47cdd40c24d26b8241a882263c602b166df.zip |
gentoostats-cli first commit
-rwxr-xr-x | client/gentoostats-cli | 28 | ||||
-rw-r--r-- | client/gentoostats/list.py | 97 |
2 files changed, 125 insertions, 0 deletions
diff --git a/client/gentoostats-cli b/client/gentoostats-cli new file mode 100755 index 0000000..cee0da1 --- /dev/null +++ b/client/gentoostats-cli @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import sys +import importlib + +actions = {'list':'gentoostats.list', 'search':'gentooostats.search'} + +def print_usage(): + print 'Usage:', sys.argv[0], '<action>' + print 'Available actions:' + for action in actions.keys(): + print action + +def main(): + argc = len(sys.argv) + if argc == 1: + print_usage() + sys.exit(1) + try: + loaded_module = importlib.import_module(actions[sys.argv[1]]) + loaded_module.main(opts=sys.argv[2:]) + except KeyError, ImportError: + sys.stderr.writelines('Unknown action') + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/client/gentoostats/list.py b/client/gentoostats/list.py new file mode 100644 index 0000000..480587c --- /dev/null +++ b/client/gentoostats/list.py @@ -0,0 +1,97 @@ + +import sys +import json +import httplib + +objects={ +'arch':'list_arch', +'feature':'list_feature', +'lang':'list_lang', +'mirror':'list_mirror', +'repo':'list_repo', +'category':'list_cat', +} + +server = 'soc.dev.gentoo.org' +url = '/gentoostats' +headers = {'Accept':'application/json'} + +def print_usage(): + print 'Usage: list <object>' + print 'Available objects:' + for obj in objects.keys(): + print obj + +def pprint(object): + import pprint + pprint.pprint(object) + +def main(opts): + l = len(opts) + if l == 0: + print_usage() + sys.exit(1) + + if opts[0] not in objects: + sys.stderr.write('Unknown object') + sys.exit(1) + + try: + globals()[objects[opts[0]]]() + except KeyError: + sys.stderr.write('Unimplemented') + sys.exit(1) + +def list_arch(): + conn = httplib.HTTPSConnection(server) + conn.request('GET', url=url+'/arch', headers=headers) + try: + arch_data = json.JSONDecoder().decode(conn.getresponse().read()) + except ValueError: + sys.exit(1) + pprint(arch_data) + +def list_feature(): + conn = httplib.HTTPSConnection(server) + conn.request('GET', url=url+'/feature', headers=headers) + try: + feature_data = json.JSONDecoder().decode(conn.getresponse().read()) + except ValueError: + sys.exit(1) + pprint(feature_data) + +def list_lang(): + conn = httplib.HTTPSConnection(server) + conn.request('GET', url=url+'/lang', headers=headers) + try: + lang_data = json.JSONDecoder().decode(conn.getresponse().read()) + except ValueError: + sys.exit(1) + pprint(lang_data) + +def list_mirror(): + conn = httplib.HTTPSConnection(server) + conn.request('GET', url=url+'/mirror', headers=headers) + try: + mirror_data = json.JSONDecoder().decode(conn.getresponse().read()) + except ValueError: + sys.exit(1) + pprint(mirror_data) + +def list_repo(): + conn = httplib.HTTPSConnection(server) + conn.request('GET', url=url+'/mirror', headers=headers) + try: + repo_data = json.JSONDecoder().decode(conn.getresponse().read()) + except ValueError: + sys.exit(1) + pprint(repo_data) + +def list_cat(): + conn = httplib.HTTPSConnection(server) + conn.request('GET', url=url+'/package', headers=headers) + try: + cat_data = json.JSONDecoder().decode(conn.getresponse().read()) + except ValueError: + sys.exit(1) + pprint(cat_data) |