Restructuring project
This commit is contained in:
1 parent
beee0b14a7
commit
354a1976c1
10 files changed
+52
-4
No files matched your search
@@ -0,0 +1,32 @@
|
|||||||
|
import setuptools
|
||||||
|
|
||||||
|
with open('requirements.txt') as f:
|
||||||
|
required = f.read().splitlines()
|
||||||
|
|
||||||
|
with open("README.md", "r", encoding="utf-8") as fh:
|
||||||
|
long_description = fh.read()
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
name="JinjaTemplateHelper",
|
||||||
|
version="0.1.0",
|
||||||
|
author="Dennis Twardowsky",
|
||||||
|
author_email="dennis@devpty.de",
|
||||||
|
description="Helper script for processing Jinja templates",
|
||||||
|
#long_description=long_description,
|
||||||
|
#long_description_content_type="text/markdown",
|
||||||
|
#url="https://github.com/pypa/sampleproject",
|
||||||
|
#project_urls={
|
||||||
|
# "Bug Tracker": "https://github.com/pypa/sampleproject/issues",
|
||||||
|
#},
|
||||||
|
classifiers=[
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
],
|
||||||
|
scripts=[
|
||||||
|
"src/renderTemplate.py"
|
||||||
|
],
|
||||||
|
packages=setuptools.find_packages(where="src"),
|
||||||
|
install_requires=required,
|
||||||
|
python_requires=">=3.6",
|
||||||
|
)
|
||||||
@@ -6,6 +6,7 @@ import os
|
|||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import jinja2
|
||||||
import toml
|
import toml
|
||||||
import yaml
|
import yaml
|
||||||
from dotenv import dotenv_values
|
from dotenv import dotenv_values
|
||||||
@@ -44,6 +45,17 @@ jenv = Environment(autoescape=True,
|
|||||||
optimized=True)
|
optimized=True)
|
||||||
|
|
||||||
|
|
||||||
|
# Jinja Context Functions
|
||||||
|
@jinja2.pass_context
|
||||||
|
def get_filtered_variables(c, filter_str=None):
|
||||||
|
ret_val = {}
|
||||||
|
for key, value in c.items():
|
||||||
|
if not callable(value) and (not filter_str or filter_str in key):
|
||||||
|
ret_val[key.replace(filter_str, '') if key.startswith(filter_str) or key.endswith(filter_str) else key] \
|
||||||
|
= value
|
||||||
|
return ret_val.items()
|
||||||
|
|
||||||
|
|
||||||
# Jinja Filters
|
# Jinja Filters
|
||||||
# -------------
|
# -------------
|
||||||
def filter_env(name, defvalue=""):
|
def filter_env(name, defvalue=""):
|
||||||
@@ -75,6 +87,7 @@ jenv.filters['ldap_dn'] = filter_domain2ldap
|
|||||||
jenv.filters['hostbyaddr'] = filter_hostbyaddr
|
jenv.filters['hostbyaddr'] = filter_hostbyaddr
|
||||||
jenv.filters['hostbyname'] = filter_hostbyname
|
jenv.filters['hostbyname'] = filter_hostbyname
|
||||||
|
|
||||||
|
jenv.globals['variables'] = get_filtered_variables
|
||||||
|
|
||||||
# Loader
|
# Loader
|
||||||
# ------
|
# ------
|
||||||
@@ -162,7 +175,7 @@ if __name__ == '__main__':
|
|||||||
# If template was found
|
# If template was found
|
||||||
if tpl:
|
if tpl:
|
||||||
if args.env_file:
|
if args.env_file:
|
||||||
content = os.environ | dotenv_values(".env")
|
content = os.environ | dotenv_values("../test/.env")
|
||||||
elif args.yaml_file:
|
elif args.yaml_file:
|
||||||
content = load_yaml_file(args.yaml_file)
|
content = load_yaml_file(args.yaml_file)
|
||||||
elif args.json_file:
|
elif args.json_file:
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"Type": "{{ TESTVAR }}",
|
|
||||||
}
|
|
||||||
File renamed without changes.
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"Type": "{{ TESTVAR }}",
|
||||||
|
{% for item,value in variables("WWW_DOMAIN_") %}
|
||||||
|
"{{ item }}": "{{ value }}",
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user