commit f3b5cb77a0807bcdc927d6e90a277bad7654533d Author: relikd Date: Sun Nov 24 20:10:12 2019 +0100 Initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..463960b --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +dist +build +*.pyc +*.pyo +*.egg-info diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..07c1f87 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2019 Oleg Geier + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0965648 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# Force Update + +Update resources regardless of changed state. +Usefull for, e.g., `.appcache` files. + + +## Configuration file + +### `configs/force-update.ini` + + enabled = yes + endswiths = .appcache, .webmanifest, ... + +Where `endswiths` is a list of patterns (e.g., file extensions) of files that need a forced update. \ No newline at end of file diff --git a/lektor_force_update.py b/lektor_force_update.py new file mode 100644 index 0000000..89e4b01 --- /dev/null +++ b/lektor_force_update.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +from lektor.pluginsystem import Plugin +from lektor.assets import File +from lektor.db import Page +from lektor.utils import bool_from_string as asBool +from lektor.reporter import reporter + + +class ForceUpdatePlugin(Plugin): + name = u'Force Update' + description = u'Update files regardless of changed state' + msg_init_config = '''Plugin not properly configured. + +configs/force-update.ini: + enabled = yes + endswith = .appcache, .webmanifest, ... +''' + patterns = list() + + def matchesPattern(self, source): + if isinstance(source, Page): + path = source.path + elif isinstance(source, File): + path = source.source_filename + else: + return False + return any(path.endswith(x) for x in self.patterns) + + def on_after_build(self, builder, build_state, source, prog): + if self.enabled and self.matchesPattern(source): + for artifact in prog.artifacts: + artifact.set_dirty_flag() + + def on_setup_env(self): + prefs = self.get_config() + endswith = prefs.get('endswith') + if endswith is None: + raise RuntimeError(self.msg_init_config) + + self.enabled = asBool(prefs.get('enabled'), default=True) + if self.enabled: + for pattern in endswith.split(','): + self.patterns.append(pattern.strip()) + if len(self.patterns) == 0: + self.enabled = False + + readable = 'ENABLED' if self.enabled else 'DISABLED' + reporter.report_generic('Plugin ' + readable + ': force-update') diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..2dcb7c9 --- /dev/null +++ b/setup.py @@ -0,0 +1,38 @@ +import ast +import io +import re + +from setuptools import setup, find_packages + +with io.open('README.md', 'rt', encoding="utf8") as f: + readme = f.read() + +_description_re = re.compile(r'description\s+=\s+(?P.*)') + +with open('lektor_force_update.py', 'rb') as f: + description = str(ast.literal_eval(_description_re.search( + f.read().decode('utf-8')).group(1))) + +setup( + author=u'relikd', + author_email='oleg@relikd.de', + description=description, + keywords='Lektor plugin force cache appcache rebuild build', + license='MIT', + long_description=readme, + long_description_content_type='text/markdown', + name='lektor-force-update', + packages=find_packages(), + py_modules=['lektor_force_update'], + url='https://github.com/relikd/lektor-force-update-plugin', + version='1.0', + classifiers=[ + 'Framework :: Lektor', + 'Environment :: Plugins', + ], + entry_points={ + 'lektor.plugins': [ + 'force-update = lektor_force_update:ForceUpdatePlugin', + ] + } +)