コード例 #1
0
    def __init__(self, assets: Environment):
        themes_config_filename = './config/themes.json'
        if not path.isfile(themes_config_filename):
            shutil.copyfile('./config/themes.example.json',
                            themes_config_filename)

        with open(themes_config_filename, 'r') as fp:
            self.config = json.load(fp)
        assets.app.jinja_env.globals.update(themes=self.config)

        self.assets = assets
        self.hash = hash_func(self.config)

        for theme in self.config:
            if 'paths' in theme:
                self.assets.register(
                    'theme_' + theme['id'],
                    *theme['paths'],
                    filters='csscomp',
                    output='gen/themes/' + theme['id'] + '.%(version)s.css',
                )

        self.assets.register(
            'themes.js',
            ['static/js/themes.js'],
            filters=(
                CacheableJinja2Filter(self, assets.app.jinja_env),
                'babili',
            ),
            output='gen/themes.%(version)s.js',
        )
コード例 #2
0
ファイル: __init__.py プロジェクト: marcellarius/webassets
    def id(self):
        """Unique identifier for the filter instance.

        Among other things, this is used as part of the caching key.
        It should therefore not depend on instance data, but yield
        the same result across multiple python invocations.
        """
        # freezedicts() allows filters to return dict objects as part
        # of unique(), which are not per-se supported by hash().
        return hash_func((self.name, freezedicts(self.unique()),))
コード例 #3
0
ファイル: __init__.py プロジェクト: ltvolks/webassets
    def id(self):
        """Unique identifier for the filter instance.

        Among other things, this is used as part of the caching key.
        It should therefore not depend on instance data, but yield
        the same result across multiple python invocations.
        """
        # freezedicts() allows filters to return dict objects as part
        # of unique(), which are not per-se supported by hash().
        return hash_func((self.name, freezedicts(self.unique()),))
コード例 #4
0
    def check_bundle_definition(self, bundle, ctx):
        if not ctx.cache:
            # If no global cache is configured, we could always
            # fall back to a memory-cache specific for the rebuild
            # process (store as env._update_cache); however,
            # whenever a bundle definition changes, it's likely that
            # a process restart will be required also, so in most cases
            # this would make no sense.
            return False

        cache_key = ('bdef', bundle.output)
        current_hash = "%s" % hash_func(bundle)
        cached_hash = ctx.cache.get(cache_key)
        # This may seem counter-intuitive, but if no cache entry is found
        # then we actually return "no update needed". This is because
        # otherwise if no cache / a dummy cache is used, then we would be
        # rebuilding every single time.
        if not cached_hash is None:
            return cached_hash != current_hash
        return False
コード例 #5
0
ファイル: updater.py プロジェクト: Alpus/Eth
    def check_bundle_definition(self, bundle, ctx):
        if not ctx.cache:
            # If no global cache is configured, we could always
            # fall back to a memory-cache specific for the rebuild
            # process (store as env._update_cache); however,
            # whenever a bundle definition changes, it's likely that
            # a process restart will be required also, so in most cases
            # this would make no sense.
            return False

        cache_key = ('bdef', bundle.output)
        current_hash = "%s" % hash_func(bundle)
        cached_hash = ctx.cache.get(cache_key)
        # This may seem counter-intuitive, but if no cache entry is found
        # then we actually return "no update needed". This is because
        # otherwise if no cache / a dummy cache is used, then we would be
        # rebuilding every single time.
        if not cached_hash is None:
            return cached_hash != current_hash
        return False
コード例 #6
0
 def build_done(self, bundle, ctx):
     if not ctx.cache:
         return False
     cache_key = ('bdef', bundle.output)
     cache_value = "%s" % hash_func(bundle)
     ctx.cache.set(cache_key, cache_value)
コード例 #7
0
ファイル: updater.py プロジェクト: Alpus/Eth
 def build_done(self, bundle, ctx):
     if not ctx.cache:
         return False
     cache_key = ('bdef', bundle.output)
     cache_value = "%s" % hash_func(bundle)
     ctx.cache.set(cache_key, cache_value)
コード例 #8
0
 def unique(self):
     hash_func(self.plugins)
コード例 #9
0
 def id(self):
     return hash_func((
         self.name,
         self.unique(),
     ))