configd / configuration templates - add helpers.file_exists to check for file existence. closes https://github.com/opnsense/core/issues/7023

This commit is contained in:
Ad Schellevis 2023-11-21 16:45:43 +01:00
parent eb74bd05ff
commit e76bc6ead8

View File

@ -175,6 +175,18 @@ class Helpers(object):
return [lst]
return lst
@staticmethod
def file_exists(pathname):
"""
:param pathname: absolute or relative path name depending if it starts with a /
:return: bool
"""
if pathname.startswith('/'):
return os.path.isfile(pathname)
else:
template_path = os.path.realpath("%s/../../templates/" % os.path.dirname(__file__))
return os.path.isfile("%s/%s" % (template_path, pathname))
@staticmethod
def glob(pathname):
"""