comparison roundup/admin.py @ 1591:21312a7564fd

moving templates around
author Richard Jones <richard@users.sourceforge.net>
date Thu, 17 Apr 2003 03:38:00 +0000
parents 93e0a565cee5
children 6318b21b0f73
comparison
equal deleted inserted replaced
1590:198dbefc1d5a 1591:21312a7564fd
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.50 2003-03-27 05:23:39 richard Exp $ 19 # $Id: admin.py,v 1.51 2003-04-17 03:37:57 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 24 import sys, os, getpass, getopt, re, UserDict, shlex, shutil, rfc822
25 try: 25 try:
26 import csv 26 import csv
27 except ImportError: 27 except ImportError:
28 csv = None 28 csv = None
29 from roundup import date, hyperdb, roundupdb, init, password, token 29 from roundup import date, hyperdb, roundupdb, init, password, token
276 print line[indent:] 276 print line[indent:]
277 else: 277 else:
278 print line 278 print line
279 return 0 279 return 0
280 280
281 def listTemplates(self):
282 ''' List all the available templates.
283
284 Look in three places:
285 <prefix>/share/roundup/templates
286 <__file__>/../templates
287 current dir
288 '''
289 # OK, try <prefix>/share/roundup/templates
290 # -- this module (roundup.admin) will be installed in something
291 # _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 # part
294 path = __file__
295 for i in range(5):
296 path = os.path.dirname(path)
297 tdir = os.path.join(path, 'share', 'roundup', 'templates')
298 if os.path.isdir(tdir):
299 templates = listTemplates(tdir)
300 else:
301 templates = {}
302
303 # OK, now try as if we're in the roundup source distribution
304 # directory, so this module will be in .../roundup-*/roundup/admin.py
305 # and we're interested in the .../roundup-*/ part.
306 path = __file__
307 for i in range(2):
308 path = os.path.dirname(path)
309 tdir = os.path.join(path, 'templates')
310 if os.path.isdir(tdir):
311 templates.update(listTemplates(tdir))
312
313 return templates
314
281 def help_initopts(self): 315 def help_initopts(self):
282 import roundup.templates 316 templates = self.listTemplates()
283 templates = roundup.templates.listTemplates() 317 print _('Templates:'), ', '.join(templates.keys())
284 print _('Templates:'), ', '.join(templates)
285 import roundup.backends 318 import roundup.backends
286 backends = roundup.backends.__all__ 319 backends = roundup.backends.__all__
287 print _('Back ends:'), ', '.join(backends) 320 print _('Back ends:'), ', '.join(backends)
288 321
289 def do_install(self, tracker_home, args): 322 def do_install(self, tracker_home, args):
310 if not os.path.exists(parent): 343 if not os.path.exists(parent):
311 raise UsageError, _('Instance home parent directory "%(parent)s"' 344 raise UsageError, _('Instance home parent directory "%(parent)s"'
312 ' does not exist')%locals() 345 ' does not exist')%locals()
313 346
314 # select template 347 # select template
315 import roundup.templates 348 templates = self.listTemplates()
316 templates = roundup.templates.listTemplates()
317 template = len(args) > 1 and args[1] or '' 349 template = len(args) > 1 and args[1] or ''
318 if template not in templates: 350 if not templates.has_key(template):
319 print _('Templates:'), ', '.join(templates) 351 print _('Templates:'), ', '.join(templates.keys())
320 while template not in templates: 352 while not templates.has_key(template):
321 template = raw_input(_('Select template [classic]: ')).strip() 353 template = raw_input(_('Select template [classic]: ')).strip()
322 if not template: 354 if not template:
323 template = 'classic' 355 template = 'classic'
324 356
325 # select hyperdb backend 357 # select hyperdb backend
333 if not backend: 365 if not backend:
334 backend = 'anydbm' 366 backend = 'anydbm'
335 # XXX perform a unit test based on the user's selections 367 # XXX perform a unit test based on the user's selections
336 368
337 # install! 369 # install!
338 init.install(tracker_home, template) 370 init.install(tracker_home, templates[template]['path'])
339 init.write_select_db(tracker_home, backend) 371 init.write_select_db(tracker_home, backend)
340 372
341 print _(''' 373 print _('''
342 You should now edit the tracker configuration file: 374 You should now edit the tracker configuration file:
343 %(config_file)s 375 %(config_file)s
1375 return ret 1407 return ret
1376 finally: 1408 finally:
1377 if self.db: 1409 if self.db:
1378 self.db.close() 1410 self.db.close()
1379 1411
1412
1413 def listTemplates(dir):
1414 ''' List all the Roundup template directories in a given directory.
1415
1416 Find all the dirs that contain a TEMPLATE-INFO.txt and parse it.
1417
1418 Return a list of dicts of info about the templates.
1419 '''
1420 ret = {}
1421 for idir in os.listdir(dir):
1422 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 return ret
1433
1380 if __name__ == '__main__': 1434 if __name__ == '__main__':
1381 tool = AdminTool() 1435 tool = AdminTool()
1382 sys.exit(tool.main()) 1436 sys.exit(tool.main())
1383 1437
1384 # vim: set filetype=python ts=4 sw=4 et si 1438 # vim: set filetype=python ts=4 sw=4 et si

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