From ced42938e16bc63d7a258400ca698425a9e8f994 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Wed, 17 Dec 2025 12:36:40 +0100 Subject: [PATCH] projects.mk / jw-projects.py: Support tmpl_dir && tmpls-dir For a project to supply templates, it needs to advertise their location. For this, the tmpl_dir make variable is added to projects.mk. If other-project wants to get hold of some-project's templates, it can do, e.g.: TEMPLATES = $(wilcard $(call tmpl_dir,some-project)/*.tmpl) To achieve this, support for the tmpls-dir command is added to jw-projects.py. Signed-off-by: Jan Lindemann --- make/projects.mk | 1 + src/python/jw/pkg/App.py | 12 +++++++++++- src/python/jw/pkg/build/cmds/CmdTmplDir.py | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/python/jw/pkg/build/cmds/CmdTmplDir.py diff --git a/make/projects.mk b/make/projects.mk index 9804f883..9e82afb3 100644 --- a/make/projects.mk +++ b/make/projects.mk @@ -34,4 +34,5 @@ ifneq ($(TOPDIR),) proj_query = $(shell $(proj_query_cmd) $(1)) proj_dir = $(call proj_query,proj-dir $(1)) htdocs_dir = $(call proj_query,htdocs-dir $(1)) + tmpl_dir = $(call proj_query,tmpl-dir $(1)) endif diff --git a/src/python/jw/pkg/App.py b/src/python/jw/pkg/App.py index 9afa912e..2080d1d8 100644 --- a/src/python/jw/pkg/App.py +++ b/src/python/jw/pkg/App.py @@ -115,7 +115,17 @@ class App(object): pd = self.proj_dir(name) if pd is None: return None - for r in [ pd + "/tools/html/htdocs", pd + "/htdocs", "/srv/www/proj/" + name ]: + for r in [ pd + "/src/html/htdocs", pd + "/tools/html/htdocs", pd + "/htdocs", "/srv/www/proj/" + name ]: + if os.path.isdir(r): + return r + return None + + # TODO: add support for customizing this in project.conf + def tmpl_dir(self, name): + pd = self.proj_dir(name) + if pd is None: + return None + for r in [ pd + "/tmpl", "/opt/" + name + "/share/tmpl" ]: if os.path.isdir(r): return r return None diff --git a/src/python/jw/pkg/build/cmds/CmdTmplDir.py b/src/python/jw/pkg/build/cmds/CmdTmplDir.py new file mode 100644 index 00000000..4ae35891 --- /dev/null +++ b/src/python/jw/pkg/build/cmds/CmdTmplDir.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +from argparse import Namespace, ArgumentParser + +from ..Cmd import Cmd + +class CmdTmplDir(Cmd): # export + + def __init__(self) -> None: + super().__init__('tmpl-dir', help='Print directory containing templates of a given module') + + def add_arguments(self, parser: ArgumentParser) -> None: + super().add_arguments(parser) + parser.add_argument('module', nargs='*', help='Modules') + + def _run(self, args: Namespace) -> None: + r = [] + for m in args.module: + r.append(self.app.tmpl_dir(m)) + print(' '.join(r))