Skip to content

Commit 48b2ff3

Browse files
author
Richard Jones
committed
more places to look for templates
1 parent 35ca8bf commit 48b2ff3

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

roundup/admin.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1717
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1818
#
19-
# $Id: admin.py,v 1.51 2003-04-17 03:37:57 richard Exp $
19+
# $Id: admin.py,v 1.52 2003-04-17 07:33:08 richard Exp $
2020

2121
'''Administration commands for maintaining Roundup trackers.
2222
'''
@@ -282,9 +282,10 @@ def listTemplates(self):
282282
''' List all the available templates.
283283
284284
Look in three places:
285-
<prefix>/share/roundup/templates
286-
<__file__>/../templates
287-
current dir
285+
<prefix>/share/roundup/templates/*
286+
<__file__>/../templates/*
287+
current dir/*
288+
current dir as a template
288289
'''
289290
# OK, try <prefix>/share/roundup/templates
290291
# -- this module (roundup.admin) will be installed in something
@@ -310,6 +311,14 @@ def listTemplates(self):
310311
if os.path.isdir(tdir):
311312
templates.update(listTemplates(tdir))
312313

314+
# Try subdirs of the current dir
315+
templates.update(listTemplates(os.getcwd()))
316+
317+
# Finally, try the current directory as a template
318+
template = loadTemplate(os.getcwd())
319+
if template:
320+
templates[template['name']] = template
321+
313322
return templates
314323

315324
def help_initopts(self):
@@ -1420,17 +1429,30 @@ def listTemplates(dir):
14201429
ret = {}
14211430
for idir in os.listdir(dir):
14221431
idir = os.path.join(dir, idir)
1423-
ti = os.path.join(idir, 'TEMPLATE-INFO.txt')
1424-
if os.path.isfile(ti):
1425-
m = rfc822.Message(open(ti))
1426-
ti = {}
1427-
ti['name'] = m['name']
1428-
ti['description'] = m['description']
1429-
ti['intended-for'] = m['intended-for']
1430-
ti['path'] = idir
1431-
ret[m['name']] = ti
1432+
ti = loadTemplate(idir)
1433+
if ti:
1434+
ret[ti['name']] = ti
14321435
return ret
14331436

1437+
def loadTemplate(dir):
1438+
''' Attempt to load a Roundup template from the indicated directory.
1439+
1440+
Return None if there's no template, otherwise a template info
1441+
dictionary.
1442+
'''
1443+
ti = os.path.join(dir, 'TEMPLATE-INFO.txt')
1444+
if not os.path.exists(ti):
1445+
return None
1446+
1447+
# load up the template's information
1448+
m = rfc822.Message(open(ti))
1449+
ti = {}
1450+
ti['name'] = m['name']
1451+
ti['description'] = m['description']
1452+
ti['intended-for'] = m['intended-for']
1453+
ti['path'] = dir
1454+
return ti
1455+
14341456
if __name__ == '__main__':
14351457
tool = AdminTool()
14361458
sys.exit(tool.main())

0 commit comments

Comments
 (0)