當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。