Esempio n. 1
0
 def add_static(self, fdir, m_dir):
     static_route = '/static/'+fdir+'/:path#.+#'
     #print "Declaring static entry", static_route, lamb
     #f = route(static_route, callback=lamb)
     def plugin_static(path):
         #print "Addr f", plugin_static, plugin_static.entry
         return static_file(path, root=os.path.join(m_dir, 'htdocs'))
     route(static_route, callback=plugin_static)
Esempio n. 2
0
 def init_http(self):
     logger.info("Starting WS arbiter http socket")
     self.srv = run(host=self.host, port=self.port, server='wsgirefselect')
     # And we link our page
     route('/push_check_result', callback=get_page, method='POST')
Esempio n. 3
0
    def load_plugins(self):
        from shinken.webui import plugins
        plugin_dir = os.path.abspath(os.path.dirname(plugins.__file__))
        print "Loading plugin directory : %s" % plugin_dir
        
        # Load plugin directories
        plugin_dirs = [ fname for fname in os.listdir(plugin_dir)
                        if os.path.isdir(os.path.join(plugin_dir, fname)) ]

        print "Plugin dirs", plugin_dirs
        sys.path.append(plugin_dir)
        # We try to import them, but we keep only the one of
        # our type
        for fdir in plugin_dirs:
            print "Try to load", fdir
            mod_path = 'shinken.webui.plugins.%s.%s' % (fdir, fdir)
            try:
                m = __import__(mod_path, fromlist=[mod_path])
                m_dir = os.path.abspath(os.path.dirname(m.__file__))
                sys.path.append(m_dir)

                print "Loaded module m", m
                print m.__file__
                pages = m.pages
                print "Try to laod pages", pages
                for (f, entry) in pages.items():
                    routes = entry.get('routes', None)
                    v = entry.get('view', None)
                    static = entry.get('static', False)

                    # IMPORTANT : apply VIEW BEFORE route!
                    if v:
                        print "Link function", f, "and view", v
                        f = view(v)(f)

                    # Maybe there is no route to link, so pass
                    if routes:
                        for r in routes:
                            print "link function", f, "and route", r
                            f = route(r, callback=f)
                        
                    # Ifthe plugin declare a static entry, register it
                    if static:
                        self.add_static(fdir, m_dir)
                        #static_route = '/static/'+fdir+'/:path#.+#'
                        #print "Declaring static entry", static_route, lamb
                        #f = route(static_route, callback=lamb)
                        #def plugin_static(path):
                        #    print "Addr f", plugin_static, plugin_static.entry
                        #    m_dir = plugin_static.m_dir
                        #    print "Get a plugin static file %s from" % path, os.path.join(m_dir, 'htdocs')
                        #    return static_file(path, root=os.path.join(m_dir, 'htdocs'))
                        #g = copy.deepcopy(plugin_static)
                        #print "Addr plugin_static", plugin_static, g, static_route
                        #g.m_dir = m_dir
                        #g.entry = static_route
                        #route(static_route, callback=g)


                # And we add the views dir of this plugin in our TEMPLATE
                # PATH
                bottle.TEMPLATE_PATH.append(os.path.join(m_dir, 'views'))

                # And finally register me so the pages can get data and other
                # useful stuff
                m.app = self
                        
                        
            except Exception, exp:
                logger.log("Warning in loading plugins : %s" % exp)
Esempio n. 4
0
 def init_http(self):
     logger.info("[Ws_arbiter] Starting WS arbiter http socket")
     self.srv = run(host=self.host, port=self.port, server='wsgirefselect')
     # And we link our page
     route('/push_check_result', callback=get_page, method='POST')