def _search_solr(self, line):
     """Perform a SOLR search.
 """
     try:
         query = 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,
             q=query,
             start=self._session.get(session.START_NAME),
             rows=self._session.get(session.COUNT_NAME))
         cli_util.print_info(self._pretty(object_list.toxml()))
     #
     # SOLR returns HTML instead of XML when there's a problem.  See:
     #   https://issues.apache.org/jira/browse/SOLR-141
     # TODO: Use the exception members instead of parsing string.
     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))
Beispiel #2
0
 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 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 _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. Continue?',
                 default='yes'):
             cli_util.print_info('Cancelled')
     cli_util.copy_file_like_object_to_file(file_like_object, abs_path)
     cli_util.print_info('Created file: {0}'.format(abs_path))
Beispiel #5
0
 def _launch_text_editor(self, path):
     editor = self._get_editor_command()
     cli_util.print_info('Launching editor: {0}'.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.')
Beispiel #6
0
 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('{0} of {1}:'.format(i + 1,
                                                  len(self._operations)))
         self._operation_formatter.print_operation(operation)
     cli_util.print_info('')
Beispiel #7
0
    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 _print_ping_result(self, result, url):
     if result:
         cli_util.print_info('Responded:       {0}'.format(url))
     else:
         cli_util.print_error('Did not respond: {0}'.format(url))
 def _output_to_dislay(self, file_like_object):
     for line in file_like_object:
         cli_util.print_info(line.rstrip())
Beispiel #10
0
 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...')
Beispiel #11
0
 def _print_info_if_verbose(self, msg):
     if self._command_processor.get_session().get(session.VERBOSE_NAME):
         cli_util.print_info(msg)
Beispiel #12
0
 def do_EOF(self, line):
     """Exit on system EOF character"""
     cli_util.print_info('')
     self.do_exit(line)
 def print_operation(self, operation):
     #pprint.pprint(operation)
     for line in self._format_operation(operation, self._template, 0):
         cli_util.print_info(line)
Beispiel #14
0
 def print_single_variable(self, variable):
     self._assert_valid_variable(variable)
     cli_util.print_info(u'{0}: {1}'.format(variable, self.get(variable)))