コード例 #1
0
ファイル: __init__.py プロジェクト: taniki/udata
def init_logging(app):
    log_level = logging.DEBUG if app.debug else logging.INFO

    handler = CliHandler()
    handler.setFormatter(CliFormatter())
    handler.setLevel(log_level)

    logger = logging.getLogger()
    logger.addHandler(handler)

    logger = logging.getLogger('__main__')
    logger.setLevel(log_level)
    logger.handlers = []
    logger.addHandler(handler)

    for name in entrypoints.get_roots():  # Entrypoints loggers
        logger = logging.getLogger(name)
        logger.setLevel(log_level)
        logger.handlers = []

    app.logger.setLevel(log_level)
    app.logger.handlers = []
    app.logger.addHandler(handler)

    for name in VERBOSE_LOGGERS:
        logger = logging.getLogger(name)
        logger.setLevel(logging.WARNING if app.debug else logging.ERROR)
        logger.handlers = []

    return app
コード例 #2
0
ファイル: app.py プロジェクト: opendatateam/udata
def create_app(config='udata.settings.Defaults', override=None,
               init_logging=init_logging):
    '''Factory for a minimal application'''
    app = UDataApp(APP_NAME)
    app.config.from_object(config)

    settings = os.environ.get('UDATA_SETTINGS', join(os.getcwd(), 'udata.cfg'))
    if exists(settings):
        app.settings_file = settings  # Keep track of loaded settings for diagnostic
        app.config.from_pyfile(settings)

    if override:
        app.config.from_object(override)

    # Loads defaults from plugins
    for pkg in entrypoints.get_roots(app):
        if pkg == 'udata':
            continue  # Defaults are already loaded
        module = '{}.settings'.format(pkg)
        if pkgutil.find_loader(module):
            settings = pkgutil.get_loader(module)
            for key, default in settings.__dict__.items():
                app.config.setdefault(key, default)

    app.json_encoder = UDataJsonEncoder

    app.debug = app.config['DEBUG'] and not app.config['TESTING']

    app.wsgi_app = ProxyFix(app.wsgi_app)

    init_logging(app)
    register_extensions(app)

    return app
コード例 #3
0
def create_app(config='udata.settings.Defaults',
               override=None,
               init_logging=init_logging):
    '''Factory for a minimal application'''
    app = UDataApp(APP_NAME)
    app.config.from_object(config)

    settings = os.environ.get('UDATA_SETTINGS', join(os.getcwd(), 'udata.cfg'))
    if exists(settings):
        app.settings_file = settings  # Keep track of loaded settings for diagnostic
        app.config.from_pyfile(settings)

    if override:
        app.config.from_object(override)

    # Loads defaults from plugins
    for pkg in entrypoints.get_roots(app):
        if pkg == 'udata':
            continue  # Defaults are already loaded
        module = '{}.settings'.format(pkg)
        if pkgutil.find_loader(module):
            settings = pkgutil.get_loader(module)
            for key, default in settings.__dict__.items():
                app.config.setdefault(key, default)

    app.json_encoder = UDataJsonEncoder

    app.debug = app.config['DEBUG'] and not app.config['TESTING']

    app.wsgi_app = ProxyFix(app.wsgi_app)

    init_logging(app)
    register_extensions(app)

    return app
コード例 #4
0
    def get_translations(self):
        """Returns the correct gettext translations that should be used for
        this request.  This will never fail and return a dummy translation
        object if used outside of the request or if a translation cannot be
        found.
        """
        ctx = stack.top
        if ctx is None:
            return NullTranslations()

        locale = get_locale()

        cache = self.get_translations_cache(ctx)

        translations = cache.get(str(locale))
        if translations is None:
            translations_dir = self.get_translations_path(ctx)
            translations = Translations.load(translations_dir, locale,
                                             domain=self.domain)

            # Load plugins translations
            if isinstance(translations, Translations):
                # Load core extensions translations
                from wtforms.i18n import messages_path
                wtforms_translations = Translations.load(messages_path(),
                                                         locale,
                                                         domain='wtforms')
                translations.merge(wtforms_translations)

                import flask_security
                flask_security_translations = Translations.load(
                    join(flask_security.__path__[0], 'translations'),
                    locale,
                    domain='flask_security'
                )
                translations.merge(flask_security_translations)

                for pkg in entrypoints.get_roots(current_app):
                    package = pkgutil.get_loader(pkg)
                    path = join(package.filename, 'translations')
                    domains = [f.replace(path, '').replace('.pot', '')[1:]
                               for f in iglob(join(path, '*.pot'))]
                    for domain in domains:
                        translations.merge(Translations.load(path, locale,
                                                             domain=domain))

                # Allows the theme to provide or override translations
                from . import theme

                theme_translations_dir = join(theme.current.path, 'translations')
                if exists(theme_translations_dir):
                    domain = theme.current.identifier
                    theme_translations = Translations.load(theme_translations_dir,
                                                           locale,
                                                           domain=domain)
                    translations.merge(theme_translations)

                cache[str(locale)] = translations

        return translations
コード例 #5
0
ファイル: i18n.py プロジェクト: odtvince/udata
    def get_translations(self):
        """Returns the correct gettext translations that should be used for
        this request.  This will never fail and return a dummy translation
        object if used outside of the request or if a translation cannot be
        found.
        """
        ctx = stack.top
        if ctx is None:
            return NullTranslations()

        locale = get_locale()

        cache = self.get_translations_cache(ctx)

        translations = cache.get(str(locale))
        if translations is None:
            translations_dir = self.get_translations_path(ctx)
            translations = Translations.load(translations_dir, locale,
                                             domain=self.domain)

            # Load plugins translations
            if isinstance(translations, Translations):
                # Load core extensions translations
                from wtforms.i18n import messages_path
                wtforms_translations = Translations.load(messages_path(),
                                                         locale,
                                                         domain='wtforms')
                translations.merge(wtforms_translations)

                import flask_security
                flask_security_translations = Translations.load(
                    join(flask_security.__path__[0], 'translations'),
                    locale,
                    domain='flask_security'
                )
                translations.merge(flask_security_translations)

                for pkg in entrypoints.get_roots(current_app):
                    package = pkgutil.get_loader(pkg)
                    path = join(package.filename, 'translations')
                    domains = [f.replace(path, '').replace('.pot', '')[1:]
                               for f in iglob(join(path, '*.pot'))]
                    for domain in domains:
                        translations.merge(Translations.load(path, locale,
                                                             domain=domain))

                # Allows the theme to provide or override translations
                from . import theme

                theme_translations_dir = join(theme.current.path, 'translations')
                if exists(theme_translations_dir):
                    domain = theme.current.identifier
                    theme_translations = Translations.load(theme_translations_dir,
                                                           locale,
                                                           domain=domain)
                    translations.merge(theme_translations)

                cache[str(locale)] = translations

        return translations
コード例 #6
0
ファイル: app.py プロジェクト: opendatateam/udata
def init_logging(app):
    logging.captureWarnings(True)  # Display warnings
    debug = app.debug or app.config.get('TESTING')
    log_level = logging.DEBUG if debug else logging.WARNING
    app.logger.setLevel(log_level)
    for name in entrypoints.get_roots():  # Entrypoints loggers
        logging.getLogger(name).setLevel(log_level)
    for logger in VERBOSE_LOGGERS:
        logging.getLogger(logger).setLevel(logging.WARNING)
    return app
コード例 #7
0
ファイル: app.py プロジェクト: opendatateam/udata
def init_logging(app):
    logging.captureWarnings(True)  # Display warnings
    debug = app.debug or app.config.get('TESTING')
    log_level = logging.DEBUG if debug else logging.WARNING
    app.logger.setLevel(log_level)
    for name in entrypoints.get_roots():  # Entrypoints loggers
        logging.getLogger(name).setLevel(log_level)
    for logger in VERBOSE_LOGGERS:
        logging.getLogger(logger).setLevel(logging.WARNING)
    return app