Exemple #1
0
 def __setup_thelma(self, ini_file):
     here_dir = os.getcwd()
     config_uri = 'config:%s' % ini_file
     self.logging_file_config(ini_file) # pylint: disable=E1101
     settings = appconfig(config_uri, 'thelma', relative_to=here_dir)
     reg = Registry('thelma')
     # Some tools need to resolve URLs, so we need to set up a request
     # and a service.
     url = 'http://0.0.0.0:6543'
     req = DummyRequest(application_url=url,
                        host_url=url,
                        path_url=url,
                        url=url,
                        registry=reg)
     config = create_config(settings, registry=reg)
     config.setup_registry(settings=settings)
     config.begin(request=req)
     config.load_zcml('configure.zcml')
     srvc = config.get_registered_utility(IService)
     req.root = srvc
     # Set up repositories.
     repo_mgr = config.get_registered_utility(IRepositoryManager)
     repo_mgr.initialize_all()
     # Start the everest service.
     srvc.start()
     # Configure the session maker.
     session_maker.configure(extension=ZopeTransactionExtension())
     # Set up machinery to enforce a session.flush() just before the
     # report is run so we have proper IDs in the output.
     # FIXME: This should be encapsulated better, perhaps depending on
     #        an option that selects the backend.
     def on_session_begin(session, trx, conn): # pylint: disable=W0613
         self._report_callback = lambda sess = session: sess.flush()
     event.listen(Session, 'after_begin', on_session_begin)
     return config
Exemple #2
0
def setup_thelma(thelma_settings):
    # Create source DB session.
    src_db_string = "postgresql+psycopg2://%s:%s@%s:%s/%s" \
                       % (DB_USER, DB_PWD, SOURCE_DB_HOST,
                          SOURCE_DB_PORT, SOURCE_DB_NAME)
    src_engine = create_engine(src_db_string)
    src_session_maker = sessionmaker(bind=src_engine)
    src_sess = src_session_maker()
    # Initialize TheLMA and create target DB session.
    reg = Registry('thelma')
    config = create_config(thelma_settings, registry=reg)
    config.setup_registry(settings=thelma_settings)
    config.begin()
    config.load_zcml('configure.zcml')
    repo_mgr = config.get_registered_utility(IRepositoryManager)
    repo_mgr.initialize_all()
    tgt_engine = get_engine(REPOSITORY_TYPES.RDB)
    tgt_session_maker = sessionmaker(bind=tgt_engine)
    tgt_sess = tgt_session_maker()
    return src_sess, tgt_sess
Exemple #3
0
    def __setup_thelma(self, ini_file):
        here_dir = os.getcwd()
        config_uri = 'config:%s' % ini_file
        self.logging_file_config(ini_file)  # pylint: disable=E1101
        settings = appconfig(config_uri, 'thelma', relative_to=here_dir)
        reg = Registry('thelma')
        # Some tools need to resolve URLs, so we need to set up a request
        # and a service.
        url = 'http://0.0.0.0:6543'
        req = DummyRequest(application_url=url,
                           host_url=url,
                           path_url=url,
                           url=url,
                           registry=reg)
        config = create_config(settings, registry=reg)
        config.setup_registry(settings=settings)
        config.begin(request=req)
        config.load_zcml('configure.zcml')
        srvc = config.get_registered_utility(IService)
        req.root = srvc
        # Set up repositories.
        repo_mgr = config.get_registered_utility(IRepositoryManager)
        repo_mgr.initialize_all()
        # Start the everest service.
        srvc.start()
        # Configure the session maker.
        session_maker.configure(extension=ZopeTransactionExtension())

        # Set up machinery to enforce a session.flush() just before the
        # report is run so we have proper IDs in the output.
        # FIXME: This should be encapsulated better, perhaps depending on
        #        an option that selects the backend.
        def on_session_begin(session, trx, conn):  # pylint: disable=W0613
            self._report_callback = lambda sess=session: sess.flush()

        event.listen(Session, 'after_begin', on_session_begin)
        return config