comparison roundup/admin.py @ 1916:d157b9b56ebf

implemented munging of template name for installed trackers
author Richard Jones <richard@users.sourceforge.net>
date Thu, 13 Nov 2003 04:12:10 +0000
parents dc43e339e607
children fc52d57c6c3e
comparison
equal deleted inserted replaced
1915:20cfd25cffda 1916:d157b9b56ebf
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.60 2003-11-11 00:35:13 richard Exp $ 19 # $Id: admin.py,v 1.61 2003-11-13 04:12:10 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, shutil, rfc822 24 import sys, os, getpass, getopt, re, UserDict, shutil, rfc822
303 # move up N elements in the path 303 # move up N elements in the path
304 for i in range(N): 304 for i in range(N):
305 path = os.path.dirname(path) 305 path = os.path.dirname(path)
306 tdir = os.path.join(path, 'share', 'roundup', 'templates') 306 tdir = os.path.join(path, 'share', 'roundup', 'templates')
307 if os.path.isdir(tdir): 307 if os.path.isdir(tdir):
308 templates = listTemplates(tdir) 308 templates = init.listTemplates(tdir)
309 break 309 break
310 310
311 # OK, now try as if we're in the roundup source distribution 311 # OK, now try as if we're in the roundup source distribution
312 # directory, so this module will be in .../roundup-*/roundup/admin.py 312 # directory, so this module will be in .../roundup-*/roundup/admin.py
313 # and we're interested in the .../roundup-*/ part. 313 # and we're interested in the .../roundup-*/ part.
314 path = __file__ 314 path = __file__
315 for i in range(2): 315 for i in range(2):
316 path = os.path.dirname(path) 316 path = os.path.dirname(path)
317 tdir = os.path.join(path, 'templates') 317 tdir = os.path.join(path, 'templates')
318 if os.path.isdir(tdir): 318 if os.path.isdir(tdir):
319 templates.update(listTemplates(tdir)) 319 templates.update(init.listTemplates(tdir))
320 320
321 # Try subdirs of the current dir 321 # Try subdirs of the current dir
322 templates.update(listTemplates(os.getcwd())) 322 templates.update(init.listTemplates(os.getcwd()))
323 323
324 # Finally, try the current directory as a template 324 # Finally, try the current directory as a template
325 template = loadTemplate(os.getcwd()) 325 template = init.loadTemplateInfo(os.getcwd())
326 if template: 326 if template:
327 templates[template['name']] = template 327 templates[template['name']] = template
328 328
329 return templates 329 return templates
330 330
1342 return ret 1342 return ret
1343 finally: 1343 finally:
1344 if self.db: 1344 if self.db:
1345 self.db.close() 1345 self.db.close()
1346 1346
1347
1348 def listTemplates(dir):
1349 ''' List all the Roundup template directories in a given directory.
1350
1351 Find all the dirs that contain a TEMPLATE-INFO.txt and parse it.
1352
1353 Return a list of dicts of info about the templates.
1354 '''
1355 ret = {}
1356 for idir in os.listdir(dir):
1357 idir = os.path.join(dir, idir)
1358 ti = loadTemplate(idir)
1359 if ti:
1360 ret[ti['name']] = ti
1361 return ret
1362
1363 def loadTemplate(dir):
1364 ''' Attempt to load a Roundup template from the indicated directory.
1365
1366 Return None if there's no template, otherwise a template info
1367 dictionary.
1368 '''
1369 ti = os.path.join(dir, 'TEMPLATE-INFO.txt')
1370 if not os.path.exists(ti):
1371 return None
1372
1373 # load up the template's information
1374 m = rfc822.Message(open(ti))
1375 ti = {}
1376 ti['name'] = m['name']
1377 ti['description'] = m['description']
1378 ti['intended-for'] = m['intended-for']
1379 ti['path'] = dir
1380 return ti
1381
1382 if __name__ == '__main__': 1347 if __name__ == '__main__':
1383 tool = AdminTool() 1348 tool = AdminTool()
1384 sys.exit(tool.main()) 1349 sys.exit(tool.main())
1385 1350
1386 # vim: set filetype=python ts=4 sw=4 et si 1351 # vim: set filetype=python ts=4 sw=4 et si

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