basics working

This commit is contained in:
Sandy Walsh 2014-06-12 19:06:33 +00:00
parent d5c91e5482
commit 5b4fe36c9c
5 changed files with 21 additions and 13 deletions

0
klugman/__init__.py Normal file
View File

View File

@ -22,4 +22,5 @@ def _remove_empty(kv):
def get(url, cmd, params):
return requests.get("%s/%s" % (url, cmd), params=params)
final = "%s/%s" % (url, cmd)
return requests.get(final, params=params)

View File

@ -22,10 +22,11 @@ Usage:
Options:
-h --help Show this help message
--version Show klugman version.
--version Show klugman version
--debug Debug mode
-a, --api_version <api_version>
Which API version to use [default: latest]
--url <url> StackTach.v3 server url [default: http://localhost]
--url <url> StackTach.v3 server url [default: http://localhost:8000]
For a list of possible StackTach commands, use:
klugman help [<command>]
@ -42,11 +43,10 @@ versions = {1: v1.V1, 2: v2.V2}
latest = 2
if __name__ == '__main__':
def main():
arguments = docopt(__doc__, options_first=True)
print "----base----"
print arguments
print "----impl----"
if arguments['--debug']:
print arguments
version = arguments["--api_version"]
if version == "latest":
@ -55,9 +55,12 @@ if __name__ == '__main__':
version = int(version)
impl = versions[version]
url = "%s/v%d/" % (arguments["--url"], version)
print "base url:", url
url = "%s/v%d" % (arguments["--url"], version)
argv = [arguments['<command>']] + arguments['<args>']
api = impl(url, arguments)
api.dispatch(argv)
if __name__ == '__main__':
main()

View File

@ -45,11 +45,13 @@ class V2(object):
def dispatch(self, cmdline):
self.arguments = docopt(__doc__, argv=cmdline)
print self.arguments
if self.base_args['--debug']:
print self.arguments
if self.arguments['events']:
response = self.do_events()
# handle cmdline output here.
print response.json()
def do_events(self):
eid = self.arguments.get('--id')
@ -57,12 +59,11 @@ class V2(object):
start = self.arguments.get('--start')
end = self.arguments.get('--end')
cmd = "/events"
cmd = "events"
if eid:
cmd = "/events/%d" % eid
cmd = "events/%d" % eid
params = base._remove_empty({'request_id': rid,
'start_ts': start,
'end_ts': end})
print "Params:", params
return base.get(self.base_url, cmd, params)

View File

@ -27,3 +27,6 @@ keywords =
[files]
packages =
klugman
[entry_points]
console_scripts =
klugman = klugman.klugman:main