Example #1
0
def load_plugin_file(filename, failover_filename=None, min_priority=0,
        max_priority=None):
    """
    Load plugins from a file (able to restrict by priority). If the first file
    doesn't exist then the failover_filename is loaded. This is so that we can
    have a 'default' plugin file which can be optionally overwritten if another
    file exists.
    """
    
    fn = filename
    if not os.path.exists(filename):
        if failover_filename and os.path.exists(failover_filename):
            fn = failover_filename
        else:
            return
        
    with open(fn) as f:
        for line in f.readlines():
            line = line.strip()
            
            if line and not line.startswith("#"):
                priority, plugin = line.split(":")
                priority = int(priority)
                
                if not min_priority or priority > min_priority:
                    if not max_priority or priority < max_priority:
                        #Load this plugin
                        print 'loading plugin %s at priority %s' % (plugin, priority)
                        try:
                            util.import_class(plugin)
                            print 'enabling plugin %s' % (plugin, )
                            enable_plugin(plugin)
                        except:
                            log.err()
Example #2
0
 def on_error_rendering(self, request, f):
     #TODO pretty error page
     #TODO custom settable error page
     log.err(f)
     request.set_response_code(500)
     request.set_header("content-type", "text/html")
     request.write("<html><body>%s</body></html>" % (f))
     return request
Example #3
0
 def load_lines(self, lines):
     for line in lines:
         line = line.strip()
         if not line.startswith("#") and line:
             method, path, pg = (x.strip() for x in line.split())
             try:
                 self.on_add_route(method, path, pg, update=False)
             except:
                 log.err()
             
     self.map.create_regs()
Example #4
0
    def login(self, request):
        """
        Login page
        """
       
        kw = {}
        if "next" in request.args:
            kw["next"] = request.args["next"]

        if "email" in request.args:
            try:
                auth.authenticate(request.args["email"], request.args["email"],
                                  request.args.get("remember", False))
                _next = kw.get("next", self.default_next)
                if not _next:
                    _next = "/"

                return http.redirect(request, _next)
            except Exception, e:
                #TODO replace this with form generation and validation code
                log.err()
                kw["error"] = str(e)