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, ))
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, ))
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))
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))
def process(self, req, start_response): self.do_init() if self.is_firstrun(): templ = self.app.get_template('firstrun.xml') else: templ = self.app.get_template('index.xml') if self.app.platform == 'arkos': templ.remove('navbar-brand') templ.append('navbar-brand-div', UI.Image(cls='navbar-brand', file='/dl/core/ui/arkos.png')) # Sort plugins into menus where necessary cats = self.app.grab_plugins(ICategoryProvider) cats = sorted(cats, key=lambda p: p.text) if not self.is_firstrun(): for c in cats: if c.folder in ['top', 'bottom']: templ.append( 'topplaceholder-'+c.folder, UI.TopCategory( text=c.text, id=c.plugin_id, iconfont=c.iconfont, counter=c.get_counter(), selected=c==self.selected_category ) ) elif c.folder == 'tools': templ.append( 'tools-placeholder', UI.PopoverLink(iconfont=c.iconfont, text=c.text, onclick="Genesis.selectCategory('"+c.plugin_id+"');", ) ) templ.append('_head', UI.HeadTitle(text='Genesis @ %s'%platform.node())) templ.append('version', UI.Label(text='Genesis '+version(), size=2)) templ.insertText('cat-username', self.app.auth.user) templ.appendAll('links', UI.LinkLabel(iconfont='gen-info', text='About', id='about'), ) return templ.render()
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, ))
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')
def process(self, req, start_response): self.do_init() templ = self.app.get_template("index.xml") cat = None v = UI.VContainer(spacing=0) # Sort plugins by name cats = self.app.grab_plugins(ICategoryProvider) cats = sorted(cats, key=lambda p: p.text) for fld in self.folder_ids: cat_vc = UI.VContainer(spacing=0) if self.folders[fld] == "": cat_folder = cat_vc # Omit wrapper for special folders else: cat_folder = UI.CategoryFolder( cat_vc, text=self.folders[fld], icon="/dl/core/ui/catfolders/" + fld + ".png" if self.folders[fld] != "" else "", id=fld, ) # cat_vc will be VContainer or CategoryFolder exp = False empty = True for c in cats: if c.folder == fld: # Put corresponding plugins in this folder empty = False if c == self.selected_category: exp = True cat_vc.append( UI.Category( icon=c.icon, name=c.text, id=c.plugin_id, counter=c.get_counter(), selected=c == self.selected_category, ) ) if not empty: v.append(cat_folder) cat_folder["expanded"] = exp for c in cats: if c.folder in ["top", "bottom"]: templ.append( "topplaceholder-" + c.folder, UI.TopCategory( text=c.text, id=c.plugin_id, icon=c.icon, counter=c.get_counter(), selected=c == self.selected_category, ), ) templ.append("_head", UI.HeadTitle(text="Genesis @ %s" % platform.node())) templ.append("leftplaceholder", v) templ.append("version", UI.Label(text="Genesis " + version(), size=2)) templ.insertText("cat-username", self.app.auth.user) templ.appendAll( "links", UI.LinkLabel(text="About", id="about"), UI.OutLinkLabel(text="License", url="http://www.gnu.org/licenses/lgpl.html"), ) return templ.render()
def get_ui_about(self): ui = self.app.inflate("core:about") ui.find("ver").set("text", version()) return ui
def get_ui_about(self): ui = self.app.inflate('core:about') ui.find('ver').set('text', version()) return ui
def process(self, req, start_response): self.do_init() templ = self.app.get_template('index.xml') cat = None v = UI.VContainer(spacing=0) # Sort plugins by name cats = self.app.grab_plugins(ICategoryProvider) cats = sorted(cats, key=lambda p: p.text) for fld in self.folder_ids: cat_vc = UI.VContainer(spacing=0) if self.folders[fld] == '': cat_folder = cat_vc # Omit wrapper for special folders else: cat_folder = UI.CategoryFolder( cat_vc, text=self.folders[fld], icon='/dl/core/ui/catfolders/'+ fld + '.png' if self.folders[fld] != '' else '', id=fld ) # cat_vc will be VContainer or CategoryFolder exp = False empty = True for c in cats: if c.folder == fld: # Put corresponding plugins in this folder empty = False if c == self.selected_category: exp = True cat_vc.append(UI.Category( iconfont=c.iconfont, name=c.text, id=c.plugin_id, counter=c.get_counter(), selected=c == self.selected_category )) if not empty: v.append(cat_folder) cat_folder['expanded'] = exp for c in cats: if c.folder in ['top', 'bottom']: templ.append( 'topplaceholder-'+c.folder, UI.TopCategory( text=c.text, id=c.plugin_id, iconfont=c.iconfont, counter=c.get_counter(), selected=c==self.selected_category ) ) templ.append('_head', UI.HeadTitle(text='Genesis @ %s'%platform.node())) templ.append('leftplaceholder', v) templ.append('version', UI.Label(text='Genesis '+version(), size=2)) templ.insertText('cat-username', self.app.auth.user) templ.appendAll('links', UI.LinkLabel(iconfont='gen-info', text='About', id='about'), UI.OutLinkLabel(iconfont='gen-certificate', text='License', url='http://www.gnu.org/licenses/gpl.html') ) return templ.render()
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')