Add optional comment removal in include_raw
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Stefan Reimer 2019-09-11 12:53:33 +00:00
parent 2579636d08
commit 7d1cc52227
3 changed files with 17 additions and 3 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## 0.7.5
- Added warning if rendered templates exceed max. inline size of 51200 bytes
- Added optional removal of comments during include_raw processing to reduce user-data size
## 0.7.4
- Fix for only Iterate in use

View File

@ -2,7 +2,7 @@ import logging
__author__ = "Stefan Reimer"
__email__ = "stefan@zero-downtimet.net"
__version__ = "0.7.4"
__version__ = "0.7.5"
# Set up logging to ``/dev/null`` like a library is supposed to.

View File

@ -46,13 +46,23 @@ def option(context, attribute, default_value=u'', source='options'):
@jinja2.contextfunction
def include_raw_gz(context, files=None, gz=True):
def include_raw_gz(context, files=None, gz=True, remove_comments=False):
jenv = context.environment
output = ''
for name in files:
output = output + jinja2.Markup(jenv.loader.get_source(jenv, name)[0])
# logger.debug(output)
if remove_comments:
# Remove full line comments but not shebang
_re = re.compile(r'^\s*#[^!]')
stripped_output = ''
for curline in output.splitlines():
if re.match(_re, curline):
logger.debug("Removed {}".format(curline))
else:
stripped_output = stripped_output + curline
output = stripped_output
if not gz:
return(output)