def refresh_standalone_status(self): if convert_text_to_bool(Config.get_config_value('Webserver', 'enable')) is True: self.standalone_status_text.set_text('Standalone app is enabled') self.standalone_status.set_attr_map({None: 'text green'}) else: self.standalone_status_text.set_text('Standalone app is disabled') self.standalone_status.set_attr_map({None: 'text red'})
def __init__(self): cr.cli.WindowCli.__init__(self) title = 'Standalone app configuration' subtitle = 'CentralReport includes a web server. You can check your statistics with a simple web ' \ 'browser, without any external service.' question = 'Do you want to activate the standalone app?' self.group = list() self.items = list() self.radios = list() self.choices = ['Yes', 'No'] for choice in self.choices: self.radios.append( cr.cli.create_radio_item(self.group, choice, None)) self.items.append(self.radios[-1]) if convert_text_to_bool( cr_config.get_config_value('Webserver', 'enable')): self.items[0].set_state(True) else: self.items[1].set_state(True) self.port_caption = urwid.Text('Port number: ', align='right') self.port_edit_box = urwid.IntEdit( default=int(cr_config.get_config_value('Webserver', 'port'))) self.port_edit = urwid.AttrMap(self.port_edit_box, 'text', 'select') self.port_columns = urwid.Columns([self.port_caption, self.port_edit]) button_ok = cr.cli.create_button('OK', self.validate) button_ok_grid = urwid.GridFlow([button_ok], 6, 2, 0, 'center') self.menu = [urwid.Divider(), urwid.Text(title), urwid.Divider(), urwid.Text(subtitle), urwid.Divider(), urwid.Text(question)] + \ self.items + \ [urwid.Divider(), self.port_columns, urwid.Divider(), button_ok_grid] self.list_box = urwid.ListBox(urwid.SimpleListWalker(self.menu)) self.content = urwid.Columns([self.list_box], focus_column=0)
def __init__(self): cr.cli.WindowCli.__init__(self) title = 'Standalone app configuration' subtitle = 'CentralReport includes a web server. You can check your statistics with a simple web ' \ 'browser, without any external service.' question = 'Do you want to activate the standalone app?' self.group = list() self.items = list() self.radios = list() self.choices = ['Yes', 'No'] for choice in self.choices: self.radios.append(cr.cli.create_radio_item(self.group, choice, None)) self.items.append(self.radios[-1]) if convert_text_to_bool(cr_config.get_config_value('Webserver', 'enable')): self.items[0].set_state(True) else: self.items[1].set_state(True) self.port_caption = urwid.Text('Port number: ', align='right') self.port_edit_box = urwid.IntEdit(default=int(cr_config.get_config_value('Webserver', 'port'))) self.port_edit = urwid.AttrMap(self.port_edit_box, 'text', 'select') self.port_columns = urwid.Columns([self.port_caption, self.port_edit]) button_ok = cr.cli.create_button('OK', self.validate) button_ok_grid = urwid.GridFlow([button_ok], 6, 2, 0, 'center') self.menu = [urwid.Divider(), urwid.Text(title), urwid.Divider(), urwid.Text(subtitle), urwid.Divider(), urwid.Text(question)] + \ self.items + \ [urwid.Divider(), self.port_columns, urwid.Divider(), button_ok_grid] self.list_box = urwid.ListBox(urwid.SimpleListWalker(self.menu)) self.content = urwid.Columns([self.list_box], focus_column=0)
def test_wrong_value(self): self.assertNotEqual(cr_text.convert_text_to_bool('hello'), True)
def test_false(self): self.assertEqual(cr_text.convert_text_to_bool('false'), False)
def test_t(self): self.assertEqual(cr_text.convert_text_to_bool('t'), True)
def run(self): """ Constructor. """ is_error = False # If True, there are one or more errors when CentralReport is trying to start log.log_info("------------------------------------------------") log.log_info("CentralReport is starting...") log.log_info("Current user: "******"Debug", "log_level") except: log_level = "INFO" log.change_log_level(log_level) # Starting the check thread... if host.get_current_host().os != host.OS_UNKNOWN: log.log_info("%s detected. Starting ThreadChecks..." % host.get_current_host().os) CentralReport.checks_thread = threads.Checks() # Launching checks thread else: is_error = True log.log_critical("Sorry, but your OS is not supported yet...") # Starting the internal webserver... if not is_error and text.convert_text_to_bool(Config.get_config_value("Webserver", "enable")): local_web_port = int(Config.get_config_value("Webserver", "port")) if not utils_web.check_port("127.0.0.1", local_web_port): log.log_info("Starting the webserver...") # Importing the module here improve the memory usage import cr.web CentralReport.webserver_thread = cr.web.server.WebServer() else: log.log_error("Error launching the webserver: port %s is already in use on this host!" % local_web_port) else: log.log_info("Webserver is disabled by configuration file!") if not is_error: log.log_info("CentralReport started!") while CentralReport.is_running: if not Config.CR_CONFIG_ENABLE_DEBUG_MODE: # If .pid file is not found, we must stop CR (only in production environment) try: pf = file(self.pidfile, "r") pf.close() except IOError: log.log_error("Pid file is not found. CentralReport must stop itself.") CentralReport.is_running = False self.stop() time.sleep(1) else: log.log_error("Error launching CentralReport!")
def run(self): """ Constructor. """ is_error = False # If True, there are one or more errors when CentralReport is trying to start log.log_info('------------------------------------------------') log.log_info('CentralReport is starting...') log.log_info('Current user: '******'Debug', 'log_level') except: log_level = 'INFO' log.change_log_level(log_level) # Starting the check thread... if host.get_current_host().os != host.OS_UNKNOWN: log.log_info('%s detected. Starting ThreadChecks...' % host.get_current_host().os) CentralReport.checks_thread = threads.Checks( ) # Launching checks thread else: is_error = True log.log_critical('Sorry, but your OS is not supported yet...') # Starting the internal webserver... if not is_error and text.convert_text_to_bool( Config.get_config_value('Webserver', 'enable')): local_web_port = int(Config.get_config_value('Webserver', 'port')) if not utils_web.check_port('127.0.0.1', local_web_port): log.log_info('Starting the webserver...') # Importing the module here improve the memory usage import cr.web CentralReport.webserver_thread = cr.web.server.WebServer() else: log.log_error( 'Error launching the webserver: port %s is already in use on this host!' % local_web_port) else: log.log_info('Webserver is disabled by configuration file!') if not is_error: log.log_info('CentralReport started!') while CentralReport.is_running: if not Config.CR_CONFIG_ENABLE_DEBUG_MODE: # If .pid file is not found, we must stop CR (only in production environment) try: pf = file(self.pidfile, 'r') pf.close() except IOError: log.log_error( 'Pid file is not found. CentralReport must stop itself.' ) CentralReport.is_running = False self.stop() time.sleep(1) else: log.log_error('Error launching CentralReport!')