def load_config_daemons(): if config_has_section(Sections.Main) and config_has_option(Sections.Main, 'daemons'): daemons = config_get(Sections.Main, 'daemons') daemons = daemons.split(',') daemons = [d.strip() for d in daemons] return daemons return []
def setup_logging(name): """ Setup logging """ if config_has_section('common') and config_has_option( 'common', 'loglevel'): loglevel = getattr(logging, config_get('common', 'loglevel').upper()) else: loglevel = logging.INFO if config_has_section('common') and config_has_option('common', 'logdir'): logging.basicConfig( filename=os.path.join(config_get('common', 'logdir'), name), level=loglevel, format='%(asctime)s\t%(threadName)s\t%(levelname)s\t%(message)s') else: logging.basicConfig( stream=sys.stdout, level=loglevel, format='%(asctime)s\t%(threadName)s\t%(levelname)s\t%(message)s')
def check_rest_host(): """ Function to check whether rest host is defined in config. To be used to decide whether to skip some test functions. :returns True: if rest host is available. Otherwise False. """ if config_has_option('rest', 'host'): host = config_get('rest', 'host') if host: return True return False
def check_database(): """ Function to check whether database is defined in config. To be used to decide whether to skip some test functions. :returns True: if database.default is available. Otherwise False. """ if config_has_option('database', 'default'): database = config_get('database', 'default') if database: return True return False
from threading import Lock from os.path import basename from sqlalchemy import create_engine, event from sqlalchemy.exc import DatabaseError, DisconnectionError, OperationalError, TimeoutError from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session from ess.common.config import config_get, config_has_option from ess.common.exceptions import ESSException, DatabaseException DATABASE_SECTION = 'database' BASE = declarative_base() if config_has_option(DATABASE_SECTION, 'schema'): DEFAULT_SCHEMA_NAME = config_get(DATABASE_SECTION, 'schema') if DEFAULT_SCHEMA_NAME: BASE.metadata.schema = DEFAULT_SCHEMA_NAME _MAKER, _ENGINE, _LOCK = None, None, Lock() def _fk_pragma_on_connect(dbapi_con, con_record): # Hack for previous versions of sqlite3 try: dbapi_con.execute('pragma foreign_keys=ON') except AttributeError: pass