예제 #1
0
    def scimeta_add(self, pid, file_name=None, format_id=None, **kwargs):
        """ Add a scimeta object.
        """
        if not pid:
            raise Exception("Missing the pid")
        # if (self.scimeta and not
        #                       cli_util.confirm('Do you wish to delete the existing science metadata object?')):
        #   return
        else:
            self.scimeta = None

        if not file_name:
            new_meta = utils.get_sysmeta_by_pid(pid, True)
            if not new_meta:
                raise Exception("Couldn't find scimeta in DataONE, and there was no file specified.")
            if not self._is_metadata_format(new_meta.formatId):
                raise Exception('"%s" is not an allowable science metadata type.' % new_meta.formatId)
            new_pid = new_meta.identifier.value()
            if new_pid != pid:
                pid = new_pid

            self.scimeta = self._get_by_pid(pid, new_meta)
            authMN = new_meta.authoritativeMemberNode
            if authMN:
                baseURL = utils.get_baseUrl(authMN.value())
                if baseURL:
                    self.scimeta.url = utils.create_get_url_for_pid(baseURL, pid)

        else:
            complex_path = utils.create_complex_path(file_name)
            if not os.path.exists(complex_path.path):
                raise Exception("%s: file not found" % complex_path.path)
            if not format_id:
                format_id = complex_path.formatId
            if not format_id and configuration.check("format"):
                format_id = configuration.format
            if not format_id:
                raise Exception("The object format could not be determined and was not defined.")
            if not self._is_metadata_format(format_id):
                raise Exception('"%s" is not an allowable science metadata type.' % new_meta.formatId)
                return
            #
            sysmeta = utils.create_sysmeta_from_path(pid, complex_path.path, format_id=format_id, **kwargs)
            self.scimeta = DataObject(pid, True, complex_path.path, None, sysmeta, format_id)
        scidata_list = self._find_scidata(self.scimeta)
        if scidata_list:
            for scidata in scidata_list:
                self.scidata_add(scidata.pid, scidata.fname)
예제 #2
0
    def scidata_add(self, pid, file_name=None, format_id=None, **kwargs):
        """ Add a science data object to the list.
        """
        if not pid:
            raise Exception("Missing the pid")

        if file_name:
            # if utils.get_sysmeta_by_pid(pid):
            #   if not cli_util.confirm('That pid (%s) already exists in DataONE.  Continue?' % pid):
            #     return
            #   raise Exception("The identifer (%s) already exists in DataONE." % pid)

            complex_path = utils.create_complex_path(file_name)
            if not format_id:
                format_id = complex_path.formatId
            if not format_id and configuration.check("format"):
                format_id = configuration.format
            if not format_id:
                raise Exception("The object format could not be determined and was not defined.")
            meta = utils.create_sysmeta_from_path(pid, complex_path.path, format_id=format_id, **kwargs)
            self.scidata_dict[pid] = DataObject(pid, True, complex_path.path, None, meta, format_id)

        else:
            sysmeta = utils.get_sysmeta_by_pid(pid, True)
            if not sysmeta:
                raise Exception("The identifier (%s) was not found in DataONE." % pid)
            else:
                pid = sysmeta.identifier.value()
                # if pid in self.scidata_dict:
                #   if not cli_util.confirm('That science data object (%s) is already in the package.  Replace?' % pid):
                #     return
                # Get the scidata object.
                scidata = self._get_by_pid(pid, sysmeta)
                authMN = sysmeta.authoritativeMemberNode
                if authMN:
                    baseURL = utils.get_baseUrl(authMN.value())
                    if baseURL:
                        scidata.url = utils.create_get_url_for_pid(baseURL, pid)
                self.scidata_dict[pid] = scidata