def save(self, uuid_name, raw_file):

        if not self._is_valid_uuid(uuid_name):
            raise InvalidParamError("This is not a uuid valid")

        if raw_file is None:
            raise InvalidParamError("Invalid file")

        #Path
        file_path = path.join(self.config.LOCAL_STORAGE_LOCATION,
                              str(uuid_name))
        info("[Storage] Saving file: " + file_path)

        #Saving File
        try:
            f = io.open(file_path, 'wb')
            f.write(raw_file)
            f.close()
        except Exception as e:
            error("[Storage] Error trying read file {0}".format(e))
            return False

        info("[Storage] Saved")

        return True
示例#2
0
def get_param(params, key, key_type, raise_exception=True):
    value = params.get(key)
    if isinstance(value, key_type):
        return value
    if raise_exception:
        raise InvalidParamError('invalid param %s' % key)
    return None
示例#3
0
    def save(self, uuid_name, raw_file):

        if raw_file is None:
            raise InvalidParamError("This is not a data valid")

        if not self._is_valid_uuid(uuid_name):
            raise InvalidParamError("This is not a uuid valid")

        try:
            self.config.S3.put_object(Bucket=self.config.BUCKET_NAME,
                                      Key=uuid_name,
                                      Body=raw_file)
            return True

        except Exception as e:
            error("[StorageAWS] Error trying save file{0}".format(e))
            raise AWSExceptionError("can't save object ")
    def get(self, uuid_name):

        if not self._is_valid_uuid(uuid_name):
            raise InvalidParamError("This is not a UUID value")

        obj = self._read(uuid_name)

        if obj is None:
            raise FileNotFoundError("{0}".format(uuid_name))

        return obj
示例#5
0
    def remove(self, uuid_name):

        if not self._is_valid_config():
            raise InvalidConfigError()

        if not self._is_valid_uuid(uuid_name):
            raise InvalidParamError("This is not a UUID value")

        try:
            self.config.S3.delete_object(Bucket=self.config.BUCKET_NAME,
                                         Key=str(uuid_name))
            return True

        except Exception as e:
            error("[StorageAWS] Error trying remove file{0}".format(e))
            raise AWSExceptionError("can't remove object {0}".format(e))
示例#6
0
    def get(self, uuid_name):

        if not self._is_valid_uuid(uuid_name):
            raise InvalidParamError("This is not a UUID value")

        try:
            response = self.config.S3.get_object(
                Bucket=self.config.BUCKET_NAME, Key=uuid_name)
            return response.get()['Body'].read()

        except ClientError as e:
            if e.response['Error']['Code'] == 'NoSuchKey':
                error("[StorageAWS] Key not found {0}".format(e))
                raise FileNotFoundError(uuid_name)
            else:
                error("[StorageAWS] Error trying read file{0}".format(e))
                raise Exception()
    def remove(self, uuid_name):

        if not self._is_valid_uuid(uuid_name):
            raise InvalidParamError("This is not a UUID value")

        #Path
        file_path = path.join(self.config.LOCAL_STORAGE_LOCATION,
                              str(uuid_name))
        info("[Storage] Removing file: " + file_path)

        #Removing File
        try:
            os.remove(file_path)
        except OSError as e:
            error("[Storage] Error trying remove file {0}".format(e))
            raise FileNotFoundError("{0}".format(file_path))
        except Exception as e:
            error("[Storage] Error trying remove file {0}".format(e))
            raise Exception("Unknown error {0}".format(file_path))

        info("[Storage] Removed")

        return True