示例#1
0
def configure(ctx, py, yaml, skip_service_validation=False):
    """
    Given the two different config files, set up the environment.

    NOTE: Will only execute once, so it's safe to call multiple times.
    """
    global __installed
    if __installed:
        return

    # Make sure that our warnings are always displayed
    import warnings

    warnings.filterwarnings("default", "", Warning, r"^sentry")

    # Add in additional mimetypes that are useful for our static files
    # which aren't common in default system registries
    import mimetypes

    for type, ext in (
        ("application/json", "map"),
        ("application/font-woff", "woff"),
        ("application/font-woff2", "woff2"),
        ("application/vnd.ms-fontobject", "eot"),
        ("application/x-font-ttf", "ttf"),
        ("application/x-font-ttf", "ttc"),
        ("font/opentype", "otf"),
        ("image/svg+xml", "svg"),
    ):
        mimetypes.add_type(type, "." + ext)

    from .importer import install

    if yaml is None:
        # `yaml` will be None when SENTRY_CONF is pointed
        # directly to a file, in which case, this file must exist
        if not os.path.exists(py):
            if ctx:
                raise click.ClickException(
                    "Configuration file does not exist. Use 'sentry init' to initialize the file."
                )
            raise ValueError(
                "Configuration file does not exist at '%s'" % click.format_filename(py)
            )
    elif not os.path.exists(yaml) and not os.path.exists(py):
        if ctx:
            raise click.ClickException(
                "Configuration file does not exist. Use 'sentry init' to initialize the file."
            )
        raise ValueError("Configuration file does not exist at '%s'" % click.format_filename(yaml))

    # Add autoreload for config.yml file if needed
    if yaml is not None and os.path.exists(yaml):
        from sentry.utils.uwsgi import reload_on_change

        reload_on_change(yaml)

    os.environ["DJANGO_SETTINGS_MODULE"] = "sentry_config"

    install("sentry_config", py, DEFAULT_SETTINGS_MODULE)

    # HACK: we need to force access of django.conf.settings to
    # ensure we don't hit any import-driven recursive behavior
    from django.conf import settings

    hasattr(settings, "INSTALLED_APPS")

    from .initializer import initialize_app

    initialize_app(
        {"config_path": py, "settings": settings, "options": yaml},
        skip_service_validation=skip_service_validation,
    )

    __installed = True
示例#2
0
def configure(ctx, py, yaml, skip_service_validation=False):
    """
    Given the two different config files, set up the environment.

    NOTE: Will only execute once, so it's safe to call multiple times.
    """
    global __installed
    if __installed:
        return

    # Make sure that our warnings are always displayed
    import warnings
    warnings.filterwarnings('default', '', Warning, r'^sentry')

    # Add in additional mimetypes that are useful for our static files
    # which aren't common in default system registries
    import mimetypes
    for type, ext in (
        ('application/json', 'map'),
        ('application/font-woff', 'woff'),
        ('application/font-woff2', 'woff2'),
        ('application/vnd.ms-fontobject', 'eot'),
        ('application/x-font-ttf', 'ttf'),
        ('application/x-font-ttf', 'ttc'),
        ('font/opentype', 'otf'),
        ('image/svg+xml', 'svg'),
    ):
        mimetypes.add_type(type, '.' + ext)

    from .importer import install

    if yaml is None:
        # `yaml` will be None when SENTRY_CONF is pointed
        # directly to a file, in which case, this file must exist
        if not os.path.exists(py):
            if ctx:
                raise click.ClickException(
                    "Configuration file does not exist. Use 'sentry init' to initialize the file."
                )
            raise ValueError(
                "Configuration file does not exist at '%s'" % click.format_filename(py)
            )
    elif not os.path.exists(yaml) and not os.path.exists(py):
        if ctx:
            raise click.ClickException(
                "Configuration file does not exist. Use 'sentry init' to initialize the file."
            )
        raise ValueError("Configuration file does not exist at '%s'" % click.format_filename(yaml))

    # Add autoreload for config.yml file if needed
    if yaml is not None and os.path.exists(yaml):
        from sentry.utils.uwsgi import reload_on_change
        reload_on_change(yaml)

    os.environ['DJANGO_SETTINGS_MODULE'] = 'sentry_config'

    install('sentry_config', py, DEFAULT_SETTINGS_MODULE)

    # HACK: we need to force access of django.conf.settings to
    # ensure we don't hit any import-driven recursive behavior
    from django.conf import settings
    hasattr(settings, 'INSTALLED_APPS')

    from .initializer import initialize_app, on_configure
    initialize_app(
        {
            'config_path': py,
            'settings': settings,
            'options': yaml,
        },
        skip_service_validation=skip_service_validation
    )
    on_configure({'settings': settings})

    __installed = True
示例#3
0
文件: settings.py 项目: zanjs/sentry
def configure(ctx, py, yaml, skip_service_validation=False):
    """
    Given the two different config files, set up the environment.

    NOTE: Will only execute once, so it's safe to call multiple times.
    """
    global __installed
    if __installed:
        return

    # Make sure that our warnings are always displayed
    import warnings
    warnings.filterwarnings('default', '', Warning, r'^sentry')

    # Add in additional mimetypes that are useful for our static files
    # which aren't common in default system registries
    import mimetypes
    for type, ext in (
        ('application/json', 'map'),
        ('application/font-woff', 'woff'),
        ('application/font-woff2', 'woff2'),
        ('application/vnd.ms-fontobject', 'eot'),
        ('application/x-font-ttf', 'ttf'),
        ('application/x-font-ttf', 'ttc'),
        ('font/opentype', 'otf'),
    ):
        mimetypes.add_type(type, '.' + ext)

    from .importer import install

    if yaml is None:
        # `yaml` will be None when SENTRY_CONF is pointed
        # directly to a file, in which case, this file must exist
        if not os.path.exists(py):
            if ctx:
                raise click.ClickException("Configuration file does not exist. Use 'sentry init' to initialize the file.")
            raise ValueError("Configuration file does not exist at '%s'" % click.format_filename(py))
    elif not os.path.exists(yaml) and not os.path.exists(py):
        if ctx:
            raise click.ClickException("Configuration file does not exist. Use 'sentry init' to initialize the file.")
        raise ValueError("Configuration file does not exist at '%s'" % click.format_filename(yaml))

    # Add autoreload for config.yml file if needed
    if yaml is not None and os.path.exists(yaml):
        from sentry.utils.uwsgi import reload_on_change
        reload_on_change(yaml)

    os.environ['DJANGO_SETTINGS_MODULE'] = 'sentry_config'

    install('sentry_config', py, DEFAULT_SETTINGS_MODULE)

    # HACK: we need to force access of django.conf.settings to
    # ensure we don't hit any import-driven recursive behavior
    from django.conf import settings
    hasattr(settings, 'INSTALLED_APPS')

    from .initializer import initialize_app, on_configure
    initialize_app({
        'config_path': py,
        'settings': settings,
        'options': yaml,
    }, skip_service_validation=skip_service_validation)
    on_configure({'settings': settings})

    __installed = True