comparison roundup/admin.py @ 1593:6318b21b0f73

more places to look for templates
author Richard Jones <richard@users.sourceforge.net>
date Thu, 17 Apr 2003 07:33:08 +0000
parents 21312a7564fd
children e5e00d3a3fe2
comparison
equal deleted inserted replaced
1592:4074e2336eed 1593:6318b21b0f73
14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
18 # 18 #
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 $
20 20
21 '''Administration commands for maintaining Roundup trackers. 21 '''Administration commands for maintaining Roundup trackers.
22 ''' 22 '''
23 23
24 import sys, os, getpass, getopt, re, UserDict, shlex, shutil, rfc822 24 import sys, os, getpass, getopt, re, UserDict, shlex, shutil, rfc822
280 280
281 def listTemplates(self): 281 def listTemplates(self):
282 ''' List all the available templates. 282 ''' List all the available templates.
283 283
284 Look in three places: 284 Look in three places:
285 <prefix>/share/roundup/templates 285 <prefix>/share/roundup/templates/*
286 <__file__>/../templates 286 <__file__>/../templates/*
287 current dir 287 current dir/*
288 current dir as a template
288 ''' 289 '''
289 # OK, try <prefix>/share/roundup/templates 290 # OK, try <prefix>/share/roundup/templates
290 # -- this module (roundup.admin) will be installed in something 291 # -- this module (roundup.admin) will be installed in something
291 # _like_ /usr/lib/python2.2/site-packages/roundup/admin.py, and 292 # _like_ /usr/lib/python2.2/site-packages/roundup/admin.py, and
292 # we're interested in where the "lib" directory is - ie. the /usr/ 293 # we're interested in where the "lib" directory is - ie. the /usr/
307 for i in range(2): 308 for i in range(2):
308 path = os.path.dirname(path) 309 path = os.path.dirname(path)
309 tdir = os.path.join(path, 'templates') 310 tdir = os.path.join(path, 'templates')
310 if os.path.isdir(tdir): 311 if os.path.isdir(tdir):
311 templates.update(listTemplates(tdir)) 312 templates.update(listTemplates(tdir))
313
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
312 321
313 return templates 322 return templates
314 323
315 def help_initopts(self): 324 def help_initopts(self):
316 templates = self.listTemplates() 325 templates = self.listTemplates()
1418 Return a list of dicts of info about the templates. 1427 Return a list of dicts of info about the templates.
1419 ''' 1428 '''
1420 ret = {} 1429 ret = {}
1421 for idir in os.listdir(dir): 1430 for idir in os.listdir(dir):
1422 idir = os.path.join(dir, idir) 1431 idir = os.path.join(dir, idir)
1423 ti = os.path.join(idir, 'TEMPLATE-INFO.txt') 1432 ti = loadTemplate(idir)
1424 if os.path.isfile(ti): 1433 if ti:
1425 m = rfc822.Message(open(ti)) 1434 ret[ti['name']] = 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 return ret 1435 return ret
1436
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
1433 1455
1434 if __name__ == '__main__': 1456 if __name__ == '__main__':
1435 tool = AdminTool() 1457 tool = AdminTool()
1436 sys.exit(tool.main()) 1458 sys.exit(tool.main())
1437 1459

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