Ejemplo n.º 1
0
 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))
Ejemplo n.º 2
0
    def science_object_get(self, pid, path):
        """First try the MN set in the session. Then try to resolve via the CN set
    in the session."""
        mn_client = cli_client.CLIMNClient(
            **self._mn_client_connect_params_from_session())
        try:
            response = mn_client.get(pid)
        except d1_common.types.exceptions.DataONEException:
            pass
        else:
            self._output(response, path)
            return

        cn_client = cli_client.CLICNClient(
            **self._cn_client_connect_params_from_session())
        object_location_list = cn_client.resolve(pid)
        for location in object_location_list.objectLocation:
            try:
                params = self._mn_client_connect_params_from_session()
                params['base_url'] = location.baseURL
                mn_client = cli_client.CLIMNClient(**params)
                response = mn_client.get(pid)
            except d1_common.types.exceptions.DataONEException:
                pass
            else:
                self._output(response, path)
                return

        raise cli_exceptions.CLIError(u'Could not find object: {}'.format(pid))
Ejemplo n.º 3
0
 def _execute_update_access_policy(self, operation):
     pid = operation['parameters']['identifier']
     policy = self._create_access_policy(operation)
     client = cli_client.CLICNClient(
         **self._cn_client_connect_params_from_operation(operation))
     sys_meta = client.getSystemMetadata(pid)
     client.setAccessPolicy(pid, policy, sys_meta.serialVersion)
Ejemplo n.º 4
0
 def _update_node_cache(self, cn_base_url):
   client = cli_client.CLICNClient(base_url=cn_base_url)
   nodes = client.listNodes()
   node_brief = sorted(
     [(node.type, node.name, node.baseURL) for node in nodes.node]
   )
   self._nodes = node_brief
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def system_metadata_get(self, pid, path):
     metadata = None
     try:
         client = cli_client.CLICNClient(
             **self._cn_client_connect_params_from_session())
         metadata = client.getSystemMetadata(pid)
     except d1_common.types.exceptions.DataONEException:
         pass
     if metadata is None:
         try:
             client = cli_client.CLIMNClient(
                 **self._mn_client_connect_params_from_session())
             metadata = client.getSystemMetadata(pid)
         except d1_common.types.exceptions.DataONEException:
             pass
     if metadata is None:
         raise
     self._system_metadata_print(metadata, path)
Ejemplo n.º 7
0
 def _update_format_id_cache(self, cn_base_url):
   client = cli_client.CLICNClient(base_url=cn_base_url)
   formats = client.listFormats()
   format_ids = sorted([f.formatId for f in formats.objectFormat])
   self._format_ids = format_ids