From 57de954cab7251c8720a2bcee8c9ce940b8ff9dc Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 17 Apr 2003 07:33:08 +0000 Subject: [PATCH] more places to look for templates git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1665 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/admin.py | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/roundup/admin.py b/roundup/admin.py index fda6e46..2641526 100644 --- a/roundup/admin.py +++ b/roundup/admin.py @@ -16,7 +16,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: admin.py,v 1.51 2003-04-17 03:37:57 richard Exp $ +# $Id: admin.py,v 1.52 2003-04-17 07:33:08 richard Exp $ '''Administration commands for maintaining Roundup trackers. ''' @@ -282,9 +282,10 @@ Command help: ''' List all the available templates. Look in three places: - /share/roundup/templates - <__file__>/../templates - current dir + /share/roundup/templates/* + <__file__>/../templates/* + current dir/* + current dir as a template ''' # OK, try /share/roundup/templates # -- this module (roundup.admin) will be installed in something @@ -310,6 +311,14 @@ Command help: if os.path.isdir(tdir): templates.update(listTemplates(tdir)) + # Try subdirs of the current dir + templates.update(listTemplates(os.getcwd())) + + # Finally, try the current directory as a template + template = loadTemplate(os.getcwd()) + if template: + templates[template['name']] = template + return templates def help_initopts(self): @@ -1420,17 +1429,30 @@ def listTemplates(dir): ret = {} for idir in os.listdir(dir): idir = os.path.join(dir, idir) - ti = os.path.join(idir, 'TEMPLATE-INFO.txt') - if os.path.isfile(ti): - m = rfc822.Message(open(ti)) - ti = {} - ti['name'] = m['name'] - ti['description'] = m['description'] - ti['intended-for'] = m['intended-for'] - ti['path'] = idir - ret[m['name']] = ti + ti = loadTemplate(idir) + if ti: + ret[ti['name']] = ti return ret +def loadTemplate(dir): + ''' Attempt to load a Roundup template from the indicated directory. + + Return None if there's no template, otherwise a template info + dictionary. + ''' + ti = os.path.join(dir, 'TEMPLATE-INFO.txt') + if not os.path.exists(ti): + return None + + # load up the template's information + m = rfc822.Message(open(ti)) + ti = {} + ti['name'] = m['name'] + ti['description'] = m['description'] + ti['intended-for'] = m['intended-for'] + ti['path'] = dir + return ti + if __name__ == '__main__': tool = AdminTool() sys.exit(tool.main()) -- 2.30.2