Python peewee.OperationalError() Examples
The following are 26
code examples of peewee.OperationalError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
peewee
, or try the search function
.
Example #1
Source File: cache.py From calm-dsl with Apache License 2.0 | 6 votes |
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
Example #2
Source File: cache.py From calm-dsl with Apache License 2.0 | 6 votes |
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
Example #3
Source File: test_core.py From paper-to-git with Apache License 2.0 | 6 votes |
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
Example #4
Source File: models.py From sentinel with MIT License | 6 votes |
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)
Example #5
Source File: init.py From sentinel with MIT License | 6 votes |
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
Example #6
Source File: db_operation.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 6 votes |
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 域名后缀
Example #7
Source File: api_db_operation.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def get_proxy_ip(self): try: query_results = proxy.select( proxy.whois_server_ip, proxy.ip, proxy.port, proxy.mode, proxy.speed ).where( proxy.speed != None, proxy.speed < 1 ) return query_results except peewee.OperationalError as e: raise e
Example #8
Source File: conftest.py From social-relay with GNU Affero General Public License v3.0 | 5 votes |
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
Example #9
Source File: api_db_operation.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def get_server_ip(self): try: query_results = svr_ip.select( svr_ip.svr_name, svr_ip.ip, svr_ip.port_available ).where( svr_ip.port_available!=None ) return query_results except peewee.OperationalError as e: raise e # 获取proxy_ip 信息
Example #10
Source File: db_operation.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def get_server_ip(self): try: query_results = svr_ip.select( svr_ip.svr_name, svr_ip.ip, svr_ip.port_available ).where( svr_ip.port_available!=None ) return query_results except peewee.OperationalError as e: raise e
Example #11
Source File: db_operation.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def get_tld(self, whois_server): try: query_results = self.whois_addr_model.select( self.whois_addr_model.tld ).where( peewee.R('addr like %s', '%,' + whois_server) | peewee.R('addr like %s', whois_server + ',%') | peewee.R('addr = %s', whois_server), self.whois_addr_model.addr <> '' ) return query_results except peewee.OperationalError as e: raise e
Example #12
Source File: db_operation.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def query_all_whois_addr(self): try: query_results = self.whois_addr_model.select().where( self.whois_addr_model.addr is not None ) return query_results except peewee.OperationalError as e: print e # 获取whois_server对应的tld
Example #13
Source File: db_operation.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def delete_whois_info(self, domain): try: domain_hash = hash(domain) table_num = get_table_num(domain_hash) event = self.model_list[table_num].delete().where( self.model_list[table_num].domain_hash == domain_hash, self.model_list[table_num].domain == domain ) event.execute() except peewee.OperationalError as e: print e
Example #14
Source File: db_operation.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def insert_whois_info(self, **domain_whois): try: table_num = get_table_num(domain_whois['domain_hash']) event = self.model_list[table_num].insert( domain_hash=domain_whois['domain_hash'], domain=domain_whois['domain'], tld=domain_whois['domain'].split('.')[-1], flag=domain_whois['flag'], domain_status=domain_whois['domain_status'], sponsoring_registrar=domain_whois['sponsoring_registrar'], top_whois_server=domain_whois['top_whois_server'], sec_whois_server=domain_whois['sec_whois_server'], reg_name=domain_whois['reg_name'], reg_phone=domain_whois['reg_phone'], reg_email=domain_whois['reg_email'], org_name=domain_whois['org_name'], name_server=domain_whois['name_server'], creation_date=domain_whois['creation_date'], expiration_date=domain_whois['expiration_date'], updated_date=domain_whois['updated_date'], insert_time=domain_whois['insert_time'], details=domain_whois['details'], whois_hash=domain_whois['whois_hash'] ) event.execute() except peewee.OperationalError as e: print e except TableChoiceError as e: print e # 删除域名的whois信息
Example #15
Source File: db_operation.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def update_whois_info(self, **domain_whois): try: table_num = get_table_num(domain_whois['domain_hash']) event = self.model_list[table_num].update( flag=domain_whois['flag'], domain_status=domain_whois['domain_status'], sponsoring_registrar=domain_whois['sponsoring_registrar'], top_whois_server=domain_whois['top_whois_server'], sec_whois_server=domain_whois['sec_whois_server'], reg_name=domain_whois['reg_name'], reg_phone=domain_whois['reg_phone'], reg_email=domain_whois['reg_email'], org_name=domain_whois['org_name'], name_server=domain_whois['name_server'], creation_date=domain_whois['creation_date'], expiration_date=domain_whois['expiration_date'], updated_date=domain_whois['updated_date'], insert_time=domain_whois['insert_time'], details=domain_whois['details'], whois_hash=domain_whois['whois_hash'] ).where( self.model_list[table_num].domain_hash == domain_whois['domain_hash'], self.model_list[table_num].domain == domain_whois['domain'] ) event.execute() except peewee.OperationalError as e: print e except TableChoiceError as e: print e
Example #16
Source File: db_operation.py From Malicious_Domain_Whois with GNU General Public License v3.0 | 5 votes |
def get_not_deal_domains(self, table_num, finished_tld): try: result_list = [] for tld in finished_tld: query_results = self.model_list[table_num].select( self.model_list[table_num].domain ).where( self.model_list[table_num].flag == -100, self.model_list[table_num].tld == tld ).limit(1000) for result in query_results: result_list.append(result.domain) # str_eval = """self.model_list[table_num].select( # self.model_list[table_num].domain # ).where( # self.model_list[table_num].flag == -100).where( # """ # for tld in finished_tld: # str_eval += "self.model_list[table_num].tld == '{tld}'|".format(tld=str(tld)) # str_eval = str_eval.strip('|') + ').limit(10000)' # # print str_eval # query_results = eval(str_eval) # return query_results return result_list except peewee.OperationalError as e: raise e # 更新whois信息
Example #17
Source File: database.py From aiopeewee with MIT License | 5 votes |
def connect(self, safe=True): if self.deferred: raise OperationalError('Database has not been initialized') if not self.closed: if safe: return raise OperationalError('Connection already open') with self.exception_wrapper: self.pool = await self._connect(self.database, **self.connect_kwargs) self.closed = False
Example #18
Source File: database.py From aiopeewee with MIT License | 5 votes |
def get_conn(self): if self.closed: raise OperationalError('Database pool has not been initialized') return AioConnection(self.pool.acquire(), autocommit=self.autocommit, autorollback=self.autorollback, exception_wrapper=self.exception_wrapper)
Example #19
Source File: validation.py From quay with Apache License 2.0 | 5 votes |
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. """ )
Example #20
Source File: validate_database.py From quay with Apache License 2.0 | 5 votes |
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
Example #21
Source File: readreplica.py From quay with Apache License 2.0 | 5 votes |
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
Example #22
Source File: 005_packagefile_basename_unique.py From pypi-server with MIT License | 5 votes |
def add_uniquie_basename_index(migrator, db): try: migrate( migrator.add_index('packagefile', ('basename',), True) ) except (OperationalError, ProgrammingError): pass
Example #23
Source File: database.py From paper-to-git with Apache License 2.0 | 5 votes |
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
Example #24
Source File: cache.py From calm-dsl with Apache License 2.0 | 5 votes |
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)
Example #25
Source File: cache.py From calm-dsl with Apache License 2.0 | 5 votes |
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)
Example #26
Source File: models.py From sentinel with MIT License | 4 votes |
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()