def create_app(**kwargs): """ create a WSGI application that can be used in the modules. """ from flask import Flask from pyggi.lib.config import config import logging static_base = '/static' if config.has_option('general', 'static_url_base'): static_base = config.get('general', 'static_url_base') app = Flask(__name__, static_url_path=static_base) # get logging settings config_settings = dict(level=logging.WARNING, format="[%(asctime)s] %(levelname)s: %(message)s", datefmt="%Y-%m-%d %H:%M:%S") if config.has_option('log', 'file'): config_settings['filename'] = config.get('log', 'file') # activate logging logging.basicConfig(**config_settings) # register modules to application. the modules come # from the configuration file. there is a list of # modules to be imported. an item in this list has the # form ("module:name","prefix") where name is the name of the module # object that should be imported for module_desc in config.items('modules'): module, prefix = module_desc module, attribute = module.rsplit('.', 1) # now we try to import the module and register it # in our application. otherwise ignore and continue try: _import = __import__(module, globals(), locals(), [attribute], -1) prefix = "" if prefix.strip('/') == "" else "/" + prefix.strip('/') app.register_blueprint(getattr(_import, attribute), url_prefix=prefix) except Exception as e: logging.critical("could not load module '%s': %s", module_desc[0], e) # register some filters import lib.filters app.jinja_env.filters['dateformat'] = lib.filters.format_datetime app.jinja_env.filters['diffformat'] = lib.filters.format_diff app.jinja_env.filters['timesince'] = lib.filters.humanize_timesince app.jinja_env.filters['force_unicode'] = lib.filters.force_unicode app.jinja_env.filters['first_line'] = lib.filters.first_line app.jinja_env.tests['text'] = lib.filters.is_text app.context_processor( lambda: dict(static_url_for=lib.filters.static_url_for)) return app
def create_app(**kwargs): """ create a WSGI application that can be used in the modules. """ from flask import Flask from pyggi.lib.config import config import logging static_base = '/static' if config.has_option('general', 'static_url_base'): static_base = config.get('general', 'static_url_base') app = Flask(__name__, static_url_path=static_base) # get logging settings config_settings = dict( level=logging.WARNING, format="[%(asctime)s] %(levelname)s: %(message)s", datefmt="%Y-%m-%d %H:%M:%S" ) if config.has_option('log', 'file'): config_settings['filename'] = config.get('log', 'file') # activate logging logging.basicConfig(**config_settings) # register modules to application. the modules come # from the configuration file. there is a list of # modules to be imported. an item in this list has the # form ("module:name","prefix") where name is the name of the module # object that should be imported for module_desc in config.items('modules'): module, prefix = module_desc module, attribute = module.rsplit('.', 1) # now we try to import the module and register it # in our application. otherwise ignore and continue try: _import = __import__(module, globals(), locals(), [attribute], -1) prefix = "" if prefix.strip('/') == "" else "/" + prefix.strip('/') app.register_blueprint(getattr(_import, attribute), url_prefix=prefix) except Exception as e: logging.critical("could not load module '%s': %s", module_desc[0], e) # register some filters import lib.filters app.jinja_env.filters['dateformat'] = lib.filters.format_datetime app.jinja_env.filters['diffformat'] = lib.filters.format_diff app.jinja_env.filters['timesince'] = lib.filters.humanize_timesince app.jinja_env.filters['force_unicode'] = lib.filters.force_unicode app.jinja_env.filters['first_line'] = lib.filters.first_line app.jinja_env.tests['text'] = lib.filters.is_text app.context_processor(lambda: dict(static_url_for=lib.filters.static_url_for)) return app
def cache_function(*args, **kwargs): key = keyfn(*args, **kwargs) if key is None: result = f(*args, **kwargs) else: from pyggi.lib.utils import cache from pyggi.lib.config import config result = cache.get(key) if result is None: result = f(*args, **kwargs) timeout = None if config.has_option('cache', 'timeout'): timeout = config.getint('cache','timeout') cache.set(key, result, timeout=timeout) return result
def cache_function(*args, **kwargs): key = keyfn(*args, **kwargs) if key is None: result = f(*args, **kwargs) else: from pyggi.lib.utils import cache from pyggi.lib.config import config result = cache.get(key) if result is None: result = f(*args, **kwargs) timeout = None if config.has_option('cache', 'timeout'): timeout = config.getint('cache', 'timeout') cache.set(key, result, timeout=timeout) return result
""" :copyright: (c) 2011 by Tobias Heinzen :license: BSD, see LICENSE for more details """ from flask import current_app from pyggi.lib.config import config import logging class DummyCache(object): def get(*args, **kwargs): pass def set(*args, **kwargs): pass if not (config.has_option('cache', 'enabled') and config.getboolean('cache', 'enabled')): cache = DummyCache() else: if current_app.debug: from werkzeug.contrib.cache import SimpleCache cache = SimpleCache() else: try: from werkzeug.contrib.cache import MemcachedCache cache = MemcachedCache([x.strip() for x in config.get('cache', 'uris').split(",") if not len(x.strip()) == 0]) except: cache = DummyCache() logging.critical("could not connect to memcache daemon - disabling caching") def get_clone_urls(): from flask import request
""" from flask import current_app from pyggi.lib.config import config import logging class DummyCache(object): def get(*args, **kwargs): pass def set(*args, **kwargs): pass if not (config.has_option('cache', 'enabled') and config.getboolean('cache', 'enabled')): cache = DummyCache() else: if current_app.debug: from werkzeug.contrib.cache import SimpleCache cache = SimpleCache() else: try: from werkzeug.contrib.cache import MemcachedCache cache = MemcachedCache([ x.strip() for x in config.get('cache', 'uris').split(",") if not len(x.strip()) == 0 ]) except: cache = DummyCache()