Пример #1
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))
Пример #2
0
 def _execute_create(self, operation):
     pid = operation['parameters']['identifier']
     path = operation['parameters']['science-file']
     sys_meta = self._create_system_metadata(operation)
     client = cli_client.CLIMNClient(
         **self._mn_client_connect_params_from_operation(operation))
     with open(cli_util.os.path.expanduser(path), 'rb') as f:
         client.create(pid, f, sys_meta)
Пример #3
0
 def _execute_update(self, operation):
     pid_new = operation[u'parameters']['identifier-new']
     pid_old = operation[u'parameters']['identifier-old']
     path = operation[u'parameters']['science-file']
     sys_meta = self._create_system_metadata_for_update(operation)
     client = cli_client.CLIMNClient(
         **self._mn_client_connect_params_from_operation(operation))
     with open(cli_util.os.path.expanduser(path), 'rb') as f:
         client.update(pid_old, f, pid_new, sys_meta)
Пример #4
0
 def log(self, path):
     client = cli_client.CLIMNClient(
         **self._mn_client_connect_params_from_session())
     object_log = client.getLogRecords(
         fromDate=self._session.get(session.FROM_DATE_NAME),
         toDate=self._session.get(session.TO_DATE_NAME),
         start=self._session.get(session.START_NAME),
         count=self._session.get(session.COUNT_NAME))
     object_log_xml = object_log.toxml('utf-8')
     self._output(StringIO.StringIO(self._pretty(object_log_xml)), path)
Пример #5
0
 def list_objects(self, path):
     client = cli_client.CLIMNClient(
         **self._mn_client_connect_params_from_session())
     object_list = client.listObjects(
         fromDate=self._session.get(session.FROM_DATE_NAME),
         toDate=self._session.get(session.TO_DATE_NAME),
         formatId=self._session.get(session.SEARCH_FORMAT_NAME),
         start=self._session.get(session.START_NAME),
         count=self._session.get(session.COUNT_NAME))
     object_list_xml = object_list.toxml('utf-8')
     self._output(StringIO.StringIO(self._pretty(object_list_xml)), path)
Пример #6
0
 def _execute_create_package(self, operation):
     pid_package = operation['parameters']['identifier-package']
     pid_sci_meta = operation['parameters']['identifier-science-meta']
     pid_sci_datas = operation['parameters']['identifier-science-data']
     resource_map = self._generate_resource_map(operation, pid_package,
                                                pid_sci_meta, pid_sci_datas)
     sys_meta = self._create_system_metadata_for_package(
         resource_map, operation)
     client = cli_client.CLIMNClient(
         **self._mn_client_connect_params_from_operation(operation))
     client.create(pid_package, io.StringIO(resource_map), sys_meta)
Пример #7
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)
Пример #8
0
 def _execute_archive(self, operation):
     pid = operation['parameters']['identifier']
     client = cli_client.CLIMNClient(
         **self._mn_client_connect_params_from_operation(operation))
     client.archive(pid)