@@ -289,7 +289,7 @@ def do_help(self, args, nl_re=re.compile('[\r\n]'),
289289 print (line )
290290 return 0
291291
292- def listTemplates (self ):
292+ def listTemplates (self , trace_search = False ):
293293 """ List all the available templates.
294294
295295 Look in the following places, where the later rules take precedence:
@@ -327,7 +327,7 @@ def listTemplates(self):
327327 for _i in range (N ):
328328 path = os .path .dirname (path )
329329 tdir = os .path .join (path , 'share' , 'roundup' , 'templates' )
330- if debug : print (tdir )
330+ if debug or trace_search : print (tdir )
331331 if os .path .isdir (tdir ):
332332 templates = init .listTemplates (tdir )
333333 if debug : print (" Found templates breaking loop" )
@@ -349,7 +349,7 @@ def listTemplates(self):
349349 # path is /usr/local/lib/python3.10/site-packages
350350 tdir = os .path .join (path , sys .prefix [1 :], 'share' ,
351351 'roundup' , 'templates' )
352- if debug : print (tdir )
352+ if debug or trace_search : print (tdir )
353353 if os .path .isdir (tdir ):
354354 templates .update (init .listTemplates (tdir ))
355355
@@ -359,27 +359,27 @@ def listTemplates(self):
359359 # path is /usr/local/lib/python3.10/site-packages
360360 tdir = os .path .join (path , sys .base_prefix [1 :], 'local' , 'share' ,
361361 'roundup' , 'templates' )
362- if debug : print (tdir )
362+ if debug or trace_search : print (tdir )
363363 if os .path .isdir (tdir ):
364364 templates .update (init .listTemplates (tdir ))
365365 # path is /usr/local/lib/python3.10/site-packages
366366
367367
368368 tdir = os .path .join (path , sys .base_prefix [1 :], 'share' ,
369369 'roundup' , 'templates' )
370- if debug : print (tdir )
370+ if debug or trace_search : print (tdir )
371371 if os .path .isdir (tdir ):
372372 templates .update (init .listTemplates (tdir ))
373373 except AttributeError :
374374 pass # sys.base_prefix doesn't work under python2
375375
376376 # Try subdirs of the current dir
377377 templates .update (init .listTemplates (os .getcwd ()))
378- if debug : print (os .getcwd () + '/*' )
378+ if debug or trace_search : print (os .getcwd () + '/*' )
379379
380380 # Finally, try the current directory as a template
381381 template = init .loadTemplateInfo (os .getcwd ())
382- if debug : print (os .getcwd () + '/*' )
382+ if debug or trace_search : print (os .getcwd ())
383383 if template :
384384 if debug : print (" Found template %s" % template ['name' ])
385385 templates [template ['name' ]] = template
@@ -1080,6 +1080,34 @@ def do_list(self, args):
10801080 print (_ ('%(nodeid)4s: %(value)s' ) % locals ())
10811081 return 0
10821082
1083+ def do_templates (self , args ):
1084+ '' """Usage: templates [trace_search]
1085+ List templates and their installed directories.
1086+
1087+ With trace_search also list all directories that are
1088+ searched for templates.
1089+ """
1090+ import textwrap
1091+
1092+ trace_search = False
1093+ if args and args [0 ] == "trace_search" :
1094+ trace_search = True
1095+
1096+ templates = self .listTemplates (trace_search = trace_search )
1097+
1098+ for name in sorted (list (templates .keys ())):
1099+ templates [name ]['description' ] = textwrap .fill (
1100+ "\n " .join ([ line .lstrip () for line in
1101+ templates [name ]['description' ].split ("\n " )]),
1102+ 70 ,
1103+ subsequent_indent = " "
1104+ )
1105+ print ("""
1106+ Name: %(name)s
1107+ Path: %(path)s
1108+ Desc: %(description)s
1109+ """ % templates [name ])
1110+
10831111 def do_table (self , args ):
10841112 '' """Usage: table classname [property[,property]*]
10851113 List the instances of a class in tabular form.
@@ -1713,6 +1741,8 @@ def run_command(self, args):
17131741 except UsageError as message : # noqa: F841
17141742 print (_ ('Error: %(message)s' ) % locals ())
17151743 return 1
1744+ elif command == "templates" :
1745+ return self .do_templates (args [1 :])
17161746
17171747 # get the tracker
17181748 try :
0 commit comments