Пример #1
0
def create_log(target):
    ident = get_ident()
    log = cv.logger('uow_defer@%s' % ident)
    log.addHandler(StreamHandler(target))
    with _active_logs_lock:
        _active_logs[ident] = log
    return log
Пример #2
0
#	coding utf-8
'''
File storage and in-memory caching of files for canvas. Files are stored in the
configured directory to which the serving user must have read and write access.
'''

import os
import time
import mimetypes
import canvas as cv

#	Load the plugin config and create a log.
config = cv.plugin_config(__name__)
log = cv.logger(__name__)

from .exceptions import NoSuchFileError
from .cache import Cache, CachedFile

#	Create the cache.
_cache = Cache(config.cache_size_mb)


def store(filename, contents):
    '''Store a file as `filename`'''
    #	Decide mode and path.
    mode = 'wb' if isinstance(contents, bytes) else 'w'
    full_path = os.path.join(cv.__home__, config.storage_dir, filename)

    #	Write the file.
    with open(full_path, mode) as output_file:
        output_file.write(contents)