1
1
"""Pylons environment configuration"""
4
from ConfigParser import RawConfigParser
4
5
from jinja2 import ChoiceLoader, Environment, FileSystemLoader
6
8
from pylons.configuration import PylonsConfig
7
from sqlalchemy import engine_from_config
9
from sqlalchemy import create_engine
9
11
from sloecode.bzr.factory import BazaarRepositoryFactory
10
12
import sloecode.lib.app_globals as app_globals
45
47
config['pylons.strict_tmpl_context'] = True
47
49
# Setup the SQLAlchemy database engine
48
engine = engine_from_config(config, 'sqlalchemy.')
50
# do this by creating the engine url from components:
51
db_config = RawConfigParser()
52
db_config.read(config['db_config_file'])
54
dialect = db_config.get('database', 'dbtype')
55
# translate from dbconfig-common terminology
56
if dialect == 'sqlite3':
58
username = db_config.get('database', 'dbuser')
59
password = db_config.get('database', 'dbpass')
60
schema_name = db_config.get('database', 'dbname')
61
db_server = db_config.get('database', 'dbserver')
62
db_port = db_config.get('database', 'dbport')
63
db_path = db_config.get('database', 'dbpath')
65
# we support sqlite:// and mysql://
66
engine_url = dialect + '://'
67
# sqlite needs 4 '/''s, and needs special path options:
68
if dialect == 'sqlite':
69
engine_url += '/' + os.path.join(db_path, schema_name)
71
engine_url += "%s:%s@%s/%s" % (username, password, db_server, schema_name)
73
engine = create_engine(engine_url)
51
# CONFIGURATION OPTIONS HERE (note: all config options will override
52
# any Pylons config options)
76
# create the Bazaar factory:
53
77
config['bzr.factory'] = BazaarRepositoryFactory(
54
78
global_conf['bzr_person_root'],
55
79
global_conf['bzr_project_root'],
56
80
global_conf['bzr_deleted_person_root'],
57
81
global_conf['bzr_deleted_project_root'],
84
# This is a bit of a nasty hack: In "developer mode", we explicitly call:
86
# `paster setup-app /path/to/config.ini`
88
# Which creates all the database tables, and also created the admin user and
89
# creates the repository for the admin user - this works fine.
91
# However, in release mode, the database schema is created by dbconfig-common
92
# and upgraded from one version to the next by the same. We never get a chance
93
# to create the Bazaar repository for the admin user, which results in crashes.
95
# The following code checks to see if the repository has been created for the
96
# admin user, and creates it if it hasn't:
97
from bzrlib.errors import NotBranchError
100
repo = config['bzr.factory'].get_repository_for_person('admin')
101
except NotBranchError:
102
config['bzr.factory'].create_shared_repository_for_person('admin')