starting messing the actually making a requests call

This commit is contained in:
Sandy Walsh 2014-06-12 17:40:26 +00:00
parent 4192c1b66f
commit d5c91e5482
5 changed files with 90 additions and 5 deletions

25
klugman/base.py Normal file
View File

@ -0,0 +1,25 @@
# Copyright (c) 2014 Dark Secret Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import requests
def _remove_empty(kv):
"""Remove kv pairs from dictionary where value is empty."""
return dict([(k, v) for k, v in kv.iteritems() if v])
def get(url, cmd, params):
return requests.get("%s/%s" % (url, cmd), params=params)

View File

@ -59,4 +59,5 @@ if __name__ == '__main__':
print "base url:", url
argv = [arguments['<command>']] + arguments['<args>']
impl(url, arguments, argv)
api = impl(url, arguments)
api.dispatch(argv)

View File

@ -32,6 +32,15 @@ from docopt import docopt
class V1(object):
def __init__(self, base_url, base_args, cmdline):
arguments = docopt(__doc__, argv=cmdline)
print arguments
def __init__(self, base_url, base_args):
self.base_url = base_url
self.base_args = base_args
def dispatch(self, cmdline):
self.arguments = docopt(__doc__, argv=cmdline)
print self.arguments
if self.arguments['events']:
response = self.do_events()
# handle cmdline output here.

View File

@ -13,8 +13,56 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""usage:
klugman.py events [options]
klugman.py events (-h | --help)
options:
-i, --id <id>
filter by event ID
-r, --request_id <request_id>
filter by Request ID
-s, --start <start_datetime>
starting datetime range
-e, --end <end_datetime>
ending datetime range
notes:
-r isn't needed if -i is supplied.
"""
import base
from docopt import docopt
class V2(object):
pass
def __init__(self, base_url, base_args):
self.base_url = base_url
self.base_args = base_args
def dispatch(self, cmdline):
self.arguments = docopt(__doc__, argv=cmdline)
print self.arguments
if self.arguments['events']:
response = self.do_events()
# handle cmdline output here.
def do_events(self):
eid = self.arguments.get('--id')
rid = self.arguments.get('--request_id')
start = self.arguments.get('--start')
end = self.arguments.get('--end')
cmd = "/events"
if 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

@ -1 +1,3 @@
docopt
prettytable
requests