def main(): # pragma: no cover, not mesured by coverage! """ Called when this module is started from shell """ global cfg_file, app_config, app_webui # ---------------------------------------------------------------------------------------------- # Command line parameters if __name__ == "__main__": # pragma: no cover, not mesured by coverage! try: args = docopt(__doc__, version=manifest['version']) except DocoptExit: print "Command line parsing error" exit(64) else: args = { '--debug': False, '--backend': None, '--hostname': None, '--port': None, '--exit': False } # Application settings # ---------------------------------------------------------------------------------------------- # Configuration file path in command line parameters if '<cfg_file>' in args: cfg_file = args['<cfg_file>'] if cfg_file and isinstance(cfg_file, list): cfg_file = cfg_file[0] # Read configuration file app_config = Settings(cfg_file) new_config_file = app_config.read(manifest['name']) print "Configuration read from: %s" % new_config_file if not app_config: # pragma: no cover, should never happen print "Required configuration file not found." exit(1) # Store application name in the configuration app_config['name'] = manifest['name'] if '--debug' in args and args['--debug']: # pragma: no cover, not mesured by coverage! app_config['debug'] = '1' print "Application is in debug mode from command line" if os.environ.get('WEBUI_DEBUG'): # pragma: no cover, not mesured by coverage! app_config['debug'] = '1' print "Application is in debug mode from environment" # Applications backend URL if args['--backend']: # pragma: no cover, not mesured by coverage! app_config['alignak_backend'] = args['--backend'] # WebUI server configuration if args['--hostname']: # pragma: no cover, not mesured by coverage! app_config['host'] = args['--hostname'] if args['--port']: # pragma: no cover, not mesured by coverage! app_config['port'] = args['--port'] # Make the configuration available globally for the package set_app_config(app_config) # Make the application available globally for the package app_webui = set_app_webui(WebUI()) try: logger.info( "--------------------------------------------------------------------------------" ) logger.info( "%s, listening on %s:%d (debug mode: %s)", app_config.get('name', 'Test'), app_config.get('host', '127.0.0.1'), int(app_config.get('port', '8868')), app_config.get('debug', '0') == '1' ) logger.info( "%s, using applications backend on %s", app_config.get('name', 'Test'), app_config['alignak_backend'] ) logger.info( "--------------------------------------------------------------------------------" ) if args['--exit']: print "Application exit because of command line parameter" exit(99) # Run application server... run( app=webapp, host=app_config.get('host', '127.0.0.1'), port=int(app_config.get('port', 8868)), debug=(app_config.get('debug', '0') == '1'), server=app_config.get('http_backend', 'cherrypy') ) except Exception as e: logger.error("Application run failed, exception: %s / %s", type(e), str(e)) logger.info("Backtrace: %s", traceback.format_exc()) logger.info("stopping backend livestate thread...") exit(2)
def main(): # pragma: no cover, not mesured by coverage! # pylint: disable=redefined-variable-type, global-statement """ Called when this module is started from shell """ global cfg_file, app_config, app_webui # ---------------------------------------------------------------------------------------------- # Command line parameters args = { '--debug': False, '--backend': None, '--hostname': None, '--port': None, '--exit': False } if __name__ == "__main__": # pragma: no cover, not mesured by coverage! try: args = docopt(__doc__, version=manifest['version']) except DocoptExit: print("Command line parsing error") exit(64) # Application settings # ---------------------------------------------------------------------------------------------- # Configuration file path in command line parameters if '<cfg_file>' in args: cfg_file = args['<cfg_file>'] if cfg_file and isinstance(cfg_file, list): cfg_file = cfg_file[0] # Read configuration file app_config = Settings(cfg_file) new_config_file = app_config.read(manifest['name']) print("Configuration read from: %s" % new_config_file) if not app_config: # pragma: no cover, should never happen print("Required configuration file not found.") exit(1) # Store application name in the configuration app_config['name'] = manifest['name'] if '--debug' in args and args['--debug']: # pragma: no cover, not mesured by coverage! app_config['debug'] = '1' print("Application is in debug mode from command line") if os.environ.get('WEBUI_DEBUG'): # pragma: no cover, not mesured by coverage! app_config['debug'] = '1' print("Application is in debug mode from environment") # Applications backend URL if args['--backend']: # pragma: no cover, not mesured by coverage! app_config['alignak_backend'] = args['--backend'] # WebUI server configuration if args['--hostname']: # pragma: no cover, not mesured by coverage! app_config['host'] = args['--hostname'] if args['--port']: # pragma: no cover, not mesured by coverage! app_config['port'] = args['--port'] # Make the configuration available globally for the package set_app_config(app_config) # Make the application available globally for the package app_webui = set_app_webui(WebUI(app_config)) try: if args['--exit']: print("Application exit because of command line parameter") exit(99) # Run application server... run( app=webapp, host=app_config.get('host', '127.0.0.1'), port=int(app_config.get('port', 5001)), debug=(app_config.get('debug', '0') == '1'), server=app_config.get('http_backend', 'cherrypy') ) except Exception as e: logger.error("Application run failed, exception: %s / %s", type(e), str(e)) logger.info("Backtrace: %s", traceback.format_exc()) logger.info("stopping backend livestate thread...") exit(2)
cfg_file = os.environ.get('TEST_WEBUI_CFG') print "Application configuration file name from environment: %s" % cfg_file # Read configuration file app_config = Settings(cfg_file) config_file = app_config.read(manifest['name']) print "Configuration read from: %s" % config_file if not app_config: # pragma: no cover, should never happen print "Required configuration file not found." exit(1) # Store application name in the configuration app_config['name'] = manifest['name'] # Debug mode for the application (run Bottle in debug mode) app_config['debug'] = (app_config.get('debug', '0') == '1') print "Application debug mode: %s" % app_config['debug'] if __name__ != "__main__": # Make the configuration available globally for the package set_app_config(app_config) # Make the application available globally for the package app_webui = set_app_webui(WebUI()) # -------------------------------------------------------------------------------------------------- # Main function def main(): # pragma: no cover, not mesured by coverage! """ Called when this module is started from shell
cfg_file = os.environ.get('ALIGNAK_WEBUI_CONFIGURATION_FILE') print("Application configuration file name from environment: %s" % cfg_file) # Read configuration file app_config = Settings(cfg_file) config_file = app_config.read(manifest['name']) print("Configuration read from: %s" % config_file) if not app_config: # pragma: no cover, should never happen print("Required configuration file not found.") exit(1) # Store application name in the configuration app_config['name'] = manifest['name'] # Debug mode for the application (run Bottle in debug mode) app_config['debug'] = (app_config.get('debug', '0') == '1') print("Application debug mode: %s" % app_config['debug']) if __name__ != "__main__": # Make the configuration available globally for the package set_app_config(app_config) # Make the application available globally for the package app_webui = set_app_webui(WebUI(app_config)) # -------------------------------------------------------------------------------------------------- # Main function def main(): # pragma: no cover, not mesured by coverage! # pylint: disable=redefined-variable-type, global-statement """