Add optional comment removal in include_raw
This commit is contained in:
parent
2579636d08
commit
7d1cc52227
@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# 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
|
## 0.7.4
|
||||||
- Fix for only Iterate in use
|
- Fix for only Iterate in use
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import logging
|
|||||||
|
|
||||||
__author__ = "Stefan Reimer"
|
__author__ = "Stefan Reimer"
|
||||||
__email__ = "stefan@zero-downtimet.net"
|
__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.
|
# Set up logging to ``/dev/null`` like a library is supposed to.
|
||||||
|
@ -46,13 +46,23 @@ def option(context, attribute, default_value=u'', source='options'):
|
|||||||
|
|
||||||
|
|
||||||
@jinja2.contextfunction
|
@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
|
jenv = context.environment
|
||||||
output = ''
|
output = ''
|
||||||
for name in files:
|
for name in files:
|
||||||
output = output + jinja2.Markup(jenv.loader.get_source(jenv, name)[0])
|
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:
|
if not gz:
|
||||||
return(output)
|
return(output)
|
||||||
|
Loading…
Reference in New Issue
Block a user