You can script something like this:
import trac.admin.console
import trac.config
import os
def _get_project_options(envdir):
confpath = os.path.join(envdir, 'conf/trac.ini')
config = trac.config.Configuration(confpath)
return dict([x for x in config.options(u'project')])
def _get_project_name(envdir):
admin = trac.admin.console.TracAdmin(envdir)
if admin.env_check():
options = _get_project_options(envdir)
return options[u'name']
else:
return None
def iter_trac_projects_from_dir(dirname):
for which in os.listdir(dirname):
if not which in ('.', '..') and os.path.isdir(dirname):
envdirname = os.path.join(dirname, which)
project_name = _get_project_name(envdirname)
if project_name:
yield (project_name, envdirname)
def get_trac_projects_from_dir(dirname):
return [pr for pr in iter_trac_projects_from_dir(dirname)]
Then you can use either iter_trac_projects_from_dir
or get_trac_projects_from_dir
whichever you think is best for you.
Alternatively you could use the function get_enviroments
from module trac.web.main
but only as alternative to os.listdir
-- you would still have to check whether or not each alleged env is really a trac environment. See why:
>>> import trac.web.main
>>> env = {'trac.env_parent_dir':
... '/home/manu/tmp'}
>>> trac.web.main.get_environments(env)
{'test': '/home/manu/tmp/test', 'no-a-real-trac-project': '/home/manu/tmp/no-a-real-trac-project', 'test2': '/home/manu/tmp/test2'}