Exemple #1
0
    def create(self, file_data, file_path):
        """
        Create a new asset and return its file_path
        If it already exists,
        return the file_path for the existing asset
        (don't create it again)
        """

        try:
            # Create object
            self.swift_connection.put_object(
                self.container_name,
                normalize(file_path),
                file_data
            )
        except SwiftException as swift_error:
            if swift_error.http_status == 404:
                # Not found, assuming container doesn't exist
                self.swift_connection.put_container(self.container_name)

                # And try to create again
                self.swift_connection.put_object(
                    self.container_name,
                    normalize(file_path),
                    file_data
                )
            else:
                # Otherwise, throw the exception again
                raise swift_error
Exemple #2
0
    def update(self, file_path, tags, data={}):
        search = {"file_path": normalize(file_path)}

        data.update({"file_path": normalize(file_path), "tags": tags})

        self.data_collection.update(search, data, True)

        return self.fetch_one(file_path)
Exemple #3
0
 def delete(self, file_path):
     if self.exists(file_path):
         self.swift_connection.delete_object(
             self.container_name,
             normalize(file_path)
         )
         return True
Exemple #4
0
    def fetch(self, file_path):
        asset_data = None

        asset = self.swift_connection.get_object(self.container_name,
                                                 normalize(file_path))
        asset_data = asset[1]

        return asset_data
Exemple #5
0
    def exists(self, file_path):
        file_exists = True

        try:
            self.swift_connection.head_object(self.container_name,
                                              normalize(file_path))
        except SwiftException as error:
            if error.http_status == 404:
                file_exists = False

        return file_exists
Exemple #6
0
 def headers(self, file_path):
     return self.swift_connection.head_object(
         self.container_name,
         normalize(file_path)
     )
Exemple #7
0
    def fetch_one(self, file_path):
        asset_data = self.data_collection.find_one(
            {"file_path": normalize(file_path)}
        )

        return self.format(asset_data) if asset_data else None