view piecrust/wsgiutil/__init__.py @ 979:45ad976712ec

tests: Big push to get the tests to pass again. - Lots of fixes everywhere in the code. - Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now. - Replace all `.md` test files with `.html` since now a auto-format extension always sets the format. - Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 29 Oct 2017 22:51:57 -0700
parents 7ecb946bfafd
children d0f86d9a9d40
line wrap: on
line source

import logging
from piecrust.serving.wrappers import get_piecrust_server


def _setup_logging(log_file, log_level, max_log_bytes, log_backup_count):
    if log_file:
        from logging.handlers import RotatingFileHandler
        handler = RotatingFileHandler(log_file, maxBytes=max_log_bytes,
                                      backupCount=log_backup_count)
        handler.setLevel(log_level)
        logging.getLogger().addHandler(handler)


def get_app(root_dir, *,
            cache_key='prod',
            serve_admin=False,
            log_file=None,
            log_level=logging.INFO,
            log_backup_count=0,
            max_log_bytes=4096):
    _setup_logging(log_file, log_level, max_log_bytes, log_backup_count)
    app = get_piecrust_server(root_dir,
                              serve_site=True,
                              serve_admin=serve_admin,
                              cache_key=cache_key)
    return app


def get_admin_app(root_dir, *,
                  cache_key='prod',
                  log_file=None,
                  log_level=logging.INFO,
                  log_backup_count=0,
                  max_log_bytes=4096):
    _setup_logging(log_file, log_level, max_log_bytes, log_backup_count)
    app = get_piecrust_server(root_dir,
                              serve_site=False,
                              serve_admin=True,
                              cache_key=cache_key)
    return app