From 73d7957501834b6c0c118f9c71ffdefee9f9c6b2 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Mon, 5 Mar 2012 16:45:22 -0800 Subject: [PATCH] Add ability to print out json structures returned by api to api.py (This is mostly to make exploration and/or mocking tests easier) --- htsworkflow/util/api.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/htsworkflow/util/api.py b/htsworkflow/util/api.py index 4c4a6e5..6ac2bb2 100644 --- a/htsworkflow/util/api.py +++ b/htsworkflow/util/api.py @@ -47,12 +47,16 @@ def add_auth_options(parser): group.add_option('--sequence', default=sequence_archive, help="sequence repository") parser.add_option_group(group) + return parser -def make_auth_from_opts(opts, parser): +def make_auth_from_opts(opts, parser=None): """Create htsw auth info dictionary from optparse info """ if opts.host is None or opts.apiid is None or opts.apikey is None: - parser.error("Please specify host url, apiid, apikey") + if parser is not None: + parser.error("Please specify host url, apiid, apikey") + else: + raise RuntimeError("Need host, api id api key") return {'apiid': opts.apiid, 'apikey': opts.apikey } @@ -158,3 +162,21 @@ class HtswApi(object): def get_url(self, url): return retrieve_info(url, self.authdata) +if __name__ == "__main__": + from optparse import OptionParser + from pprint import pprint + parser = OptionParser() + parser = add_auth_options(parser) + parser.add_option('--flowcell', default=None) + parser.add_option('--library', default=None) + + opts, args = parser.parse_args() + apidata = make_auth_from_opts(opts) + + api = HtswApi(opts.host, apidata) + + if opts.flowcell is not None: + pprint(api.get_flowcell(opts.flowcell)) + if opts.library is not None: + pprint(api.get_library(opts.library)) + -- 2.30.2