def find_local_child_template()

in taskcat/_cfn/stack_url_helper.py [0:0]


    def find_local_child_template(self, parent_template_path, child_template_path):
        final_template_path = ""

        # Start where the Parent template is
        project_root = Path(os.path.dirname(parent_template_path))

        # Get rid of any "//"
        child_template_path_tmp = os.path.normpath(child_template_path)

        # Take the path piece by piece and try in current folder
        while "/" in str(child_template_path_tmp):
            child_template_path_tmp = self._remove_one_level(child_template_path_tmp)
            final_template_path = Path(
                "/".join([str(project_root), str(child_template_path_tmp)])
            )
            if final_template_path.exists() and final_template_path.is_file():
                return str(final_template_path)

        # Take the path piece by piece and try in one folder up folder
        project_root = Path(
            os.path.normpath(os.path.dirname(parent_template_path) + "/../")
        )
        # Get rid of any "//"
        child_template_path_tmp = os.path.normpath(child_template_path)

        while "/" in str(child_template_path_tmp):
            child_template_path_tmp = self._remove_one_level(child_template_path_tmp)
            final_template_path = Path(
                "/".join([str(project_root), str(child_template_path_tmp)])
            )
            if final_template_path.exists() and final_template_path.is_file():
                return str(final_template_path)

        return ""