Skip to content

Instantly share code, notes, and snippets.

@ejucovy
Last active December 14, 2015 11:29
Show Gist options
  • Save ejucovy/5079195 to your computer and use it in GitHub Desktop.
Save ejucovy/5079195 to your computer and use it in GitHub Desktop.
Initializing a new trac database for an existing environment.
from trac.env import Environment
from trac.db import DatabaseManager
from trac import db_default
env = Environment("/path/to/my/env")
DatabaseManager(env).init_db()
with env.db_transaction as db:
for table, cols, vals in db_default.get_data(db):
db.executemany("INSERT INTO %s (%s) VALUES (%s)" % (table, ','.join(cols), ','.join(['%s' for c in cols])), vals)
import pkg_resources
from trac.wiki.admin import WikiAdmin
pages_dir = pkg_resources.resource_filename('trac.wiki', 'default-pages')
WikiAdmin(env).load_pages(pages_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment