blob: b94511ebd2339a5c4d4a7964b49232aa80937b56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
__all__ = ['models', 'db_from_config', 'setup_session']
import sqlalchemy, sqlalchemy.orm, ConfigParser
def db_from_config(fname='/etc/bcfg2.conf'):
cp = ConfigParser.ConfigParser()
cp.read([fname])
driver = cp.get('snapshots', 'driver')
if driver == 'sqlite':
path = cp.get('snapshots', 'database')
return 'sqlite:///%s' % path
else:
raise Exception, "not done yet"
def setup_session(debug=False):
engine = sqlalchemy.create_engine(db_from_config(),
echo=debug)
Session = sqlalchemy.orm.sessionmaker()
Session.configure(bind=engine)
return Session()
|