diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/template.py | 21 | ||||
| -rw-r--r-- | python/vyos/tpm.py | 2 | ||||
| -rw-r--r-- | python/vyos/xml_ref/__init__.py | 6 | ||||
| -rw-r--r-- | python/vyos/xml_ref/definition.py | 27 | 
4 files changed, 43 insertions, 13 deletions
| diff --git a/python/vyos/template.py b/python/vyos/template.py index ac77e8a3d..fbc5f1456 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -25,6 +25,14 @@ from vyos.utils.file import makedir  from vyos.utils.permission import chmod  from vyos.utils.permission import chown +# We use a mutable global variable for the default template directory +# to make it possible to call scripts from this repository +# outside of live VyOS systems. +# If something (like the image build scripts) +# want to call a script, they can modify the default location +# to the repository path. +DEFAULT_TEMPLATE_DIR = directories["templates"] +  # Holds template filters registered via register_filter()  _FILTERS = {}  _TESTS = {} @@ -35,18 +43,7 @@ def _get_environment(location=None):      from os import getenv      if location is None: -        # Sometimes functions that rely on templates need to be executed outside of VyOS installations: -        # for example, installer functions are executed for image builds, -        # and anything may be invoked for testing from a developer's machine. -        # This environment variable allows running any unmodified code -        # with a custom template location. -        location_env_var = getenv("VYOS_TEMPLATE_DIR") -        if location_env_var: -            print(f"Using environment variable {location_env_var}") -            template_dir = location_env_var -        else: -            template_dir = directories["templates"] -        loc_loader=FileSystemLoader(template_dir) +        loc_loader=FileSystemLoader(DEFAULT_TEMPLATE_DIR)      else:          loc_loader=FileSystemLoader(location)      env = Environment( diff --git a/python/vyos/tpm.py b/python/vyos/tpm.py index b9f28546f..a24f149fd 100644 --- a/python/vyos/tpm.py +++ b/python/vyos/tpm.py @@ -15,7 +15,7 @@  import os  import tempfile -from vyos.util import rc_cmd +from vyos.utils.process import rc_cmd  default_pcrs = ['0','2','4','7']  tpm_handle = 0x81000000 diff --git a/python/vyos/xml_ref/__init__.py b/python/vyos/xml_ref/__init__.py index bf434865d..2ba3da4e8 100644 --- a/python/vyos/xml_ref/__init__.py +++ b/python/vyos/xml_ref/__init__.py @@ -53,6 +53,12 @@ def is_valueless(path: list) -> bool:  def is_leaf(path: list) -> bool:      return load_reference().is_leaf(path) +def owner(path: list) -> str: +    return load_reference().owner(path) + +def priority(path: list) -> str: +    return load_reference().priority(path) +  def cli_defined(path: list, node: str, non_local=False) -> bool:      return load_reference().cli_defined(path, node, non_local=non_local) diff --git a/python/vyos/xml_ref/definition.py b/python/vyos/xml_ref/definition.py index c90c5ddbc..c85835ffd 100644 --- a/python/vyos/xml_ref/definition.py +++ b/python/vyos/xml_ref/definition.py @@ -135,6 +135,33 @@ class Xml:          d = self._get_ref_path(path)          return self._is_leaf_node(d) +    def _least_upper_data(self, path: list, name: str) -> str: +        ref_path = path.copy() +        d = self.ref +        data = '' +        while ref_path and d: +            d = d.get(ref_path[0], {}) +            ref_path.pop(0) +            if self._is_tag_node(d) and ref_path: +                ref_path.pop(0) +            if self._is_leaf_node(d) and ref_path: +                ref_path.pop(0) +            res = self._get_ref_node_data(d, name) +            if res is not None: +                data = res + +        return data + +    def owner(self, path: list) -> str: +        from pathlib import Path +        data = self._least_upper_data(path, 'owner') +        if data: +            data = Path(data.split()[0]).name +        return data + +    def priority(self, path: list) -> str: +        return self._least_upper_data(path, 'priority') +      @staticmethod      def _dict_get(d: dict, path: list) -> dict:          for i in path: | 
