Example #1
0
    def _generate_hash(cls, filename, options):
        """ Generates an unique hash for the effect. The effect hash is based
        on the filename and the configured options, and is ensured to make the
        effect unique. This is important to make sure the caching works as
        intended. All options not present in options are set to the default value"""

        # Set all options which are not present in the dict to its defaults
        options = {
            k: options.get(k, v)
            for k, v in iteritems(cls._DEFAULT_OPTIONS)
        }

        # Hash filename, make sure it has the right format and also resolve
        # it to an absolute path, to make sure that relative paths are cached
        # correctly (otherwise, specifying a different path to the same file
        # will cause a cache miss)
        filename = Filename(filename)
        filename.make_absolute()
        file_hash = str(hash(filename.to_os_generic()))

        # Hash the options, that is, sort the keys to make sure the values
        # are always in the same order, and then convert the flags to strings using
        # '1' for a set flag, and '0' for a unset flag
        options_hash = "".join([
            "1" if options[key] else "0" for key in sorted(iterkeys(options))
        ])
        return file_hash + "-" + options_hash
Example #2
0
    def generate_hash(cls, filename, options):
        """ Generates an unique hash based on the effect path and options """
        constructed_dict = {}
        for key in sorted(iterkeys(Effect._DEFAULT_OPTIONS)):
            if key in options:
                val = options[key]
            else:
                val = Effect._DEFAULT_OPTIONS[key]
            constructed_dict[key] = val

        # Hash filename, make sure it has the right format before tho
        fname = Filename(filename)
        fname.make_absolute()
        fhash = str(hash(fname.to_os_generic()))

        # Hash the options
        to_str = lambda v: "1" if v else "0"
        opt_hash = ''.join([to_str(options[k]) if k in options else to_str(cls._DEFAULT_OPTIONS[k]) for k in sorted(cls._DEFAULT_OPTIONS)])

        return fhash + "-" + opt_hash
Example #3
0
    def _generate_hash(cls, filename, options):
        """ Generates an unique hash for the effect. The effect hash is based
        on the filename and the configured options, and is ensured to make the
        effect unique. This is important to make sure the caching works as
        intended. All options not present in options are set to the default value"""

        # Set all options which are not present in the dict to its defaults
        options = {k: options.get(k, v) for k, v in iteritems(cls._DEFAULT_OPTIONS)}

        # Hash filename, make sure it has the right format and also resolve
        # it to an absolute path, to make sure that relative paths are cached
        # correctly (otherwise, specifying a different path to the same file
        # will cause a cache miss)
        filename = Filename(filename)
        filename.make_absolute()
        file_hash = str(hash(filename.to_os_generic()))

        # Hash the options, that is, sort the keys to make sure the values
        # are always in the same order, and then convert the flags to strings using
        # '1' for a set flag, and '0' for a unset flag
        options_hash = ''.join(['1' if options[key] else '-' for key in sorted(iterkeys(options))])
        return file_hash + "-" + options_hash