• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.construct_engine函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中migrate.versioning.util.construct_engine函数的典型用法代码示例。如果您正苦于以下问题:Python construct_engine函数的具体用法?Python construct_engine怎么用?Python construct_engine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了construct_engine函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _migrate

def _migrate(url, repository, version, upgrade, err, **opts):
    engine = construct_engine(url, **opts)
    schema = ControlledSchema(engine, repository)
    version = _migrate_version(schema, version, upgrade, err)

    changeset = schema.changeset(version)
    for ver, change in changeset:
        nextver = ver + changeset.step
        print '%s -> %s... ' % (ver, nextver)

        if opts.get('preview_sql'):
            if isinstance(change, PythonScript):
                print change.preview_sql(url, changeset.step, **opts)
            elif isinstance(change, SqlScript):
                print change.source()

        elif opts.get('preview_py'):
            source_ver = max(ver, nextver)
            module = schema.repository.version(source_ver).script().module
            funcname = upgrade and "upgrade" or "downgrade"
            func = getattr(module, funcname)
            if isinstance(change, PythonScript):
                print inspect.getsource(func)
            else:
                raise UsageError("Python source can be only displayed"
                    " for python migration files")
        else:
            schema.runchange(ver, change, changeset.step)
            print 'done'
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:29,代码来源:api.py


示例2: load_environment

def load_environment(global_conf, app_conf):
    """\
    Configure the Pylons environment via the ``pylons.config`` object
    """

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(
        global_conf,
        app_conf,
        package='openspending.ui',
        paths=paths)

    config['routes.map'] = routing.make_map()
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = helpers

    # set log level in markdown
    markdown.logger.setLevel(logging.WARN)

    # SQLAlchemy
    engine = engine_from_config(config, 'openspending.db.')
    engine = construct_engine(engine)
    init_model(engine)

    # Configure Solr
    import openspending.lib.solr_util as solr
    solr.configure(config)
开发者ID:ToroidalATLAS,项目名称:openspending,代码行数:34,代码来源:environment.py


示例3: __init__

 def __init__(self, url, schema=None, reflectMetadata=True, row_type=dict):
     kw = {}
     if url.startswith('postgres'):
         kw['poolclass'] = NullPool
     self.lock = threading.RLock()
     self.local = threading.local()
     if '?' in url:
         url, query = url.split('?', 1)
         query = parse_qs(query)
         if schema is None:
             # le pop
             schema_qs = query.pop('schema', query.pop('searchpath', []))
             if len(schema_qs):
                 schema = schema_qs.pop()
         if len(query):
             url = url + '?' + urlencode(query, doseq=True)
     self.schema = schema
     engine = create_engine(url, **kw)
     self.url = url
     self.engine = construct_engine(engine)
     self.metadata = MetaData(schema=schema)
     self.metadata.bind = self.engine
     if reflectMetadata:
         self.metadata.reflect(self.engine)
     self.row_type = row_type
     self._tables = {}
开发者ID:jonathaneunice,项目名称:dataset,代码行数:26,代码来源:database.py


示例4: drop_version_control

def drop_version_control(url, repository, **opts):
    """%prog drop_version_control URL REPOSITORY_PATH

    Removes version control from a database.
    """
    engine = construct_engine(url, **opts)
    schema = ControlledSchema(engine, repository)
    schema.drop()
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:8,代码来源:api.py


示例5: create_model

def create_model(url, repository, **opts):
    """%prog create_model URL REPOSITORY_PATH

    Dump the current database as a Python model to stdout.

    NOTE: This is EXPERIMENTAL.
    """  # TODO: get rid of EXPERIMENTAL label
    engine = construct_engine(url, **opts)
    declarative = opts.get('declarative', False)
    print ControlledSchema.create_model(engine, repository, declarative)
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:10,代码来源:api.py


示例6: compare_model_to_db

def compare_model_to_db(url, model, repository, **opts):
    """%prog compare_model_to_db URL MODEL REPOSITORY_PATH

    Compare the current model (assumed to be a module level variable
    of type sqlalchemy.MetaData) against the current database.

    NOTE: This is EXPERIMENTAL.
    """  # TODO: get rid of EXPERIMENTAL label
    engine = construct_engine(url, **opts)
    print ControlledSchema.compare_model_to_db(engine, model, repository)
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:10,代码来源:api.py


示例7: patched_with_engine

def patched_with_engine(f, *a, **kw):
    url = a[0]
    engine = migrate_util.construct_engine(url, **kw)
    try:
        kw['engine'] = engine
        return f(*a, **kw)
    finally:
        if isinstance(engine, migrate_util.Engine) and engine is not url:
            migrate_util.log.debug('Disposing SQLAlchemy engine %s', engine)
            engine.dispose()
开发者ID:AsherBond,项目名称:heat,代码行数:10,代码来源:migration.py


示例8: connect

def connect(url):
    """ Create an engine for the given database URL. """
    kw = {}
    if url.startswith('postgres'):
        kw['pool_size'] = 1
    engine = create_engine(url, **kw)
    engine = construct_engine(engine)
    meta = MetaData()
    meta.bind = engine
    engine._metadata = meta
    return engine
开发者ID:asuffield,项目名称:sqlaload,代码行数:11,代码来源:schema.py


示例9: make_update_script_for_model

def make_update_script_for_model(url, oldmodel, model, repository, **opts):
    """%prog make_update_script_for_model URL OLDMODEL MODEL REPOSITORY_PATH

    Create a script changing the old Python model to the new (current)
    Python model, sending to stdout.

    NOTE: This is EXPERIMENTAL.
    """  # TODO: get rid of EXPERIMENTAL label
    engine = construct_engine(url, **opts)
    print PythonScript.make_update_script_for_model(
        engine, oldmodel, model, repository, **opts)
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:11,代码来源:api.py


示例10: preview_sql

    def preview_sql(self, url, step, **args):
        """Mock engine to store all executable calls in a string \
        and execute the step"""
        buf = StringIO()
        args['engine_arg_strategy'] = 'mock'
        args['engine_arg_executor'] = lambda s, p='': buf.write(s + p)
        engine = construct_engine(url, **args)

        self.run(engine, step)

        return buf.getvalue()
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:11,代码来源:py.py


示例11: db_version

def db_version(url, repository, **opts):
    """%prog db_version URL REPOSITORY_PATH

    Show the current version of the repository with the given
    connection string, under version control of the specified
    repository.

    The url should be any valid SQLAlchemy connection string.
    """
    engine = construct_engine(url, **opts)
    schema = ControlledSchema(engine, repository)
    return schema.version
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:12,代码来源:api.py


示例12: __init__

 def __init__(self, url):
     kw = {}
     if url.startswith('postgres'):
         kw['poolclass'] = NullPool
     engine = create_engine(url, **kw)
     self.lock = RLock()
     self.url = url
     self.engine = construct_engine(engine)
     self.metadata = MetaData()
     self.metadata.bind = self.engine
     self.metadata.reflect(self.engine)
     self._tables = {}
开发者ID:CARocha,项目名称:dataset,代码行数:12,代码来源:database.py


示例13: update_db_from_model

def update_db_from_model(url, model, repository, **opts):
    """%prog update_db_from_model URL MODEL REPOSITORY_PATH

    Modify the database to match the structure of the current Python
    model. This also sets the db_version number to the latest in the
    repository.

    NOTE: This is EXPERIMENTAL.
    """  # TODO: get rid of EXPERIMENTAL label
    engine = construct_engine(url, **opts)
    schema = ControlledSchema(engine, repository)
    schema.update_db_from_model(model)
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:12,代码来源:api.py


示例14: load_environment

def load_environment(global_conf, app_conf):
    """\
    Configure the Pylons environment via the ``pylons.config`` object
    """

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='openspending.ui', paths=paths)

    config['routes.map'] = routing.make_map()
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = helpers

    # set log level in markdown
    markdown.logger.setLevel(logging.WARN)

    # Establish celery loader:
    from openspending.command import celery

    # Translator (i18n)
    config['openspending.ui.translations'] = MultiDomainTranslator([config.get('lang', 'en')])
    translator = Translator(config['openspending.ui.translations'])
    def template_loaded(template):
        translator.setup(template)

    template_paths = [paths['templates'][0]]
    extra_template_paths = config.get('extra_template_paths', '')
    if extra_template_paths:
        # must be first for them to override defaults
        template_paths = extra_template_paths.split(',') + template_paths

    # Create the Genshi TemplateLoader
    config['pylons.app_globals'].genshi_loader = TemplateLoader(
        search_path=template_paths,
        auto_reload=True,
        callback=template_loaded
    )

    # SQLAlchemy
    engine = engine_from_config(config, 'openspending.db.')
    engine = construct_engine(engine)
    init_model(engine)

    # Configure Solr
    import openspending.lib.solr_util as solr
    solr.configure(config)
开发者ID:AlbertoPeon,项目名称:openspending,代码行数:52,代码来源:environment.py


示例15: setup_database

    def setup_database(self):
        """
        Configure the database based on the provided configuration
        file, but be sure to overwrite the url so that it will use
        sqlite in memory, irrespective of what the user has set in
        test.ini. Construct the sqlalchemy engine with versioning
        and initialise everything.
        """

        config['openspending.db.url'] = 'sqlite:///:memory:'
        engine = engine_from_config(config, 'openspending.db.')
        engine = construct_engine(engine)
        init_model(engine)
开发者ID:ToroidalATLAS,项目名称:openspending,代码行数:13,代码来源:base.py


示例16: connect

def connect(url):
    """ Create an engine for the given database URL. """
    kw = {}
    if url.startswith('postgres'):
        #kw['pool_size'] = 5
        from sqlalchemy.pool import NullPool
        kw['poolclass'] = NullPool
    engine = create_engine(url, **kw)
    engine = construct_engine(engine)
    meta = MetaData()
    meta.bind = engine
    engine._metadata = meta
    return engine
开发者ID:rossjones,项目名称:sqlaload,代码行数:13,代码来源:schema.py


示例17: setup_package

def setup_package():
    '''
    Create a new, not scoped  global sqlalchemy session
    and rebind it to a new root transaction to which we can roll
    back. Otherwise :func:`adhocracy.model.init_model`
    will create as scoped session and invalidates
    the connection we need to begin a new root transaction.

    Return: The new root `connection`
    '''
    from sqlalchemy import engine_from_config
    from migrate.versioning.util import construct_engine
    config['openspending.db.url'] = 'sqlite:///:memory:'
    engine = engine_from_config(config, 'openspending.db.')
    engine = construct_engine(engine)
    init_model(engine)
开发者ID:AlbertoPeon,项目名称:openspending,代码行数:16,代码来源:__init__.py


示例18: load_environment

def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='openspending.etl.ui', paths=paths)

    config['routes.map'] = make_map()
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = helpers

    # set log level in markdown
    markdown.logger.setLevel(logging.WARN)

    ## redo template setup to use genshi.search_path (so remove std template setup)
    template_paths = [paths['templates'][0]]

    # Translator (i18n)
    config['openspending.etl.ui.translations'] = MultiDomainTranslator([config.get('lang', 'en')])
    translator = Translator(config['openspending.etl.ui.translations'])

    def template_loaded(template):
        translator.setup(template)

    config['pylons.app_globals'].genshi_loader = TemplateLoader(
        template_paths, auto_reload=True, callback=template_loaded)

    # SQLAlchemy
    engine = engine_from_config(config, 'openspending.db.')
    engine = construct_engine(engine)
    init_model(engine)

    # Configure ckan
    import openspending.etl.importer.ckan as ckan
    ckan.configure(config)

    # Configure Solr
    import openspending.lib.solr_util as solr
    solr.configure(config)
开发者ID:jagarcias,项目名称:openspending.etl,代码行数:47,代码来源:environment.py


示例19: __init__

 def __init__(self, url, search_path):
     kw = {}
     if url.startswith('postgres'):
         kw['poolclass'] = NullPool
     engine = create_engine(url, **kw)
     self.lock = RLock()
     self.url = url
     self.search_path = search_path
     self.engine = construct_engine(engine)
     self.metadata = MetaData()
     self.metadata.bind = self.engine
     if self.search_path and url.startswith('postgres'):
         for schema in self.search_path:
             self.metadata.reflect(self.engine, schema=schema)
     else:
         self.metadata.reflect(self.engine)
     self._tables = {}
开发者ID:aklaver,项目名称:dataset,代码行数:17,代码来源:database.py


示例20: _migrate

    def _migrate(self, repository, version, upgrade, **opts):
        engine = construct_engine(self.url, **opts)
        schema = api.ControlledSchema(engine, repository)
        version = self._migrate_version(schema, version, upgrade)

        yield "<h2>Migrating %s</h2>\n" % repository.id

        changeset = schema.changeset(version)
        if not changeset:
            yield "<p>This repository is already up to date.</p>\n"
            return

        for ver, change in changeset:
            nextver = ver + changeset.step
            doc = schema.repository.version(max(ver, nextver)).script().module.__doc__
            yield "<h3>Version %s -> %s - %s</h3>\n" % (ver, nextver, doc)
            for message in schema.runchange(ver, change, changeset.step):
                yield message
            yield "\n<p>Done!</p>\n"
开发者ID:avacariu,项目名称:zine,代码行数:19,代码来源:__init__.py



注:本文中的migrate.versioning.util.construct_engine函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python text_effects.fprint函数代码示例发布时间:2022-05-27
下一篇:
Python shell.main函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap