def init_session(override_session=None):
    global DBSession
    if override_session:
        DBSession = override_session
    else:
        DBSession = scoped_session(
            sessionmaker(extension=ZopeTransactionExtension(),
                         class_=MySession))
示例#2
0
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    logging.getLogger('sqlalchemy.engine').setLevel(logging.ERROR)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session = sessionmaker(extension=ZopeTransactionExtension())  # noqa
    session = Session(bind=engine)
    configure_es_from_config(settings)

    with transaction.manager:
        fill_index(session)
示例#3
0
from sqlalchemy.orm import scoped_session, sessionmaker
import sqlalchemy.types as types
import sqlalchemy as sa
from horus.models import GroupMixin
from horus.models import UserMixin
from horus.models import UserGroupMixin
from horus.models import ActivationMixin
from horus.models import BaseModel
from zope.sqlalchemy.datamanager import ZopeTransactionExtension
from pyramid.i18n import TranslationStringFactory
from hem.db import get_session

import cjson as json
import operator

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base(cls=BaseModel)

_ = TranslationStringFactory('jobinator')

OPERATORS = ('==', '!=', '<', '>')
OPERATORS = map(lambda x: (x, x), OPERATORS)

FACT_TYPE_BOOL = 'bool'
FACT_TYPE_NUMBER = 'number'

FACT_TYPES = (FACT_TYPE_BOOL, FACT_TYPE_NUMBER)
FACT_TYPES = map(lambda x: (x, x), FACT_TYPES)

FACT_LIST = map(lambda x: (x, sa.Boolean, False), ('jQuery', 'Web', 'J2EE', 'Git', 'Java',
                    'RDBMS', 'NoSQL', 'Flask', 'JavaScript', 'Redis', 'CVS', 'Rails',
示例#4
0
def get_sessionmaker(bind=None):
    return sessionmaker(extension=ZopeTransactionExtension(),
                        class_=MySession,
                        bind=bind)