Example #1
0
 def __init__(self, config=None):
     PluginManager.__init__(self)
     self.gconfig = config
     self.log = config.get('log_facility')
     self.platform = config.get('platform')
     PluginLoader.register_observer(self)
     self.refresh_plugin_data()
Example #2
0
 def __init__(self, config=None):
     PluginManager.__init__(self)
     self.gconfig = config
     self.log = config.get('log_facility')
     self.platform = config.get('platform')
     PluginLoader.register_observer(self)
     self.refresh_plugin_data()
Example #3
0
    def refresh_plugin_data(self):
        """
        Rescans plugins for JS, CSS, LESS, XSLT widgets and XML templates.
        """
        self.template_path = []
        self.less_styles = []
        self.woff_fonts = []
        self.eot_fonts = []
        self.svg_fonts = []
        self.ttf_fonts = []
        self.template_styles = []
        self.template_scripts = []
        self.layouts = {}
        includes = []
        functions = {}

        for f in self.grab_plugins(IXSLTFunctionProvider):
            functions.update(f.get_funcs())

        # Get path for static content and templates
        plugins = []
        plugins.extend(PluginLoader.list_plugins().keys())
        plugins.extend(genesis.plugins.plist)

        for c in plugins:
            path = os.path.join(PluginLoader.get_plugin_path(self, c), c)

            fp = os.path.join(path, "files")
            if os.path.exists(fp):
                self.template_styles.extend(["/dl/" + c + "/" + s for s in os.listdir(fp) if s.endswith(".css")])
                self.less_styles.extend(["/dl/" + c + "/" + s for s in os.listdir(fp) if s.endswith(".less")])
                self.woff_fonts.extend(["/dl/" + c + "/" + s for s in os.listdir(fp) if s.endswith(".woff")])
                self.eot_fonts.extend(["/dl/" + c + "/" + s for s in os.listdir(fp) if s.endswith(".eot")])
                self.svg_fonts.extend(["/dl/" + c + "/" + s for s in os.listdir(fp) if s.endswith(".svg")])
                self.ttf_fonts.extend(["/dl/" + c + "/" + s for s in os.listdir(fp) if s.endswith(".ttf")])
                self.template_scripts.extend(["/dl/" + c + "/" + s for s in os.listdir(fp) if s.endswith(".js")])

            wp = os.path.join(path, "widgets")
            if os.path.exists(wp):
                includes.extend([os.path.join(wp, s) for s in os.listdir(wp) if s.endswith(".xslt")])

            lp = os.path.join(path, "layout")
            if os.path.exists(lp):
                for s in os.listdir(lp):
                    if s.endswith(".xml"):
                        self.layouts["%s:%s" % (c, s)] = os.path.join(lp, s)

            tp = os.path.join(path, "templates")
            if os.path.exists(tp):
                self.template_path.append(tp)

        if xslt.xslt is None:
            xslt.prepare(includes, functions)
Example #4
0
def make_report(app, err):
    """
    Formats a bug report.
    """
    from genesis.plugmgr import PluginLoader
    pr = ''
    for p in sorted(PluginLoader.list_plugins().keys()):
        pr += p + '\n'

    # Finalize the reported log
    app.log.blackbox.stop()

    return (('Genesis %s bug report\n' +
           '--------------------\n\n' +
           'System: %s\n' +
           'Detected platform: %s\n' +
           'Detected distro: %s\n' +
           'Python: %s\n\n' +
           'Config path: %s\n\n' +
           '%s\n\n'
           'Loaded plugins:\n%s\n\n' +
           'Log:\n%s\n'
           )
            % (version(),
               shell('uname -a'),
               detect_platform(),
               detect_distro(),
               '.'.join([str(x) for x in platform.python_version_tuple()]),
               app.config.filename,
               err,
               pr,
               app.log.blackbox.buffer,
              ))
Example #5
0
def make_report(app, err):
    """
    Formats a bug report.
    """
    from genesis.plugmgr import PluginLoader
    pr = ''
    for p in sorted(PluginLoader.list_plugins().keys()):
        pr += p + '\n'

    # Finalize the reported log
    app.log.blackbox.stop()

    buf = app.log.blackbox.buffer.split('\n')
    if len(buf) >= 50:
        buf = buf[-50:]
        buf.insert(0, '(Showing only the last 50 entries)\n')
    buf = '\n'.join(buf)

    return (
        ('Genesis %s bug report\n' + '--------------------\n\n' +
         'System: %s\n' + 'Detected platform: %s\n' + 'Detected distro: %s\n' +
         'Python: %s\n\n' + 'Config path: %s\n\n' + '%s\n\n'
         'Loaded plugins:\n%s\n\n' + 'Log:\n%s\n') % (
             version(),
             shell('uname -a'),
             detect_platform(),
             detect_distro(),
             '.'.join([str(x) for x in platform.python_version_tuple()]),
             app.config.filename,
             err,
             pr,
             buf,
         ))
Example #6
0
    def __new__(cls, *args, **kwargs):
        """ Returns a class instance,
        If it already instantiated, return it
        otherwise return new instance
        """
        if issubclass(cls, PluginManager):
            # If we also a PluginManager, just create and return
            self = super(Plugin, cls).__new__(cls)
            self.plugin_manager = self
            return self

        # Normal case when we are standalone plugin
        self = None
        plugin_manager = args[0]
        if not cls.multi_instance:
            self = plugin_manager.instance_get(cls)

        if self is None:
            self = super(Plugin, cls).__new__(cls)
            self.plugin_manager = plugin_manager
            self.plugin_id = cls.__name__.lower()
            from genesis.plugmgr import PluginLoader
            pl, mod = PluginLoader.list_plugins(), cls.__module__.split('.')[0]
            self.plugin_info = pl[mod] if pl.has_key(mod) else None
            # Allow PluginManager implementation to update Plugin
            plugin_manager.plugin_activated(self)

        return self
Example #7
0
    def __new__(cls, *args, **kwargs):
        """ Returns a class instance,
        If it already instantiated, return it
        otherwise return new instance
        """
        if issubclass(cls, PluginManager):
            # If we also a PluginManager, just create and return
            self = super(Plugin, cls).__new__(cls)
            self.plugin_manager = self
            return self

        # Normal case when we are standalone plugin
        self = None
        plugin_manager = args[0]
        if not cls.multi_instance:
            self = plugin_manager.instance_get(cls)

        if self is None:
            self = super(Plugin, cls).__new__(cls)
            self.plugin_manager = plugin_manager
            self.plugin_id = cls.__name__.lower()
            from genesis.plugmgr import PluginLoader
            pl, mod = PluginLoader.list_plugins(), cls.__module__.split('.')[0]
            self.pid = pl[mod].id if pl.has_key(mod) else cls.__module__.split('.')[2]
            self.plugin_info = pl[mod] if pl.has_key(mod) else None
            # Allow PluginManager implementation to update Plugin
            plugin_manager.plugin_activated(self)

        return self
Example #8
0
    def process_dl(self, req, start_response):
        params = req['PATH_INFO'].split('/', 3)
        self.log.debug('Dispatching download: %s'%req['PATH_INFO'])

        path = PluginLoader.get_plugin_path(self.app, params[2])
        file = os.path.join(path, params[2], 'files', params[3])

        return wsgi_serve_file(req, start_response, file)
Example #9
0
    def process_dl(self, req, start_response):
        params = req['PATH_INFO'].split('/', 3)
        self.log.debug('Dispatching download: %s' % req['PATH_INFO'])

        path = PluginLoader.get_plugin_path(self.app, params[2])
        file = os.path.join(path, params[2], 'files', params[3])

        return wsgi_serve_file(req, start_response, file)
Example #10
0
File: main.py Project: bneg/genesis
 def on_click(self, event, params, vars=None):
     if params[0] == 'update':
         self._mgr.update_list()
         self.put_message('info', 'Plugin list updated')
     if params[0] == 'remove':
         self._mgr.remove(params[1])
         self.put_message('info', 'Plugin removed. Refresh page for changes to take effect.')
     if params[0] == 'reload':
         try:
             PluginLoader.unload(params[1])
         except:
             pass
         try:
             PluginLoader.load(params[1])
         except:
             pass
         self.put_message('info', 'Plugin reloaded. Refresh page for changes to take effect.')
     if params[0] == 'restart':
         self.app.restart()
     if params[0] == 'install':
         self._mgr.install(params[1], load=True)
         self.put_message('info', 'Plugin installed. Refresh page for changes to take effect.')
         ComponentManager.get().rescan()
         ConfManager.get().rescan();
Example #11
0
	def scan_plugins(self):
		lst = PluginLoader.list_plugins()
		for c in lst:
			if hasattr(lst[c], 'services'):
				for s in self.servers:
					if lst[c].id == s.plugin_id:
						break
				else:
					for p in lst[c].services:
						try:
							if p['ports'] != []:
								self.add(lst[c].id, p['binary'], p['name'], 
									lst[c].icon, p['ports'])
						except IndexError:
							pass
Example #12
0
 def scan_plugins(self):
     lst = PluginLoader.list_plugins()
     for c in lst:
         if hasattr(lst[c], 'services'):
             for s in self.servers:
                 if lst[c].id == s.plugin_id:
                     break
             else:
                 for p in lst[c].services:
                     try:
                         if p['ports'] != []:
                             self.add(lst[c].id, p['binary'], p['name'],
                                      lst[c].icon, p['ports'])
                     except IndexError:
                         pass
Example #13
0
 def on_click(self, event, params, vars=None):
     if params[0] == 'update':
         self._mgr.update_list()
         self.put_message('info', 'Plugin list updated')
     if params[0] == 'remove':
         self._mgr.remove(params[1])
         self.put_message('info', 'Plugin removed. Refresh page for changes to take effect.')
     if params[0] == 'reload':
         try:
             PluginLoader.unload(params[1])
         except:
             pass
         try:
             PluginLoader.load(params[1])
         except:
             pass
         self.put_message('info', 'Plugin reloaded. Refresh page for changes to take effect.')
     if params[0] == 'restart':
         self.app.restart()
     if params[0] == 'install':
         self._mgr.install(params[1], load=True)
         self.put_message('info', 'Plugin installed. Refresh page for changes to take effect.')
         ComponentManager.get().rescan()
         ConfManager.get().rescan();
Example #14
0
def run_server(log_level=logging.INFO, config_file=''):
    log = make_log(debug=log_level == logging.DEBUG, log_level=log_level)

    # For the debugging purposes
    log.info('Genesis %s' % version())

    # We need this early
    genesis.utils.logger = log

    # Read config
    config = Config()
    if config_file:
        log.info('Using config file %s' % config_file)
        config.load(config_file)
    else:
        log.info('Using default settings')

    # Handle first-launch reconfiguration
    deployed.reconfigure(config)

    # Add log handler to config, so all plugins could access it
    config.set('log_facility', log)

    # Start recording log for the bug reports
    log.blackbox.start()

    arch = genesis.utils.detect_architecture()
    log.info('Detected architecture/hardware: %s, %s' % (arch[0], arch[1]))

    platform = genesis.utils.detect_platform()
    log.info('Detected platform: %s' % platform)

    # Load external plugins
    PluginLoader.initialize(log, config.get('genesis', 'plugins'), arch[0],
                            platform)
    PluginLoader.load_plugins()

    # Start components
    app = Application(config)
    PluginLoader.register_mgr(app)  # Register permanent app
    ComponentManager.create(app)

    # Check system time
    log.info('Verifying system time...')
    os = 0
    try:
        st = genesis.utils.SystemTime()
        os = st.get_offset()
    except Exception, e:
        log.error('System time could not be retrieved. Error: %s' % str(e))
Example #15
0
def run_server(log_level=logging.INFO, config_file=''):
    log = make_log(debug=log_level==logging.DEBUG, log_level=log_level)

    # For the debugging purposes
    log.info('Genesis %s' % version())

    # We need this early
    genesis.utils.logger = log

    # Read config
    config = Config()
    if config_file:
        log.info('Using config file %s'%config_file)
        config.load(config_file)
    else:
        log.info('Using default settings')

    # Handle first-launch reconfiguration
    deployed.reconfigure(config)
    
    # Add log handler to config, so all plugins could access it
    config.set('log_facility',log)

    # Start recording log for the bug reports
    log.blackbox.start()

    arch = genesis.utils.detect_architecture()
    log.info('Detected architecture/hardware: %s, %s'%(arch[0],arch[1]))

    platform = genesis.utils.detect_platform()
    log.info('Detected platform: %s'%platform)

    # Load external plugins
    PluginLoader.initialize(log, config.get('genesis', 'plugins'), arch[0], platform)
    PluginLoader.load_plugins()

    # Start components
    app = Application(config)
    PluginLoader.register_mgr(app) # Register permanent app
    ComponentManager.create(app)

    # Check system time
    log.info('Verifying system time...')
    os = 0
    try:
        st = genesis.utils.SystemTime()
        os = st.get_offset()
    except Exception, e:
        log.error('System time could not be retrieved. Error: %s' % str(e))
Example #16
0
def make_report(app, err):
    """
    Formats a bug report.
    """
    from genesis.plugmgr import PluginLoader
    pr = ''
    k = PluginLoader.list_plugins()
    for p in sorted(k.keys()):
        pr += "%s %s\n" % (p, k[p].version)

    # Finalize the reported log
    app.log.blackbox.stop()

    buf = app.log.blackbox.buffer.split('\n')
    if len(buf) >= 50:
      buf = buf[-50:]
      buf.insert(0, '(Showing only the last 50 entries)\n')
    buf = '\n'.join(buf)

    return (('Genesis %s bug report\n' +
           '--------------------\n\n' +
           'System: %s\n' +
           'Detected platform: %s\n' +
           'Detected distro: %s\n' +
           'Python: %s\n\n' +
           'Config path: %s\n\n' +
           '%s\n\n'
           'Loaded plugins:\n%s\n\n' +
           'Log:\n%s\n'
           )
            % (version(),
               shell('uname -a'),
               detect_platform(),
               detect_distro(),
               '.'.join([str(x) for x in platform.python_version_tuple()]),
               app.config.filename,
               err,
               pr,
               buf,
              ))
Example #17
0
def run_server(log_level=logging.INFO, config_file=''):
    log = make_log(debug=log_level==logging.DEBUG, log_level=log_level)

    # For the debugging purposes
    log.info('Genesis %s' % version())

    # We need this early
    genesis.utils.logger = log

    # Read config
    config = Config()
    if config_file:
        log.info('Using config file %s'%config_file)
        config.load(config_file)
    else:
        log.info('Using default settings')

    # Handle first-launch reconfiguration
    deployed.reconfigure(config)
    
    # Add log handler to config, so all plugins could access it
    config.set('log_facility',log)

    # Start recording log for the bug reports
    log.blackbox.start()

    platform = genesis.utils.detect_platform()
    log.info('Detected platform: %s'%platform)

    # Load external plugins
    PluginLoader.initialize(log, config.get('genesis', 'plugins'), platform)
    PluginLoader.load_plugins()

    # Start components
    app = Application(config)
    PluginLoader.register_mgr(app) # Register permanent app
    ComponentManager.create(app)

    # Make sure correct kernel modules are enabled
    genesis.utils.shell('modprobe ip_tables')

    # Start server
    host = config.get('genesis','bind_host')
    port = config.getint('genesis','bind_port')
    log.info('Listening on %s:%d'%(host, port))

    # SSL params
    ssl = {}
    if config.getint('genesis', 'ssl') == 1:
        ssl = {
    	    'keyfile':  config.get('genesis','cert_key'),
    	    'certfile': config.get('genesis','cert_file'),
    	}

    log.info('Using HTTP server: %s'%http_server)

    server = WSGIServer(
        (host, port),
        application=AppDispatcher(config).dispatcher,
        **ssl
    )

    config.set('server', server)

    try:
        syslog.openlog(
            ident='genesis',
            facility=syslog.LOG_AUTH,
        )
    except:
        syslog.openlog('genesis')

    log.info('Starting server')

    server.serve_forever()

    ComponentManager.get().stop()

    if hasattr(server, 'restart_marker'):
        log.info('Restarting by request')

        fd = 20 # Close all descriptors. Creepy thing
        while fd > 2:
            try:
                os.close(fd)
                log.debug('Closed descriptor #%i'%fd)
            except:
                pass
            fd -= 1

        os.execv(sys.argv[0], sys.argv)
    else:
        log.info('Stopped by request')
Example #18
0
File: main.py Project: tewe/genesis
     except Exception, e:
         self.put_message('err', str(e))
         self.app.log.error(str(e))
     else:
         self.put_message('info', 'Plugin list updated')
 if params[0] == 'remove':
     try:
         self._mgr.check_conflict(params[1], 'remove')
         lr = LiveRemove(self._mgr, params[1], self)
         lr.start()
         self._nc.remove(params[1])
     except ImSorryDave, e:
         self.put_message('err', str(e))
 if params[0] == 'reload':
     try:
         PluginLoader.unload(params[1])
     except:
         pass
     try:
         PluginLoader.load(params[1])
     except:
         pass
     self.put_message(
         'info',
         'Plugin reloaded. Refresh page for changes to take effect.')
 if params[0] == 'restart':
     self.app.restart()
 if params[0] == 'install':
     try:
         self._mgr.check_conflict(params[1], 'install')
         li = LiveInstall(self._mgr, params[1], True, self)
Example #19
0
    def refresh_plugin_data(self):
        """
        Rescans plugins for JS, CSS, LESS, XSLT widgets and XML templates.
        """
        self.template_path = []
        self.less_styles = []
        self.woff_fonts = []
        self.eot_fonts = []
        self.svg_fonts = []
        self.ttf_fonts = []
        self.template_styles = []
        self.template_scripts = []
        self.layouts = {}
        includes = []
        functions = {}

        for f in self.grab_plugins(IXSLTFunctionProvider):
            functions.update(f.get_funcs())

        # Get path for static content and templates
        plugins = []
        plugins.extend(PluginLoader.list_plugins().keys())
        plugins.extend(genesis.plugins.plist)

        for c in plugins:
            path = os.path.join(PluginLoader.get_plugin_path(self, c), c)

            fp = os.path.join(path, 'files')
            if os.path.exists(fp):
                self.template_styles.extend([
                    '/dl/' + c + '/' + s for s in os.listdir(fp)
                    if s.endswith('.css')
                ])
                self.less_styles.extend([
                    '/dl/' + c + '/' + s for s in os.listdir(fp)
                    if s.endswith('.less')
                ])
                self.woff_fonts.extend([
                    '/dl/' + c + '/' + s for s in os.listdir(fp)
                    if s.endswith('.woff')
                ])
                self.eot_fonts.extend([
                    '/dl/' + c + '/' + s for s in os.listdir(fp)
                    if s.endswith('.eot')
                ])
                self.svg_fonts.extend([
                    '/dl/' + c + '/' + s for s in os.listdir(fp)
                    if s.endswith('.svg')
                ])
                self.ttf_fonts.extend([
                    '/dl/' + c + '/' + s for s in os.listdir(fp)
                    if s.endswith('.ttf')
                ])
                self.template_scripts.extend([
                    '/dl/' + c + '/' + s for s in os.listdir(fp)
                    if s.endswith('.js')
                ])

            wp = os.path.join(path, 'widgets')
            if os.path.exists(wp):
                includes.extend([
                    os.path.join(wp, s) for s in os.listdir(wp)
                    if s.endswith('.xslt')
                ])

            lp = os.path.join(path, 'layout')
            if os.path.exists(lp):
                for s in os.listdir(lp):
                    if s.endswith('.xml'):
                        self.layouts['%s:%s' % (c, s)] = os.path.join(lp, s)

            tp = os.path.join(path, 'templates')
            if os.path.exists(tp):
                self.template_path.append(tp)

        if xslt.xslt is None:
            xslt.prepare(includes, functions)
Example #20
0
     except Exception, e:
         self.put_message('err', str(e))
         self.app.log.error(str(e))
     else:
         self.put_message('info', 'Plugin list updated')
 if params[0] == 'remove':
     try:
         self._mgr.check_conflict(params[1], 'remove')
         lr = LiveRemove(self._mgr, params[1], self)
         lr.start()
         self._nc.remove(params[1])
     except ImSorryDave, e:
         self.put_message('err', str(e))
 if params[0] == 'reload':
     try:
         PluginLoader.unload(params[1])
     except:
         pass
     try:
         PluginLoader.load(params[1])
     except:
         pass
     self.put_message('info', 'Plugin reloaded. Refresh page for changes to take effect.')
 if params[0] == 'restart':
     self.app.restart()
 if params[0] == 'install':
     try:
         self._mgr.check_conflict(params[1], 'install')
         li = LiveInstall(self._mgr, params[1], 
             True, self)
         li.start()
Example #21
0
    def refresh_plugin_data(self):
        """
        Rescans plugins for JS, CSS, LESS, XSLT widgets and XML templates.
        """
        self.template_path = []
        self.less_styles = []
        self.template_styles = []
        self.template_scripts = []
        self.layouts = {}
        includes = []
        functions = {}

        for f in self.grab_plugins(IXSLTFunctionProvider):
            functions.update(f.get_funcs())

        # Get path for static content and templates
        plugins = []
        plugins.extend(PluginLoader.list_plugins().keys())
        plugins.extend(genesis.plugins.plist)

        for c in plugins:
            path = os.path.join(PluginLoader.get_plugin_path(self, c), c)

            fp = os.path.join(path, 'files')
            if os.path.exists(fp):
                self.template_styles.extend([
                    '/dl/'+c+'/'+s
                    for s in os.listdir(fp)
                    if s.endswith('.css')
                ])
                self.less_styles.extend([
                    '/dl/'+c+'/'+s
                    for s in os.listdir(fp)
                    if s.endswith('.less')
                ])
                self.template_scripts.extend([
                    '/dl/'+c+'/'+s
                    for s in os.listdir(fp)
                    if s.endswith('.js')
                ])

            wp = os.path.join(path, 'widgets')
            if os.path.exists(wp):
                includes.extend([
                    os.path.join(wp, s)
                    for s in os.listdir(wp)
                    if s.endswith('.xslt')
                ])

            lp = os.path.join(path, 'layout')
            if os.path.exists(lp):
                for s in os.listdir(lp):
                    if s.endswith('.xml'):
                        self.layouts['%s:%s'%(c,s)] = os.path.join(lp, s)

            tp = os.path.join(path, 'templates')
            if os.path.exists(tp):
                self.template_path.append(tp)

        if xslt.xslt is None:
            xslt.prepare(
                includes,
                functions
            )
Example #22
0
def run_server(log_level=logging.INFO, config_file=''):
    log = make_log(debug=log_level == logging.DEBUG, log_level=log_level)

    # For the debugging purposes
    log.info('Genesis %s' % version())

    # We need this early
    genesis.utils.logger = log

    # Read config
    config = Config()
    if config_file:
        log.info('Using config file %s' % config_file)
        config.load(config_file)
    else:
        log.info('Using default settings')

    # Handle first-launch reconfiguration
    deployed.reconfigure(config)

    # Add log handler to config, so all plugins could access it
    config.set('log_facility', log)

    # Start recording log for the bug reports
    log.blackbox.start()

    platform = genesis.utils.detect_platform()
    log.info('Detected platform: %s' % platform)

    # Load external plugins
    PluginLoader.initialize(log, config.get('genesis', 'plugins'), platform)
    PluginLoader.load_plugins()

    # Start components
    app = Application(config)
    PluginLoader.register_mgr(app)  # Register permanent app
    ComponentManager.create(app)

    # Make sure correct kernel modules are enabled
    genesis.utils.shell('modprobe ip_tables')

    # Start server
    host = config.get('genesis', 'bind_host')
    port = config.getint('genesis', 'bind_port')
    log.info('Listening on %s:%d' % (host, port))

    # SSL params
    ssl = {}
    if config.getint('genesis', 'ssl') == 1:
        ssl = {
            'keyfile': config.get('genesis', 'cert_key'),
            'certfile': config.get('genesis', 'cert_file'),
        }

    log.info('Using HTTP server: %s' % http_server)

    server = WSGIServer((host, port),
                        application=AppDispatcher(config).dispatcher,
                        **ssl)

    config.set('server', server)

    try:
        syslog.openlog(
            ident='genesis',
            facility=syslog.LOG_AUTH,
        )
    except:
        syslog.openlog('genesis')

    log.info('Starting server')

    server.serve_forever()

    ComponentManager.get().stop()

    if hasattr(server, 'restart_marker'):
        log.info('Restarting by request')

        fd = 20  # Close all descriptors. Creepy thing
        while fd > 2:
            try:
                os.close(fd)
                log.debug('Closed descriptor #%i' % fd)
            except:
                pass
            fd -= 1

        os.execv(sys.argv[0], sys.argv)
    else:
        log.info('Stopped by request')