示例#1
0
def run(project_dir, appstats=True, debug=None):
    # auto detect environment (development or production)
    if debug is None:
        debug = development_env()
    COOKIE_KEY = 'my_private_key_used_for_this_application_%s' % get_application_id()
    if development_env(): # always reload configuration
        app = WSGIApplication(project_dir, debug)
    else:
        app = WSGIApplication.active_instance or WSGIApplication(project_dir, debug)
    app = SessionMiddleware(app, cookie_key=COOKIE_KEY, cookie_only_threshold=0)
    if appstats:
        app = recording.appstats_wsgi_middleware(app)
    run_wsgi_app(app)
示例#2
0
def get_config(path=None, default_value=None):
    # create one copy of configuration
    global _config
    # doesn't cache config in development environment
    if _config is None or development_env():
        _config = Config()
    # load given configuration options
    if path is not None:
        return _config.get(path, default_value)
    return _config
示例#3
0
 def _get_error_page(self, code):
     '''Return html page for given error number'''
     filename = os.path.join(self._project_dir, 'apps', 'site', 'templates', '%s.html' % code)
     if os.path.exists(filename):
         fd = open(filename, "r")
         text = fd.read()
         fd.close()
         if development_env() and text:
             return text.replace("[ERROR MESSAGES]", "\n".join(self._errors))
         return text
     return ""