Mercurial > p > roundup > code
comparison roundup/admin.py @ 2072:cc692b8b8fa9 maint-0.6
back-port template renaming fix
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 05 Mar 2004 00:06:20 +0000 |
| parents | 3d7bb1659d73 |
| children | 332c040b82da |
comparison
equal
deleted
inserted
replaced
| 2071:3555941caea0 | 2072:cc692b8b8fa9 |
|---|---|
| 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.55.2.2 2003-08-29 12:45:54 richard Exp $ | 19 # $Id: admin.py,v 1.55.2.3 2004-03-05 00:06:20 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 |
| 296 # move up N elements in the path | 296 # move up N elements in the path |
| 297 for i in range(N): | 297 for i in range(N): |
| 298 path = os.path.dirname(path) | 298 path = os.path.dirname(path) |
| 299 tdir = os.path.join(path, 'share', 'roundup', 'templates') | 299 tdir = os.path.join(path, 'share', 'roundup', 'templates') |
| 300 if os.path.isdir(tdir): | 300 if os.path.isdir(tdir): |
| 301 templates = listTemplates(tdir) | 301 templates = init.listTemplates(tdir) |
| 302 break | 302 break |
| 303 | 303 |
| 304 # OK, now try as if we're in the roundup source distribution | 304 # OK, now try as if we're in the roundup source distribution |
| 305 # directory, so this module will be in .../roundup-*/roundup/admin.py | 305 # directory, so this module will be in .../roundup-*/roundup/admin.py |
| 306 # and we're interested in the .../roundup-*/ part. | 306 # and we're interested in the .../roundup-*/ part. |
| 307 path = __file__ | 307 path = __file__ |
| 308 for i in range(2): | 308 for i in range(2): |
| 309 path = os.path.dirname(path) | 309 path = os.path.dirname(path) |
| 310 tdir = os.path.join(path, 'templates') | 310 tdir = os.path.join(path, 'templates') |
| 311 if os.path.isdir(tdir): | 311 if os.path.isdir(tdir): |
| 312 templates.update(listTemplates(tdir)) | 312 templates.update(init.listTemplates(tdir)) |
| 313 | 313 |
| 314 # Try subdirs of the current dir | 314 # Try subdirs of the current dir |
| 315 templates.update(listTemplates(os.getcwd())) | 315 templates.update(init.listTemplates(os.getcwd())) |
| 316 | 316 |
| 317 # Finally, try the current directory as a template | 317 # Finally, try the current directory as a template |
| 318 template = loadTemplate(os.getcwd()) | 318 template = init.loadTemplateInfo(os.getcwd()) |
| 319 if template: | 319 if template: |
| 320 templates[template['name']] = template | 320 templates[template['name']] = template |
| 321 | 321 |
| 322 return templates | 322 return templates |
| 323 | 323 |
| 1405 finally: | 1405 finally: |
| 1406 if self.db: | 1406 if self.db: |
| 1407 self.db.close() | 1407 self.db.close() |
| 1408 | 1408 |
| 1409 | 1409 |
| 1410 def listTemplates(dir): | |
| 1411 ''' List all the Roundup template directories in a given directory. | |
| 1412 | |
| 1413 Find all the dirs that contain a TEMPLATE-INFO.txt and parse it. | |
| 1414 | |
| 1415 Return a list of dicts of info about the templates. | |
| 1416 ''' | |
| 1417 ret = {} | |
| 1418 for idir in os.listdir(dir): | |
| 1419 idir = os.path.join(dir, idir) | |
| 1420 ti = loadTemplate(idir) | |
| 1421 if ti: | |
| 1422 ret[ti['name']] = ti | |
| 1423 return ret | |
| 1424 | |
| 1425 def loadTemplate(dir): | |
| 1426 ''' Attempt to load a Roundup template from the indicated directory. | |
| 1427 | |
| 1428 Return None if there's no template, otherwise a template info | |
| 1429 dictionary. | |
| 1430 ''' | |
| 1431 ti = os.path.join(dir, 'TEMPLATE-INFO.txt') | |
| 1432 if not os.path.exists(ti): | |
| 1433 return None | |
| 1434 | |
| 1435 # load up the template's information | |
| 1436 m = rfc822.Message(open(ti)) | |
| 1437 ti = {} | |
| 1438 ti['name'] = m['name'] | |
| 1439 ti['description'] = m['description'] | |
| 1440 ti['intended-for'] = m['intended-for'] | |
| 1441 ti['path'] = dir | |
| 1442 return ti | |
| 1443 | |
| 1444 if __name__ == '__main__': | 1410 if __name__ == '__main__': |
| 1445 tool = AdminTool() | 1411 tool = AdminTool() |
| 1446 sys.exit(tool.main()) | 1412 sys.exit(tool.main()) |
| 1447 | 1413 |
| 1448 # vim: set filetype=python ts=4 sw=4 et si | 1414 # vim: set filetype=python ts=4 sw=4 et si |
