2 import sqlalchemy.ext.declarative
5 import CondCore.Utilities.credentials
as auth
7 prod_db_service = [
'cms_orcon_prod',
'cms_orcon_prod/cms_cond_general_w']
8 dev_db_service = [
'cms_orcoff_prep',
'cms_orcoff_prep/cms_test_conditions']
9 schema_dict = {
'cms_orcon_prod':
'CMS_COND_O2O',
'cms_orcoff_prep':
'CMS_COND_STRIP'}
10 sqlalchemy_tpl =
'oracle://%s:%s@%s' 11 coral_tpl =
'oracle://%s/%s' 12 private_db =
'sqlite:///post_o2o.db' 13 authPathEnvVar =
'COND_AUTH_PATH' 15 _Base = sqlalchemy.ext.declarative.declarative_base()
19 name = re.sub(
'Def$',
'', base_class.__name__)
21 members[
'__tablename__'] = base_class.__tablename__
22 members[
'__table_args__'] =
None 25 members[
'__table_args__'] = {
'schema' : schema}
26 dbType = type(name, (_Base, base_class), members)
40 raise RuntimeError(
'Option db(=%s) is not in the supported database list: [prod, dev, private]' % db)
42 logging.info(
'Connecting to %s database' % self.
db_service[0]
if self.
db_service else private_db)
51 if force_schema
and self.
schema:
53 username, _, pwd = auth.get_credentials(authPathEnvVar, authEntry, self.
authFile)
54 url = sqlalchemy_tpl % (username, pwd, self.
db_service[0])
59 if not self.engine.has_table(table_def.__tablename__, self.
schema):
60 logging.info(
'Creating table %s on %s' % (table_def.__tablename__,
63 table_class.__table__.create(bind=self.
engine)
64 self.
session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=self.
engine))
67 engine = sqlalchemy.create_engine(url)
if url
else self.
engine 68 session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=engine))
def connect(self, url=None)
def check_table(self, table_def, table_class)
def __init__(self, db, authFile=None)
def get_url(self, force_schema=False)
def make_dbtype(base_class, schema=None)