Esempio 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',
        )
Esempio 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()),))
Esempio 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()),))
Esempio 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
Esempio n. 5
0
File: updater.py Progetto: 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
Esempio 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)
Esempio n. 7
0
File: updater.py Progetto: 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)
 def unique(self):
     hash_func(self.plugins)
Esempio n. 9
0
 def id(self):
     return hash_func((
         self.name,
         self.unique(),
     ))