def lookup(argv): """CLI command to run the various search types""" opt_parser = RoseOptionParser().add_my_options( "address_mode", "all_revs", "lookup_mode", "no_headers", "prefixes", "print_format", "query_mode", "reverse", "search_mode", "sort") opts, args = opt_parser.parse_args(argv) if not args: sys.exit(opt_parser.print_usage()) if not opts.lookup_mode: if args[0].startswith("http"): opts.lookup_mode = "address" else: opts.lookup_mode = "search" ws_client = RosieWSClient( prefixes=opts.prefixes, event_handler=Reporter(opts.verbosity - opts.quietness)) try: if opts.lookup_mode == "address": data_and_url_list = ws_client.address_lookup(url=args[0]) elif opts.lookup_mode == "query": q_items = ws_client.query_split(args) for i, q_item in enumerate(q_items): q_items[i] = " ".join(q_item) data_and_url_list = ws_client.query( q_items, all_revs=int(opts.all_revs)) else: # if opts.lookup_mode == "search": data_and_url_list = ws_client.search( args, all_revs=int(opts.all_revs)) except RosieWSClientError as exc: if opts.debug_mode: traceback.print_exc(exc) sys.exit(str(exc)) for data, url in data_and_url_list: _display_maps(opts, ws_client, data, url)
class SearchManager(): """Wrapper class for running searches.""" def __init__(self, prefix): self.ws_client = RosieWSClient(prefix=prefix) def address_lookup(self, **items): """Return search results for a url lookup.""" return self.ws_client.address_search(None, **items) def get_datasource(self): """Return the current datasource prefix.""" return self.ws_client.prefix def set_datasource(self, prefix): """Set the datasource.""" self.ws_client = RosieWSClient(prefix=prefix) def ws_query(self, filters, **items): """Return search results for a query.""" return self.ws_client.query(filters, **items) def ws_search(self, search, **items): """Return search results for a keyword search""" return self.ws_client.search(search, **items)
def hello(argv): """Set up connection to a Rosie web service.""" opt_parser = RoseOptionParser().add_my_options("prefixes") opts = opt_parser.parse_args(argv)[0] report = Reporter(opts.verbosity - opts.quietness) ws_client = RosieWSClient(prefixes=opts.prefixes, event_handler=report) for response_data, response_url in ws_client.hello(): report("%s: %s" % (response_url, response_data), level=0)
def list_local_suites(argv): """CLI command to list all the locally checked out suites""" opt_parser = RoseOptionParser().add_my_options( "no_headers", "prefixes", "print_format", "reverse", "sort", "user") opts = opt_parser.parse_args(argv)[0] report = Reporter(opts.verbosity - opts.quietness) if opts.user: alternative_roses_dir = SuiteId.get_local_copy_root(opts.user) report(UserSpecificRoses(alternative_roses_dir), prefix=None) ws_client = RosieWSClient(prefixes=opts.prefixes, event_handler=report) _display_maps(opts, ws_client, ws_client.query_local_copies(opts.user))
def list_local_suites(argv): """CLI command to list all the locally checked out suites""" opt_parser = RoseOptionParser().add_my_options("no_headers", "prefixes", "print_format", "reverse", "sort", "user") opts = opt_parser.parse_args(argv)[0] report = Reporter(opts.verbosity - opts.quietness) if opts.user: alternative_roses_dir = SuiteId.get_local_copy_root(opts.user) report(UserSpecificRoses(alternative_roses_dir), prefix=None) ws_client = RosieWSClient(prefixes=opts.prefixes, event_handler=report) _display_maps(opts, ws_client, ws_client.query_local_copies(opts.user))
def set_datasource(self, prefix): """Set the datasource.""" self.ws_client = RosieWSClient(prefix=prefix)
def __init__(self, prefix): self.ws_client = RosieWSClient(prefix=prefix)