Exemple #1
0
    def set_data(cls, data=None):
        """
        set's an objects data. if there is no hash in the data
        one will be added. the data's hash is returned
        """

        # get our data client
        data_client = DataClient.instance()

        # if the data doesn't have a hash, give it one
        if not data.get("_hash"):
            data["_hash"] = cls._create_hash(data)

        # push the data to storage
        key = cls.storage_key(data.get("_hash"))

        # serialize the data as it goes out the door
        s_data = cls.serialize_data(data)

        cherrypy.log("setting data: %s" % s_data)

        # and set it
        data_client.set(key, s_data)

        return data.get("_hash")
Exemple #2
0
    def get_data(cls, _hash=None, key=None):
        """
        returns a skeleton of the obj data if no hash is passed,
        else returns the data for the obj
        """

        # get our data client
        data_client = DataClient.instance()

        # see if they gave us a key to hash
        if key:
            _hash = cls._hash(key)

        # first, if no hash was sent, return skeleton
        if not _hash:
            return cls.get_skeleton()

        # if they did pass a hash, get the obj's data
        key = cls.storage_key(_hash)

        # grab the data
        data = data_client.get(key)

        cherrypy.log("got data: %s %s" % (key, data))

        # if we didn't get anything return None
        if not data:
            return None

        # deserialize the data off the wire
        data = cls.deserialize_data(data)

        return data
Exemple #3
0
    def set_data(cls, data=None):
        """
        set's an objects data. if there is no hash in the data
        one will be added. the data's hash is returned
        """

        # get our data client
        data_client = DataClient.instance()

        # if the data doesn't have a hash, give it one
        if not data.get('_hash'):
            data['_hash'] = cls._create_hash(data)

        # push the data to storage
        key = cls.storage_key(data.get('_hash'))

        # serialize the data as it goes out the door
        s_data = cls.serialize_data(data)

        cherrypy.log('setting data: %s' % s_data)

        # and set it
        data_client.set(key, s_data)

        return data.get('_hash')
Exemple #4
0
    def get_data(cls, _hash=None, key=None):
        """
        returns a skeleton of the obj data if no hash is passed,
        else returns the data for the obj
        """

        # get our data client
        data_client = DataClient.instance()

        # see if they gave us a key to hash
        if key:
            _hash = cls._hash(key)

        # first, if no hash was sent, return skeleton
        if not _hash:
            return cls.get_skeleton()

        # if they did pass a hash, get the obj's data
        key = cls.storage_key(_hash)

        # grab the data
        data = data_client.get(key)

        cherrypy.log('got data: %s %s' % (key, data))

        # if we didn't get anything return None
        if not data:
            return None

        # deserialize the data off the wire
        data = cls.deserialize_data(data)

        return data
Exemple #5
0
    def delete_data(cls, _hash):
        """
        delete's the objs data
        """

        # get our obj's key
        key = cls.storage_key(_hash)

        # delete that mother
        data_client = DataClient.instance()
        return data_client.delete(key)
Exemple #6
0
    def delete_data(cls, _hash):
        """
        delete's the objs data
        """

        # get our obj's key
        key = cls.storage_key(_hash)

        # delete that mother
        data_client = DataClient.instance()
        return data_client.delete(key)