Exemplo n.º 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',
        )
Exemplo n.º 2
0
    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()),))
Exemplo n.º 3
0
    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()),))
Exemplo n.º 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
Exemplo n.º 5
0
Arquivo: updater.py Projeto: 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
Exemplo n.º 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)
Exemplo n.º 7
0
Arquivo: updater.py Projeto: 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)
Exemplo n.º 8
0
 def unique(self):
     hash_func(self.plugins)
Exemplo n.º 9
0
 def id(self):
     return hash_func((
         self.name,
         self.unique(),
     ))