def build_transaction(cls, songs):
            """:param songs: a list of dictionary representations of songs."""

            #Warn about metadata changes that may cause problems.
            #If you change the interface in api, you can warn about changing bad categories, too.
            #Something like safelychange(song, entries) where entries are only those you want to change.

            for song in songs:
                for key in song:
                    allowed_values = Metadata_Expectations.get_expectation(
                        key).allowed_values
                    if allowed_values and song[key] not in allowed_values:
                        LogController.get_logger("modifyentries").warning(
                            "setting key {0} to unallowed value {1} for id {2}. Check metadata expectations in protocol.py"
                            .format(key, song[key], song["id"]))

            req = {"entries": songs}

            res = {
                "type": "object",
                "properties": {
                    "success": {
                        "type": "boolean"
                    },
                    "songs": WC_Protocol.song_array
                },
                "additionalProperties": False
            }
            return (req, res)
        def build_transaction(cls, songs):
            """:param songs: a list of dictionary representations of songs."""

            #Warn about metadata changes that may cause problems.
            #If you change the interface in api, you can warn about changing bad categories, too.
            #Something like safelychange(song, entries) where entries are only those you want to change.

            for song in songs:
                for key in song:
                    allowed_values = Metadata_Expectations.get_expectation(key).allowed_values
                    if allowed_values and song[key] not in allowed_values:
                        LogController.get_logger("modifyentries").warning(
                            "setting key %s to unallowed value %s for id "
                            "%s. Check metadata expectations in "
                            "protocol.py" % (key, song[key], song["id"]))


            req = {"entries": songs}

            res = {"type": "object",
                   "properties":{
                       "success": {"type":"boolean"},
                       "songs":WC_Protocol.song_array
                       },
                   "additionalProperties":False
                   }
            return (req, res)
Exemple #3
0
    def get_expectation(cls, key, warn_on_unknown=True):
        """Get the Expectation associated with the given key name.
        If no Expectation exists for that name, an immutable Expectation of any type is returned."""

        mangle = False
        if not hasattr(cls,key):
            mangle = True

        expt_name = "gm_" + key if mangle else key

        try:
            expt = getattr(cls,expt_name)
            if not issubclass(expt, _Metadata_Expectation):
                raise TypeError
            return expt
        except (AttributeError, TypeError):
            if warn_on_unknown: LogController.get_logger("get_expectation").warning("unknown metadata type '%s'", key)

            return UnknownExpectation