Skip to content

Commit ea1d152

Browse files
committed
add checkfile package: use check_file(filename) template function to check if file is present.
1 parent d784188 commit ea1d152

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

packages/checkfile/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist
2+
build
3+
*.pyc
4+
*.pyo
5+
*.egg-info

packages/checkfile/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# CheckFile
2+
3+
Plugin to check if a file is present.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
import os
3+
from lektor.pluginsystem import Plugin
4+
5+
6+
class CheckfilePlugin(Plugin):
7+
name = 'CheckFile'
8+
description = u'Plugin to check if a file is present.'
9+
10+
def on_setup_env(self, **extra):
11+
12+
def check_file(filename):
13+
fn = os.path.join(self.env.root_path, filename)
14+
assert os.path.isfile(fn), 'file {} does not exist'.format(fn)
15+
return ""
16+
self.env.jinja_env.globals.update(
17+
check_file=check_file
18+
)

packages/checkfile/setup.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import ast
2+
import io
3+
import re
4+
5+
from setuptools import setup, find_packages
6+
7+
with io.open('README.md', 'rt', encoding="utf8") as f:
8+
readme = f.read()
9+
10+
_description_re = re.compile(r'description\s+=\s+(?P<description>.*)')
11+
12+
with open('lektor_checkfile.py', 'rb') as f:
13+
description = str(ast.literal_eval(_description_re.search(
14+
f.read().decode('utf-8')).group(1)))
15+
16+
setup(
17+
author='mayank',
18+
author_email='mayank.nader11@gmail.com',
19+
description=description,
20+
keywords='Lektor plugin',
21+
license='MIT',
22+
long_description=readme,
23+
long_description_content_type='text/markdown',
24+
name='lektor-checkfile',
25+
packages=find_packages(),
26+
py_modules=['lektor_checkfile'],
27+
# url='[link to your repository]',
28+
version='0.1',
29+
classifiers=[
30+
'Framework :: Lektor',
31+
'Environment :: Plugins',
32+
],
33+
entry_points={
34+
'lektor.plugins': [
35+
'checkfile = lektor_checkfile:CheckfilePlugin',
36+
]
37+
}
38+
)

0 commit comments

Comments
 (0)