当前位置: 首页>>代码示例>>Python>>正文


Python peewee.OperationalError方法代码示例

本文整理汇总了Python中peewee.OperationalError方法的典型用法代码示例。如果您正苦于以下问题:Python peewee.OperationalError方法的具体用法?Python peewee.OperationalError怎么用?Python peewee.OperationalError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在peewee的用法示例。


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

示例1: get_entity_data

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def get_entity_data(cls, entity_type, name, **kwargs):
        """returns entity data corresponding to supplied entry using entity name"""

        cache_tables = cls.get_cache_tables()
        if not entity_type:
            LOG.error("No entity type for cache supplied")
            sys.exit(-1)

        db_cls = cache_tables.get(entity_type, None)
        if not db_cls:
            LOG.error("Unknown entity type ({}) supplied".format(entity_type))
            sys.exit(-1)

        try:
            res = db_cls.get_entity_data(name=name, **kwargs)
        except OperationalError:
            formatted_exc = traceback.format_exc()
            LOG.debug("Exception Traceback:\n{}".format(formatted_exc))
            LOG.error(
                "Cache error occurred. Please update cache using 'calm update cache' command"
            )
            sys.exit(-1)

        return res 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:26,代码来源:cache.py

示例2: get_entity_data_using_uuid

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def get_entity_data_using_uuid(cls, entity_type, uuid, *args, **kwargs):
        """returns entity data corresponding to supplied entry using entity uuid"""

        cache_tables = cls.get_cache_tables()
        if not entity_type:
            LOG.error("No entity type for cache supplied")
            sys.exit(-1)

        db_cls = cache_tables.get(entity_type, None)
        if not db_cls:
            LOG.error("Unknown entity type ({}) supplied".format(entity_type))
            sys.exit(-1)

        try:
            res = db_cls.get_entity_data_using_uuid(uuid=uuid, **kwargs)
        except OperationalError:
            formatted_exc = traceback.format_exc()
            LOG.debug("Exception Traceback:\n{}".format(formatted_exc))
            LOG.error(
                "Cache error occurred. Please update cache using 'calm update cache' command"
            )
            sys.exit(-1)

        return res 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:26,代码来源:cache.py

示例3: test_initialize_2

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def test_initialize_2(self, tmpdir_factory):
        var_dir = tmpdir_factory.mktemp('temp_var')
        test_config = var_dir.join('paper-git.cfg')
        with test_config.open(ensure=True, mode='w') as fp:
            print("""
[dropbox]
api_token: thisisanotherapikey
            """, file=fp)
        assert config.dbox is None
        assert config.db.path is None
        with pytest.raises(peewee.OperationalError):
            config.db.db.connect()
        with var_dir.as_cwd():
            initialize()
        # Make sure that the database connection works.
        assert config.db.path is not None
        assert set(config.db.db.get_tables()) == set([
            'paperdoc', 'paperfolder', 'sync'])
        assert config.dbox is not None 
开发者ID:maxking,项目名称:paper-to-git,代码行数:21,代码来源:test_core.py

示例4: check_db_sane

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def check_db_sane():
    """ Ensure DB tables exist, create them if they don't. """
    check_db_schema_version()

    missing_table_models = []

    for model in db_models():
        if not getattr(model, 'table_exists')():
            missing_table_models.append(model)
            printdbg("[warning]: Table for %s (%s) doesn't exist in DB." % (model, model._meta.db_table))

    if missing_table_models:
        printdbg("[warning]: Missing database tables. Auto-creating tables.")
        try:
            db.create_tables(missing_table_models, safe=True)
        except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
            print("[error] Could not create tables: %s" % e)

    update_schema_version()
    purge_invalid_amounts() 
开发者ID:dashpay,项目名称:sentinel,代码行数:22,代码来源:models.py

示例5: check_db_schema_version

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def check_db_schema_version():
    """ Ensure DB schema is correct version. Drop tables if not. """
    db_schema_version = None

    try:
        db_schema_version = Setting.get(Setting.name == 'DB_SCHEMA_VERSION').value
    except (peewee.OperationalError, peewee.DoesNotExist, peewee.ProgrammingError) as e:
        printdbg("[info]: Can't get DB_SCHEMA_VERSION...")

    printdbg("[info]: SCHEMA_VERSION (code) = [%s]" % SCHEMA_VERSION)
    printdbg("[info]: DB_SCHEMA_VERSION = [%s]" % db_schema_version)
    if (SCHEMA_VERSION != db_schema_version):
        printdbg("[info]: Schema version mis-match. Syncing tables.")
        try:
            existing_table_names = db.get_tables()
            existing_models = [m for m in db_models() if m._meta.db_table in existing_table_names]
            if (existing_models):
                printdbg("[info]: Dropping tables...")
                db.drop_tables(existing_models, safe=False, cascade=False)
        except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
            print("[error] Could not drop tables: %s" % e) 
开发者ID:dashpay,项目名称:sentinel,代码行数:23,代码来源:models.py

示例6: is_database_correctly_configured

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def is_database_correctly_configured():
    import peewee
    import config

    configured = False

    cannot_connect_message = "Cannot connect to database. Please ensure database service is running and user access is properly configured in 'sentinel.conf'."

    try:
        db = config.db
        db.connect()
        configured = True
    except (peewee.ImproperlyConfigured, peewee.OperationalError, ImportError) as e:
        print("[error]: %s" % e)
        print(cannot_connect_message)
        sys.exit(1)

    return configured 
开发者ID:dashpay,项目名称:sentinel,代码行数:20,代码来源:init.py

示例7: query_whois_info

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def query_whois_info(self, domain):
        try:
            domain_hash = hash(domain)
            table_num = get_table_num(domain_hash)
            query_results = self.model_list[table_num].select(
            ).where(
                self.model_list[table_num].domain_hash == domain_hash,
                self.model_list[table_num].domain == domain
            )
            return query_results
        except peewee.OperationalError as e:
            raise e
        except TableChoiceError as e:
            raise e

    # 获取没有处理的域名
    # @param table_num 表序号
    # @param tld 域名后缀 
开发者ID:h-j-13,项目名称:Malicious_Domain_Whois,代码行数:20,代码来源:db_operation.py

示例8: app

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def app(request):
    from social_relay import app, database
    try:
        drop_all_tables(database)
    except (ProgrammingError, OperationalError):
        pass
    create_all_tables(database)

    def drop_db():
        drop_all_tables(database)

    request.addfinalizer(drop_db)

    return app 
开发者ID:jaywink,项目名称:social-relay,代码行数:16,代码来源:conftest.py

示例9: sync

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def sync(cls):
        """Sync cache by latest data"""

        def sync_tables(tables):
            for table in tables:
                table.sync()
                click.echo(".", nl=False, err=True)

        cache_table_map = cls.get_cache_tables()
        tables = list(cache_table_map.values())

        # Inserting version table at start
        tables.insert(0, Version)

        try:
            LOG.info("Updating cache", nl=False)
            sync_tables(tables)

        except (OperationalError, IntegrityError):
            click.echo(" [Fail]")
            # init db handle once (recreating db if some schema changes are there)
            LOG.info("Removing existing db and updating cache again")
            init_db_handle()
            LOG.info("Updating cache", nl=False)
            sync_tables(tables)
            click.echo(" [Done]", err=True) 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:28,代码来源:cache.py

示例10: show_data

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def show_data(cls):
        """Display data present in cache tables"""

        cache_tables = cls.get_cache_tables()
        for cache_type, table in cache_tables.items():
            click.echo("\n{}".format(cache_type.upper()))
            try:
                table.show_data()
            except OperationalError:
                formatted_exc = traceback.format_exc()
                LOG.debug("Exception Traceback:\n{}".format(formatted_exc))
                LOG.error(
                    "Cache error occurred. Please update cache using 'calm update cache' command"
                )
                sys.exit(-1) 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:17,代码来源:cache.py

示例11: _post_initialization

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def _post_initialization(self):
        from papergit.models import PaperDoc, PaperFolder, Sync
        try:
            self.db.create_tables([PaperDoc, PaperFolder, Sync])
        except OperationalError as e:
            if "already exists" in str(e):
                return
            raise 
开发者ID:maxking,项目名称:paper-to-git,代码行数:10,代码来源:database.py

示例12: add_uniquie_basename_index

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def add_uniquie_basename_index(migrator, db):
    try:
        migrate(
            migrator.add_index('packagefile', ('basename',), True)
        )
    except (OperationalError, ProgrammingError):
        pass 
开发者ID:mosquito,项目名称:pypi-server,代码行数:9,代码来源:005_packagefile_basename_unique.py

示例13: execute_sql

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def execute_sql(self, sql, params=None, commit=SENTINEL):
        try:
            return self._primary_db.execute_sql(sql, params, commit)
        except OperationalError:
            if self._fallback_db is not None:
                try:
                    return self._fallback_db.execute_sql(sql, params, commit)
                except OperationalError:
                    raise 
开发者ID:quay,项目名称:quay,代码行数:11,代码来源:readreplica.py

示例14: validate

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def validate(cls, validator_context):
        """
        Validates connecting to the database.
        """
        config = validator_context.config

        try:
            validate_database_precondition(config["DB_URI"], config.get("DB_CONNECTION_ARGS", {}))
        except OperationalError as ex:
            if ex.args and len(ex.args) > 1:
                raise ConfigValidationException(ex.args[1])
            else:
                raise ex 
开发者ID:quay,项目名称:quay,代码行数:15,代码来源:validate_database.py

示例15: validate_postgres_precondition

# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import OperationalError [as 别名]
def validate_postgres_precondition(driver):
    cursor = driver.execute_sql("SELECT extname FROM pg_extension", ("public",))
    if "pg_trgm" not in [extname for extname, in cursor.fetchall()]:
        raise OperationalError(
            """
      "pg_trgm" extension does not exists in the database.
      Please run `CREATE EXTENSION IF NOT EXISTS pg_trgm;` as superuser on this database.
    """
        ) 
开发者ID:quay,项目名称:quay,代码行数:11,代码来源:validation.py


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