This commit is contained in:
relikd
2019-11-24 20:10:12 +01:00
commit f3b5cb77a0
5 changed files with 112 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
dist
build
*.pyc
*.pyo
*.egg-info

7
LICENSE Normal file
View File

@@ -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.

14
README.md Normal file
View File

@@ -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.

48
lektor_force_update.py Normal file
View File

@@ -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')

38
setup.py Normal file
View File

@@ -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<description>.*)')
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',
]
}
)