def main(): """Launcher for the CLI.""" opt_parser = RoseOptionParser() opt_parser.add_my_options('name') opts, args = opt_parser.parse_args(sys.argv[1:]) event_handler = Reporter(opts.verbosity - opts.quietness) suite_vc_cmp = SuiteVCComparator(event_handler) suite_name = opts.name if not suite_name and args: suite_name = args[0] if not suite_name: suite_name = os.getenv(suite_vc_cmp.suite_engine_proc.SUITE_NAME_ENV) if not suite_name: opt_parser.print_usage(sys.stderr) sys.exit(2) try: lines = suite_vc_cmp.cmp_source_vc_info(suite_name=suite_name) except Exception as exc: event_handler(exc) traceback.print_exc() sys.exit(2) else: if lines is None: event_handler( '%s: rose-suite-run.version: VC info not found' % ( suite_name), kind=Reporter.KIND_ERR, level=Reporter.FAIL) sys.exit(2) lines = list(line for line in lines) for line in lines: event_handler('%s\n' % line, prefix='') if lines: sys.exit(1) else: sys.exit(0)
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() sys.exit(str(exc)) for data, url in data_and_url_list: _display_maps(opts, ws_client, data, url)
def lookup(): """CLI command to run the various search types""" opt_parser = RoseOptionParser( usage='rosie lookup [OPTIONS] LOOKUP-TEXT ...', description=''' Find suites in the suite discovery database. Search for suites using an address, a query or search words and display the information of the matching suites. Unless an option is used to specify the initial search type the argument is interpreted as follows: * A string beginning with "http": an address * A string not beginning with "http": search words An address URL may contain shell meta characters, so remember to put it in quotes. The default output format includes a local working copy status field (`%local`) in the first column. * A blank field means there is no related suite checked out. * `=` means that the suite is checked out at this branch and revision. * `<` means that the suite is checked out but at an older revision. * `>` means that the suite is checked out but at a newer revision. * `S` means that the suite is checked out but on a different branch. * `M` means that the suite is checked out and modified. * `X` means that the suite is checked out but is corrupted. Search strings may contain SQL wildcard characters. E.g: * `%` (percent) is a substitute for zero or more characters. * `_` (underscore) is a substitute for a single character. ''', ).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() 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() sys.exit(str(exc)) for data, url in data_and_url_list: _display_maps(opts, ws_client, data, url)