Python environ.Path() Examples

The following are 2 code examples of environ.Path(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module environ , or try the search function .
Example #1
Source File: settings.py    From woeip with MIT License 6 votes vote down vote up
def generate_file_handler(filename):
    """ Generates a logging handler that writes to a file.

    If the `ENABLE_LOGGING_TO_FILE` setting is `False`, `logging.NullHandler` will be used instead
    of `logging.FileHandler`.

    Args:
        filename (str): Name of the file to which logs are written.

    Returns:
        dict
    """
    handler = {"level": "INFO", "formatter": "standard"}
    if ENABLE_LOGGING_TO_FILE:
        handler.update(
            {
                "class": "logging.FileHandler",
                "filename": environ.Path(LOG_FILE_PATH).path(filename),
            }
        )
    else:
        handler["class"] = "logging.NullHandler"

    return handler 
Example #2
Source File: __init__.py    From pydoc.io with Apache License 2.0 6 votes vote down vote up
def update_body(app, pagename, templatename, context, doctree):
    outdir = environ.Path(app.config.html_context['output_directory'])
    project = app.config.project
    version = app.config.version
    if not os.path.exists(outdir.root):
        os.makedirs(outdir.root)
    directory_name = "{name}-{version}".format(name=project, version=version)
    json_dir = outdir.path(directory_name)
    if not os.path.exists(json_dir.root):
        os.makedirs(json_dir.root)
    try:
        out_dir = json_dir.path('/'.join(pagename.split('/')[:-1]))
        if not os.path.exists(out_dir()):
            os.makedirs(out_dir())
        out_file = json_dir.path(pagename + '.json')
        to_write = open(out_file(), 'w+')
        to_context = copy.copy(context)
        # Use list here so we don't get an error on changing dict during iteration
        for key in list(context):
            if key not in KEYS:
                del to_context[key]
        to_write.write(json.dumps(to_context, indent=4))
    except Exception:
        log.exception('Failure in JSON search dump')