mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 00:24:40 +00:00
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:
parent
a21baa1d85
commit
a714c22060
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user