changeset 6957:f924af12ef50

issue2551233 - create new roundup-admin command "templates" add a command to list all templates, the directory where they are defined, and a description. If called as templates trace_dir also list all directores that are search for templates even if none are found.
author John Rouillard <rouilj@ieee.org>
date Mon, 12 Sep 2022 18:29:50 -0400
parents ca6b056b79a4
children e54a2db40a9e
files CHANGES.txt roundup/admin.py share/man/man1/roundup-admin.1 test/test_admin.py
diffstat 4 files changed, 62 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Sat Sep 10 23:00:52 2022 -0400
+++ b/CHANGES.txt	Mon Sep 12 18:29:50 2022 -0400
@@ -66,6 +66,10 @@
 - sqlite databases use WAL mode when *created* to improve read
   concurrency. Existing sqlite database still use rollback journal
   mode. See upgrading.txt for details. (John Rouillard)
+- issue2551233 - create new roundup-admin command "templates"
+  list all template names, location and descriptions. Should help
+  find where /usr/share/roundup/templates is buried during some
+  install mechanisms. (John Rouillard)
 
 2022-07-13 2.2.0
 
--- a/roundup/admin.py	Sat Sep 10 23:00:52 2022 -0400
+++ b/roundup/admin.py	Mon Sep 12 18:29:50 2022 -0400
@@ -289,7 +289,7 @@
                     print(line)
         return 0
 
-    def listTemplates(self):
+    def listTemplates(self, trace_search=False):
         """ List all the available templates.
 
         Look in the following places, where the later rules take precedence:
@@ -327,7 +327,7 @@
             for _i in range(N):
                 path = os.path.dirname(path)
             tdir = os.path.join(path, 'share', 'roundup', 'templates')
-            if debug: print(tdir)
+            if debug or trace_search: print(tdir)
             if os.path.isdir(tdir):
                 templates = init.listTemplates(tdir)
                 if debug: print("  Found templates breaking loop")
@@ -349,7 +349,7 @@
         # path is /usr/local/lib/python3.10/site-packages
         tdir = os.path.join(path, sys.prefix[1:], 'share',
                             'roundup', 'templates')
-        if debug: print(tdir)
+        if debug or trace_search: print(tdir)
         if os.path.isdir(tdir):
             templates.update(init.listTemplates(tdir))
 
@@ -359,7 +359,7 @@
             # path is /usr/local/lib/python3.10/site-packages
             tdir = os.path.join(path, sys.base_prefix[1:], 'local', 'share',
                                 'roundup', 'templates')
-            if debug: print(tdir)
+            if debug or trace_search: print(tdir)
             if os.path.isdir(tdir):
                 templates.update(init.listTemplates(tdir))
                             # path is /usr/local/lib/python3.10/site-packages
@@ -367,7 +367,7 @@
 
             tdir = os.path.join(path, sys.base_prefix[1:], 'share',
                                 'roundup', 'templates')
-            if debug: print(tdir)
+            if debug or trace_search: print(tdir)
             if os.path.isdir(tdir):
                 templates.update(init.listTemplates(tdir))
         except AttributeError:
@@ -375,11 +375,11 @@
 
         # Try subdirs of the current dir
         templates.update(init.listTemplates(os.getcwd()))
-        if debug: print(os.getcwd() + '/*')
+        if debug or trace_search: print(os.getcwd() + '/*')
             
         # Finally, try the current directory as a template
         template = init.loadTemplateInfo(os.getcwd())
-        if debug: print(os.getcwd() + '/*')
+        if debug or trace_search: print(os.getcwd())
         if template:
             if debug: print("  Found template %s"%template['name'])
             templates[template['name']] = template
@@ -1080,6 +1080,34 @@
                 print(_('%(nodeid)4s: %(value)s') % locals())
         return 0
 
+    def do_templates(self, args):
+        ''"""Usage: templates [trace_search]
+        List templates and their installed directories.
+
+        With trace_search also list all directories that are
+        searched for templates.
+        """
+        import textwrap
+
+        trace_search = False
+        if args and args[0] == "trace_search":
+            trace_search = True
+
+        templates = self.listTemplates(trace_search=trace_search)
+
+        for name in sorted(list(templates.keys())):
+            templates[name]['description'] = textwrap.fill(
+                "\n".join([ line.lstrip() for line in
+                            templates[name]['description'].split("\n")]),
+                70,
+                subsequent_indent="      "
+            )
+            print("""
+Name: %(name)s
+Path: %(path)s
+Desc: %(description)s
+"""%templates[name])
+
     def do_table(self, args):
         ''"""Usage: table classname [property[,property]*]
         List the instances of a class in tabular form.
@@ -1713,6 +1741,8 @@
             except UsageError as message:  # noqa: F841
                 print(_('Error: %(message)s') % locals())
                 return 1
+        elif command == "templates":
+            return self.do_templates(args[1:])
 
         # get the tracker
         try:
--- a/share/man/man1/roundup-admin.1	Sat Sep 10 23:00:52 2022 -0400
+++ b/share/man/man1/roundup-admin.1	Mon Sep 12 18:29:50 2022 -0400
@@ -237,6 +237,9 @@
 \fBspecification\fP \fIclassname\fP
 Show the properties for a classname.
 .TP
+\fBtemplates\fP \fI[trace_search]]\fP
+Lists the names, location and description of all known templates.
+.TP
 \fBtable\fP \fIclassname [property[,property]*]\fP
 Lists all instances of the given class. If the properties are not
 specified, all properties are displayed. By default, the column
--- a/test/test_admin.py	Sat Sep 10 23:00:52 2022 -0400
+++ b/test/test_admin.py	Mon Sep 12 18:29:50 2022 -0400
@@ -1250,6 +1250,24 @@
         print(expected)
         self.assertEqual(out, expected)
 
+    def testTemplates(self):
+        
+        self.install_init()
+        self.admin=AdminTool()
+
+        with captured_output() as (out, err):
+            # command does not require a tracker home. use zZzZ to cause error 
+            sys.argv=['main', '-i', "zZzZ", 'templates' ]
+            ret = self.admin.main()
+
+        out = out.getvalue().strip()
+
+        for tracker in ['Name: classic\nPath:',
+                        'Name: devel\nPath:',
+                        'Name: jinja2\nPath:',
+                        'Name: minimal\nPath:',
+                        'Name: responsive\nPath:']:
+            self.assertIn(tracker, out)
 
 class anydbmAdminTest(AdminTest, unittest.TestCase):
     backend = 'anydbm'

Roundup Issue Tracker: http://roundup-tracker.org/