示例#1
0
def ini_settings(request, test_config_path) -> dict:
    """Load INI settings for test run from py.test command line.

    Example:

         py.test yourpackage -s --ini=test.ini


    :return: A dictionary representing the key/value pairs in an ``app`` section within the file represented by ``config_uri``
    """

    # This enables our INI inclusion mechanism
    # TODO: Don't use get_appsettings() from paster, but create a INI includer compatible version
    from websauna.utils.configincluder import monkey_patch_paster_config_parser
    monkey_patch_paster_config_parser()

    # Setup Python logging from the INI
    setup_logging(test_config_path)

    # Read [app] section
    config = get_appsettings(test_config_path)

    # To pass the config filename itself forward
    config["_ini_file"] = test_config_path

    return config
示例#2
0
def ini_settings(request, test_config_path) -> dict:
    """Load INI settings for test run from py.test command line.

    Example:

         py.test yourpackage -s --ini=test.ini


    :return: A dictionary representing the key/value pairs in an ``app`` section within the file represented by ``config_uri``
    """

    # This enables our INI inclusion mechanism
    # TODO: Don't use get_appsettings() from paster, but create a INI includer compatible version
    from websauna.utils.configincluder import monkey_patch_paster_config_parser
    monkey_patch_paster_config_parser()

    # Setup Python logging from the INI
    setup_logging(test_config_path)

    # Read [app] section
    config = get_appsettings(test_config_path)

    # To pass the config filename itself forward
    config["_ini_file"] = test_config_path

    return config
示例#3
0
def ini_settings(request) -> dict:
    """Load INI settings for test run from py.test command line.

    Example:

         py.test yourpackage -s --ini=test.ini


    :return: Adictionary representing the key/value pairs in an ``app`` section within the file represented by ``config_uri``
    """

    if not getattr(request.config.option, "ini", None):
        raise RuntimeError("You need to give --ini test.ini command line option to py.test to find our test settings")

    from websauna.utils.configincluder import monkey_patch_paster_config_parser
    monkey_patch_paster_config_parser()

    config_uri = os.path.abspath(request.config.option.ini)
    setup_logging(config_uri)
    config = get_appsettings(config_uri)

    # To pass the config filename itself forward
    config["_ini_file"] = config_uri

    return config
示例#4
0
def ini_settings(request, test_config_path) -> dict:
    """Load INI settings for test run from py.test command line.

    Example:

         py.test yourpackage -s --ini=test.ini


    :return: A dictionary representing the key/value pairs in an ``app`` section within the file represented by ``config_uri``
    """

    from websauna.utils.configincluder import monkey_patch_paster_config_parser
    monkey_patch_paster_config_parser()

    setup_logging(test_config_path)
    config = get_appsettings(test_config_path)

    # To pass the config filename itself forward
    config["_ini_file"] = test_config_path

    return config
示例#5
0
def run_alembic(package: str):
    """Alembic env.py script entry point for Websauna application.

    Initialize the application, load models and pass control to Alembic migration handler.

    :param package: String of the Python package name whose model the migration concerns. E.g. the name of the current Websauna package.
    """
    global logger
    global version_table

    current_package = package

    # this is the Alembic Config object, which provides
    # access to the values within the .ini file in use.
    config = context.config

    # This was -c passed to ws-alembic command
    config_file = config.config_file_name

    setup_logging(config_file)

    # Load the WSGI application, etc.
    request = init_websauna(config_file)
    engine = request.dbsession.get_bind()

    # Delay logger creation until we have initialized the logging system
    logger = logging.getLogger(__name__)

    # Extract database connection URL from the settings
    url = request.registry.settings["sqlalchemy.url"]

    allowed_packages = parse_allowed_packages(current_package)

    #: Pull out MetaData instance for the system
    target_metadata = get_sqlalchemy_metadata(allowed_packages)

    # Each package needs to maintain its own alembic_history table
    version_table = get_migration_table_name(allowed_packages, current_package)

    def include_object(object, name, type_, reflected, compare_to):
        """
        """

        # Try to figure out smartly table from different object types
        if type_ in ("index", "column", "foreign_key_constraint",
                     "unique_constraint"):
            table_name = object.table.name
            table = object.table
        elif type_ == "table":
            table_name = object.name
            table = object
        else:
            raise RuntimeError(
                "Don't know how to check type for migration inclusion list: {}"
                .format(type_))

        model = get_class_by_table(table)
        if not model:
            # Don't know what's this... let's skip
            logger.info("No model available: %s %s %s", object, type_,
                        table_name)
            return False

        module = model.__module__

        # XXX: This is not very beautiful check but works for now
        return consider_module_for_migration(module, allowed_packages)

    if context.is_offline_mode():
        run_migrations_offline(url, target_metadata, version_table,
                               include_object)
    else:
        logger.info(
            "Starting online migration engine on database connection {} version history table {}"
            .format(engine, version_table))
        run_migrations_online(engine, target_metadata, version_table,
                              include_object)

    # TODO: If a migration file is written, post-edit it and add websauna import

    logger.info("All done")
示例#6
0
def fix_celery_logging(loglevel, logfile, format, colorize, **kwargs):
    """Fix Celery logging by re-enforcing our loggers after Celery messes up them."""
    setup_logging(ini_file)
示例#7
0
def run_alembic(package:str):
    """Alembic env.py script entry point for Websauna application.

    Initialize the application, load models and pass control to Alembic migration handler.

    :param package: String of the Python package name whose model the migration concerns. E.g. the name of the current Websauna package.
    """
    global logger
    global version_table

    current_package = package

    # this is the Alembic Config object, which provides
    # access to the values within the .ini file in use.
    config = context.config

    # This was -c passed to ws-alembic command
    config_file = config.config_file_name

    setup_logging(config_file)

    # Load the WSGI application, etc.
    request = init_websauna(config_file)
    engine = request.dbsession.get_bind()

    # Delay logger creation until we have initialized the logging system
    logger = logging.getLogger(__name__)

    # Extract database connection URL from the settings
    url = request.registry.settings["sqlalchemy.url"]

    allowed_packages = parse_allowed_packages(current_package)

    #: Pull out MetaData instance for the system
    target_metadata = get_sqlalchemy_metadata(allowed_packages)

    # Each package needs to maintain its own alembic_history table
    version_table = get_migration_table_name(allowed_packages, current_package)

    def include_object(object, name, type_, reflected, compare_to):
        """
        """

        # Try to figure out smartly table from different object types
        if type_ in ("index", "column", "foreign_key_constraint", "unique_constraint"):
            table_name = object.table.name
            table = object.table
        elif type_ == "table":
            table_name = object.name
            table = object
        else:
            raise RuntimeError("Don't know how to check type for migration inclusion list: {}".format(type_))

        model = get_class_by_table(table)
        if not model:
            # Don't know what's this... let's skip
            logger.info("No model available: %s %s %s", object, type_, table_name)
            return False

        module = model.__module__

        # XXX: This is not very beautiful check but works for now
        return consider_module_for_migration(module, allowed_packages)

    if context.is_offline_mode():
        run_migrations_offline(url, target_metadata, version_table, include_object)
    else:
        logger.info("Starting online migration engine on database connection {} version history table {}".format(engine, version_table))
        run_migrations_online(engine, target_metadata, version_table, include_object)

    # TODO: If a migration file is written, post-edit it and add websauna import

    logger.info("All done")