Exemplo n.º 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: {0}'.format(pid))
Exemplo n.º 2
0
 def _execute_create(self, operation):
     pid = operation[u'parameters']['identifier']
     path = operation[u'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), u'r') as f:
         client.create(pid, f, sys_meta)
Exemplo n.º 3
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()
     self._output(StringIO.StringIO(self._pretty(object_log_xml)), path)
Exemplo n.º 4
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),
         objectFormat=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()
     self._output(StringIO.StringIO(self._pretty(object_list_xml)), path)
Exemplo n.º 5
0
 def _execute_create_package(self, operation):
     pid_package = operation[u'parameters']['identifier-package']
     pid_sci_meta = operation[u'parameters']['identifier-science-meta']
     pid_sci_datas = operation[u'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, StringIO.StringIO(resource_map), sys_meta)
Exemplo 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)
Exemplo n.º 7
0
 def _execute_archive(self, operation):
     pid = operation[u'parameters']['identifier']
     client = cli_client.CLIMNClient(
         **self._mn_client_connect_params_from_operation(operation))
     client.archive(pid)