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

Python locals.create_database函数代码示例

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

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



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

示例1: test_check_unmodifiable_strings

    def test_check_unmodifiable_strings(self):
        # This test case asserts that data migration updates unmodifiable l10n strings
        self._initStartDB(34)

        notification_l10n = NotificationL10NFactory(self.store)

        t0 = notification_l10n.get_val("export_template", "it")

        notification_l10n.set_val("export_template", "it", "")

        t1 = notification_l10n.get_val("export_template", "it")

        self.assertEqual(t1, "")

        self.store.commit()

        # place a dummy version in the current db
        store = Store(create_database(GLSettings.db_uri))
        prv = config.PrivateFactory(store)
        self.dummy_ver = "2.XX.XX"
        prv.set_val("version", self.dummy_ver)
        self.assertEqual(prv.get_val("version"), self.dummy_ver)
        store.commit()
        store.close()

        migration.perform_data_update(self.db_file)

        store = Store(create_database(GLSettings.db_uri))
        notification_l10n = NotificationL10NFactory(store)
        t2 = notification_l10n.get_val("export_template", "it")
        self.assertEqual(t2, t0)
        store.commit()
        store.close()

        shutil.rmtree(GLSettings.db_path)
开发者ID:globaleaks,项目名称:GlobaLeaks,代码行数:35,代码来源:test_migration.py


示例2: __init__

    def __init__(self, table_history, old_db_file, new_db_file, start_ver):
        self.table_history = table_history
        self.old_db_file = old_db_file
        self.new_db_file = new_db_file
        self.start_ver = start_ver

        self.std_fancy = " ł "
        self.debug_info = "   [%d => %d] " % (start_ver, start_ver + 1)

        for k, v in table_history.iteritems():
            # +1 because count start from 0,
            # -8 because the relase befor the 8th are not supported anymore
            length = DATABASE_VERSION + 1 - 8
            if len(v) != length:
                msg = 'Expecting a table with {} statuses ({})'.format(length, k)
                raise TypeError(msg)

        log.msg('{} Opening old DB: {}'.format(self.debug_info, old_db_file))
        old_database = create_database('sqlite:' + self.old_db_file)
        self.store_old = Store(old_database)

        GLSetting.db_file = new_db_file

        new_database = create_database('sqlite:' + new_db_file)
        self.store_new = Store(new_database)

        if self.start_ver + 1 == DATABASE_VERSION:
            log.msg('{} Acquire SQL schema {}'.format(self.debug_info, GLSetting.db_schema_file))

            if not os.access(GLSetting.db_schema_file, os.R_OK):
                log.msg('Unable to access', GLSetting.db_schema_file)
                raise IOError('Unable to access db schema file')

            with open(GLSetting.db_schema_file) as f:
                create_queries = ''.join(f).split(';')
                for create_query in create_queries:
                    try:
                        self.store_new.execute(create_query + ';')
                    except OperationalError:
                        log.msg('OperationalError in "{}"'.format(create_query))
            self.store_new.commit()
            return
            # return here and manage the migrant versions here:

        for k, v in self.table_history.iteritems():

            create_query = self.get_right_sql_version(k, self.start_ver + 1)
            if not create_query:
                # table not present in the version
                continue

            try:
                self.store_new.execute(create_query + ';')
            except OperationalError as excep:
                log.msg('{} OperationalError in [{}]'.format(self.debug_info, create_query))
                raise excep

        self.store_new.commit()
开发者ID:tonegas,项目名称:GlobaLeaks,代码行数:58,代码来源:base_updater.py


示例3: setUp

    def setUp(self):
        super(PatchTest, self).setUp()

        self.patchdir = self.makeDir()
        self.pkgdir = os.path.join(self.patchdir, "mypackage")
        os.makedirs(self.pkgdir)

        f = open(os.path.join(self.pkgdir, "__init__.py"), "w")
        f.write("shared_data = []")
        f.close()

        # Order of creation here is important to try to screw up the
        # patch ordering, as os.listdir returns in order of mtime (or
        # something).
        for pname, data in [("patch_380.py", patch_test_1),
                            ("patch_42.py", patch_test_0)]:
            self.add_module(pname, data)

        sys.path.append(self.patchdir)

        self.filename = self.makeFile()
        self.uri = "sqlite:///%s" % self.filename
        self.store = Store(create_database(self.uri))

        self.store.execute("CREATE TABLE patch "
                           "(version INTEGER NOT NULL PRIMARY KEY)")

        self.assertFalse(self.store.get(Patch, (42)))
        self.assertFalse(self.store.get(Patch, (380)))

        import mypackage
        self.mypackage = mypackage

        # Create another connection just to keep track of the state of the
        # whole transaction manager.  See the assertion functions below.
        self.another_store = Store(create_database("sqlite:"))
        self.another_store.execute("CREATE TABLE test (id INT)")
        self.another_store.commit()
        self.prepare_for_transaction_check()

        class Committer(object):

            def commit(committer):
                self.store.commit()
                self.another_store.commit()

            def rollback(committer):
                self.store.rollback()
                self.another_store.rollback()

        self.committer = Committer()
        self.patch_applier = PatchApplier(self.store, self.mypackage,
                                          self.committer)
开发者ID:DamnWidget,项目名称:mamba-storm,代码行数:53,代码来源:patch.py


示例4: test_detect_and_fix_cfg_change

    def test_detect_and_fix_cfg_change(self):
        store = Store(create_database(GLSettings.db_uri))
        ret = config.is_cfg_valid(store)
        self.assertFalse(ret)
        store.close()

        migration.perform_data_update(self.db_file)

        store = Store(create_database(GLSettings.db_uri))
        prv = config.PrivateFactory(store)
        self.assertEqual(prv.get_val('version'), __version__)
        self.assertEqual(prv.get_val('xx_smtp_password'), self.dp)
        ret = config.is_cfg_valid(store)
        self.assertTrue(ret)
        store.close()
开发者ID:Taipo,项目名称:GlobaLeaks,代码行数:15,代码来源:test_migration.py


示例5: getDB

def getDB():
    """
    I return a connection to the database
    """
    db_uri = getURI() 
    db = create_database("postgres://jburns:[email protected]/postgres")
    return db 
开发者ID:teamsonic,项目名称:wld,代码行数:7,代码来源:db.py


示例6: userDatabase

def userDatabase(uri=DB_FILE_NAME):
    """
    Give a user database
    """
    filename, uri = parseURI(uri)
    db = locals.create_database(uri)
    if filename is not None:
        # test existence of the database file so as to throw an exception when
        # the bootstrap script was not run.  Test it before creating the Store
        # because creating the Store creates the file whether it makes sense
        # to or not.
        open(filename).close()
        store = locals.Store(db)
    else:
        store = locals.Store(db)
        from .usersql import SQL_SCRIPT
        for sql in SQL_SCRIPT:
            store.execute(sql)
    assert store is not None

    global theStore  # UGLY but necessary?  many many things in resource need
                     # this; passing it around would be heinous.
    theStore = store

    return store
开发者ID:corydodt,项目名称:Goonmill,代码行数:25,代码来源:user.py


示例7: setUp

    def setUp(self):
        helpers.init_glsettings_for_unit_tests()

        GLSettings.db_path = os.path.join(GLSettings.ramdisk_path, 'db_test')
        os.mkdir(GLSettings.db_path)
        db_name = 'glbackend-%d.db' % DATABASE_VERSION
        db_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'db', 'populated', db_name)
        shutil.copyfile(db_path, os.path.join(GLSettings.db_path, db_name))

        self.db_file = os.path.join(GLSettings.db_path, db_name)
        GLSettings.db_uri = GLSettings.make_db_uri(self.db_file)

        # place a dummy version in the current db
        store = Store(create_database(GLSettings.db_uri))
        prv = config.PrivateFactory(store)
        self.dummy_ver = '2.XX.XX'
        prv.set_val('version', self.dummy_ver)
        self.assertEqual(prv.get_val('version'), self.dummy_ver)
        store.commit()
        store.close()

        # backup various mocks that we will use
        self._bck_f = config.is_cfg_valid
        GLConfig['private']['xx_smtp_password'] = GLConfig['private'].pop('smtp_password')
        self.dp = u'yes_you_really_should_change_me'
开发者ID:Taipo,项目名称:GlobaLeaks,代码行数:25,代码来源:test_migration.py


示例8: test_version_change_success

    def test_version_change_success(self):
        migration.perform_data_update(self.db_file)

        store = Store(create_database(GLSettings.db_uri))
        prv = config.PrivateFactory(store)
        self.assertEqual(prv.get_val('version'), __version__)
        store.close()
开发者ID:Taipo,项目名称:GlobaLeaks,代码行数:7,代码来源:test_migration.py


示例9: initialize

 def initialize(self, debug=None):
     """See `IDatabase`."""
     # Calculate the engine url.
     url = expand(config.database.url, config.paths)
     log.debug('Database url: %s', url)
     # XXX By design of SQLite, database file creation does not honor
     # umask.  See their ticket #1193:
     # http://www.sqlite.org/cvstrac/tktview?tn=1193,31
     #
     # This sucks for us because the mailman.db file /must/ be group
     # writable, however even though we guarantee our umask is 002 here, it
     # still gets created without the necessary g+w permission, due to
     # SQLite's policy.  This should only affect SQLite engines because its
     # the only one that creates a little file on the local file system.
     # This kludges around their bug by "touch"ing the database file before
     # SQLite has any chance to create it, thus honoring the umask and
     # ensuring the right permissions.  We only try to do this for SQLite
     # engines, and yes, we could have chmod'd the file after the fact, but
     # half dozen and all...
     self.url = url
     self._prepare(url)
     database = create_database(url)
     store = Store(database, GenerationalCache())
     database.DEBUG = (as_boolean(config.database.debug)
                       if debug is None else debug)
     self.store = store
     store.commit()
开发者ID:trevor,项目名称:mailman3,代码行数:27,代码来源:base.py


示例10: test_make_commits_transaction_once

    def test_make_commits_transaction_once(self):
        """
        L{ZStormResourceManager.make} commits schema changes only once
        across all stores, after all patch and delete statements have
        been executed.
        """
        database2 = {"name": "test2",
                     "uri": "sqlite:///%s" % self.makeFile(),
                     "schema": self.databases[0]["schema"]}
        self.databases.append(database2)
        other_store = Store(create_database(database2["uri"]))
        for store in [self.store, other_store]:
            store.execute("CREATE TABLE patch "
                          "(version INTEGER NOT NULL PRIMARY KEY)")
            store.execute("CREATE TABLE test (foo TEXT)")
            store.execute("INSERT INTO test (foo) VALUES ('data')")
            store.commit()

        with CaptureTracer() as tracer:
            zstorm = self.resource.make([])

        self.assertEqual(["COMMIT", "COMMIT"], tracer.queries[-2:])
        store1 = zstorm.get("test")
        store2 = zstorm.get("test2")
        self.assertEqual([], list(store1.execute("SELECT foo FROM test")))
        self.assertEqual([], list(store2.execute("SELECT foo FROM test")))
开发者ID:DamnWidget,项目名称:mamba-storm,代码行数:26,代码来源:testing.py


示例11: __init_database

 def __init_database(self):    
     """
     creates the sqlite database instance and checks if the database exists in biodb.
     """
     database= create_database("sqlite:%s" % biodb_sql_db_path)
     print "Created storm database from %s." % biodb_sql_db_path
     self.store= Store(database)
开发者ID:ecotox,项目名称:biodb,代码行数:7,代码来源:ncbi_taxonomy_selector.py


示例12: setup_request

def setup_request():
    # Read the configuration.
    stream = open('%s/config.yaml' % request.environ['UNISON_ROOT'])
    g.config = yaml.load(stream)
    # Set up the database.
    database = create_database(g.config['database']['string'])
    g.store = Store(database)
开发者ID:lca4,项目名称:unison-recsys,代码行数:7,代码来源:www.py


示例13: get_store

def get_store():
    global _database, _store
    if not _database:
        _database = create_database('sqlite:///%s' % db_uri)
    if not _store:
        _store = Store(_database)

    return _store
开发者ID:ratazzi,项目名称:ServicesBox-Helper,代码行数:8,代码来源:storage.py


示例14: connection

def connection():
  """Returns database connection."""
  try:
    if not flask.g.db:
      raise AttributeError()
  except (KeyError, AttributeError):
    flask.g.db = Store(create_database(flask.current_app.config['STORM_DATABASE_URI']))
  return flask.g.db
开发者ID:najeira,项目名称:valforce-tools,代码行数:8,代码来源:storm.py


示例15: setup_db

def setup_db(uri):
    db = storm.create_database(uri)
    store = storm.Store(db)

    store.execute('create table if not exists tasks(id varchar(36) not null primary key, eta datetime not null, content text)')
    store.execute('create index if not exists eta_idx on tasks(eta asc)')

    return store
开发者ID:m0n5t3r,项目名称:gruntworks,代码行数:8,代码来源:models.py


示例16: test_migration_error_with_removed_language

    def test_migration_error_with_removed_language(self):
        store = Store(create_database(GLSettings.db_uri))
        zyx = EnabledLanguage('zyx')
        store.add(zyx)
        store.commit()
        store.close()

        self.assertRaises(Exception, migration.perform_data_update, self.db_file)
开发者ID:Taipo,项目名称:GlobaLeaks,代码行数:8,代码来源:test_migration.py


示例17: __open_db

    def __open_db(self,pathname):
	#db_url = 'sqlite:/:memory:'
	db_url = 'sqlite:' + pathname
	db_url += '?debug=1'
	storm.database.DEBUG = True
	database = stm.create_database(db_url)
	store = stm.Store(database)
	return store
开发者ID:avsm,项目名称:opam-ppa-OLD,代码行数:8,代码来源:test.py


示例18: _connect

    def _connect(self):
        opts = Config()

        self.database = create_database('mysql://' + opts.db_user_out + ':'
                                        + opts.db_password_out + '@'
                                        + opts.db_hostname_out + ':'
                                        + opts.db_port_out + '/'
                                        + opts.db_database_out)
        self.store = Store(self.database)
开发者ID:brainwane,项目名称:Bicho,代码行数:9,代码来源:issues_log.py


示例19: create_store

def create_store(url, debug):
    if debug:
        storm.tracer.debug(True, stream=sys.stdout)
    database = create_database(url)
    dbtype = url.partition(":")[0]
    store = Store(database)
    dbschema = Schema(schema.CREATES[dbtype], [], [], schema)
    dbschema.upgrade(store)
    return StormStore(store, debug)
开发者ID:aslakknutsen,项目名称:kittystore,代码行数:9,代码来源:__init__.py


示例20: test_ver_change_exception

    def test_ver_change_exception(self):
        # Explicity throw an exception in managed_ver_update via is_cfg_valid
        config.is_cfg_valid = apply_gen(throw_excep)

        self.assertRaises(IOError, migration.perform_data_update, self.db_file)

        store = Store(create_database(GLSettings.db_uri))
        prv = config.PrivateFactory(store)
        self.assertEqual(prv.get_val('version'), self.dummy_ver)
        store.close()
开发者ID:Taipo,项目名称:GlobaLeaks,代码行数:10,代码来源:test_migration.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python locals.Store类代码示例发布时间:2022-05-27
下一篇:
Python info.get_obj_info函数代码示例发布时间: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