configd/templates add support for helpers.glob() to enable template traversal, which is practical when trying to merge several files into the same output.

required for https://github.com/opnsense/core/issues/3505
This commit is contained in:
Ad Schellevis 2019-05-31 14:41:59 +02:00
parent a21baa1d85
commit a714c22060

View File

@ -28,6 +28,8 @@
package : configd
"""
import os
import glob
import collections
import netaddr
@ -167,3 +169,18 @@ class Helpers(object):
elif type(lst) in (collections.OrderedDict, dict):
return [lst]
return lst
@staticmethod
def glob(pathname):
""" glob within template directory scope
:param pathname: relative path name
:return: list
"""
result = list()
template_path = os.path.realpath("%s/../../templates/" % os.path.dirname(__file__))
for sfilename in glob.glob("%s/%s" % (template_path, pathname)):
sfilename = os.path.realpath(sfilename)
if sfilename.startswith(template_path):
result.append(sfilename[len(template_path):].lstrip('/'))
return result