def do_history(self, line): """history Display a list of commands that have been entered """ self._split_args(line, 0, 0) for idx, item in enumerate(self._history): cli_util.print_info(u'{0: 3d} {1}'.format(idx, item))
def _search_solr(self, line): """Perform a SOLR search. """ try: query_str = self._create_solr_query(line) client = cli_client.CLICNClient( **self._cn_client_connect_params_from_session()) object_list = client.search( queryType=d1_common.const.DEFAULT_SEARCH_ENGINE, query=query_str, start=self._session.get(session.START_NAME), rows=self._session.get(session.COUNT_NAME), ) cli_util.print_info(self._pretty(object_list.toxml('utf-8'))) except d1_common.types.exceptions.ServiceFailure as e: e = "%".join(str(e).splitlines()) # Flatten line regexp = re.compile( r"errorCode: (?P<error_code>\d+)%.*%Status code: (?P<status_code>\d+)" ) result = regexp.search(e) if ((result is not None) and (result.group(u'error_code') == '500') and (result.group(u'status_code') == '400')): # noqa: E129 result = re.search( r"<b>description</b> <u>(?P<description>[^<]+)</u>", e) msg = re.sub( u'&([^;]+);', lambda m: unichr(htmlentitydefs. name2codepoint[m.group(1)]), result.group(u'description')) cli_util.print_info(u'Warning: %s' % msg) else: cli_util.print_error(u'Unexpected error:\n%s' % str(e))
def resolve(self, pid): """Get Object Locations for Object. """ client = cli_client.CLICNClient( **self._cn_client_connect_params_from_session()) object_location_list = client.resolve(pid) for location in object_location_list.objectLocation: cli_util.print_info(location.url)
def test_1180(self): """print()""" with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): msg = 'test_msg' cli_util.print_debug(msg) cli_util.print_error(msg) cli_util.print_warn(msg) cli_util.print_info(msg) self.sample.assert_equals(out_stream.getvalue(), 'print')
def _launch_text_editor(self, path): editor = self._get_editor_command() cli_util.print_info('Launching editor: {}'.format(editor)) try: subprocess.call([editor, path]) except OSError: cli_util.print_error( 'Unable to launch editor. Please set the editor session variable\n' 'or the EDITOR environment variable to the filename of a valid editor\n' 'executable on your system.')
def test_1180(self): """print()""" with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): msg = 'test_msg' cli_util.print_debug(msg) cli_util.print_error(msg) cli_util.print_warn(msg) cli_util.print_info(msg) assert 'DEBUG test_msg\n' \ 'ERROR test_msg\n' \ 'WARN test_msg\n' \ ' test_msg\n' == \ out_stream.getvalue()
def _output_to_file(self, file_like_object, path): abs_path = cli_util.os.path.expanduser(path) if os.path.exists(abs_path): if not cli_util.confirm( 'You are about to overwrite an existing file at "{}". Continue? ' .format(abs_path), default='yes'): cli_util.print_info('Cancelled') if isinstance(file_like_object, requests.Response): cli_util.copy_requests_stream_to_file(file_like_object, path) else: cli_util.copy_file_like_object_to_file(file_like_object, abs_path) cli_util.print_info('Created file: {}'.format(abs_path))
def _print_operation_queue(self): self._assert_queue_not_empty() self._update_comments(self._operations) cli_util.print_info('Operation queue:') for i, operation in enumerate(self._operations): cli_util.print_info('') cli_util.print_info('{} of {}:'.format(i + 1, len(self._operations))) self._operation_formatter.print_operation(operation) cli_util.print_info('')
def _print_help(self): """Custom help message to group commands by functionality""" msg = """Commands (type help <command> for details) CLI: help history exit quit Session, General: set load save reset Session, Access Control: allowaccess denyaccess clearaccess Session, Replication: allowrep denyrep preferrep blockrep removerep numberrep clearrep Read Operations: get meta list log resolve Write Operations: update create package archive updateaccess updatereplication Utilities: listformats listnodes search ping Write Operation Queue: queue run edit clearqueue Command History: Arrow Up, Arrow Down Command Editing: Arrow Left, Arrow Right, Delete """ if platform.system() != 'Windows': msg += """Command Completion: Single Tab: Complete unique command Double Tab: Display possible commands """ cli_util.print_info(msg)
def postloop(self): """Take care of any unfinished business. Despite the claims in the Cmd documentaion, Cmd.postloop() is not a stub. """ cmd.Cmd.postloop(self) # Clean up command completion cli_util.print_info(u'Exiting...')
def _print_info_if_verbose(self, msg): if self._command_processor.get_session().get(session.VERBOSE_NAME): cli_util.print_info(msg)
def do_eof(self, line): """Exit on system EOF character""" cli_util.print_info('') self.do_exit(line)
def print_single_variable(self, variable): self._assert_valid_variable(variable) cli_util.print_info('{}: {}'.format(variable, self.get(variable)))
def print_operation(self, operation): #pprint.pprint(operation) for line in self._format_operation(operation, self._template, 0): cli_util.print_info(line)
def _print_ping_result(self, result, url): if result: cli_util.print_info('Responded: {}'.format(url)) else: cli_util.print_error('Did not respond: {}'.format(url))
def _output_to_display(self, file_like_object): for line in file_like_object: cli_util.print_info(line.rstrip())