def _do_run(klass, config_path=None, values_source_list=None): # while this method is defined here, only derived classes are allowed # to call it. if klass is SocorroApp: raise NotImplementedError( "The SocorroApp class has no useable 'main' method") if config_path is None: config_path = os.environ.get('DEFAULT_SOCORRO_CONFIG_PATH', './config') if values_source_list is None: values_source_list = [ # pull in the application defaults from the 'application' # configman option, once it has been defined application_defaults_proxy, # pull in any configuration file ConfigFileFutureProxy, # get values from the environment environment, # use the command line to get the final overriding values command_line ] elif application_defaults_proxy not in values_source_list: values_source_list = ([application_defaults_proxy] + values_source_list) config_definition = klass.get_required_config() if 'application' not in config_definition: # the application option has not been defined. This means that # the we're likely trying to run one of the applications directly # rather than through the SocorroWelocomApp. Add the 'application' # option initialized with the target application as the default. application_config = Namespace() application_config.add_option( 'application', doc=('the fully qualified classname of the app to run'), default=klass_to_pypath(klass), # the following setting means this option will NOT be # commented out when configman generates a config file likely_to_be_changed=True, from_string_converter=( application_defaults_proxy.str_to_application_class), ) config_definition = application_config config_manager = ConfigurationManager( config_definition, app_name=klass.app_name, app_version=klass.app_version, app_description=klass.app_description, values_source_list=values_source_list, options_banned_from_help=[], config_pathname=config_path) def fix_exit_code(code): # some apps don't return a code so you might get None # which isn't good enough to send to sys.exit() if code is None: return 0 return code with config_manager.context() as config: config.executor_identity = ( lambda: threading.currentThread().getName()) try: config_manager.log_config(config.logger) respond_to_SIGHUP_with_logging = functools.partial( respond_to_SIGHUP, logger=config.logger) # install the signal handler with logging signal.signal(signal.SIGHUP, respond_to_SIGHUP_with_logging) except KeyError: # config apparently doesn't have 'logger' # install the signal handler without logging signal.signal(signal.SIGHUP, respond_to_SIGHUP) # we finally know what app to actually run, instantiate it app_to_run = klass(config) app_to_run.config_manager = config_manager # whew, finally run the app that we wanted return_code = fix_exit_code(app_to_run.main()) return return_code
def _do_run(klass, config_path=None, values_source_list=None): # while this method is defined here, only derived classes are allowed # to call it. if klass is SocorroApp: raise NotImplementedError( "The SocorroApp class has no useable 'main' method" ) if config_path is None: config_path = os.environ.get( 'DEFAULT_SOCORRO_CONFIG_PATH', './config' ) if values_source_list is None: values_source_list = [ # pull in the application defaults from the 'application' # configman option, once it has been defined application_defaults_proxy, # pull in any configuration file ConfigFileFutureProxy, # get values from the environment environment, # use the command line to get the final overriding values command_line ] elif application_defaults_proxy not in values_source_list: values_source_list = ( [application_defaults_proxy] + values_source_list ) config_definition = klass.get_required_config() if 'application' not in config_definition: # the application option has not been defined. This means that # the we're likely trying to run one of the applications directly # rather than through the SocorroWelocomApp. Add the 'application' # option initialized with the target application as the default. application_config = Namespace() application_config.add_option( 'application', doc=( 'the fully qualified classname of the app to run' ), default=klass_to_pypath(klass), # the following setting means this option will NOT be # commented out when configman generates a config file likely_to_be_changed=True, from_string_converter=( application_defaults_proxy.str_to_application_class ), ) config_definition = application_config config_manager = ConfigurationManager( config_definition, app_name=klass.app_name, app_version=klass.app_version, app_description=klass.app_description, values_source_list=values_source_list, options_banned_from_help=[], config_pathname=config_path ) def fix_exit_code(code): # some apps don't return a code so you might get None # which isn't good enough to send to sys.exit() if code is None: return 0 return code with config_manager.context() as config: config.executor_identity = ( lambda: threading.currentThread().getName() ) try: config_manager.log_config(config.logger) respond_to_SIGHUP_with_logging = functools.partial( respond_to_SIGHUP, logger=config.logger ) # install the signal handler with logging signal.signal(signal.SIGHUP, respond_to_SIGHUP_with_logging) except KeyError: # config apparently doesn't have 'logger' # install the signal handler without logging signal.signal(signal.SIGHUP, respond_to_SIGHUP) # we finally know what app to actually run, instantiate it app_to_run = klass(config) app_to_run.config_manager = config_manager # whew, finally run the app that we wanted return_code = fix_exit_code(app_to_run.main()) return return_code
definitions = ( app_definition, logging_required_config(app_name) ) config_manager = ConfigurationManager( definitions, app_name=app_name, app_version=app_version, app_description=app_description, values_source_list=values_source_list, ) with config_manager.context() as config: config_manager.log_config(config.logger) # get the app class from configman. Why bother since we have it aleady # with the 'initial_app' name? In most cases initial_app == app, # it might not always be that way. The user always has the ability # to specify on the command line a new app class that will override # 'initial_app'. app = config.application if isinstance(app, type): # invocation of the app if the app_object was a class instance = app(config) instance.main() elif inspect.ismodule(app): # invocation of the app if the app_object was a module app.main(config)
definitions = ( app_definition, logging_required_config(app_name) ) config_manager = ConfigurationManager( definitions, app_name=app_name, app_version=app_version, app_description=app_description, values_source_list=values_source_list, config_pathname=config_path ) with config_manager.context() as config: config_manager.log_config(config.logger) # get the app class from configman. Why bother since we have it aleady # with the 'initial_app' name? In most cases initial_app == app, # it might not always be that way. The user always has the ability # to specify on the command line a new app class that will override # 'initial_app'. app = config.application if isinstance(app, type): # invocation of the app if the app_object was a class instance = app(config) instance.main() elif inspect.ismodule(app): # invocation of the app if the app_object was a module app.main(config)
def run(cls, config_path=None, values_source_list=None): # NOTE(willkg): This is a classmethod, so we need a different logger. mylogger = logging.getLogger(__name__ + "." + cls.__name__) if config_path is None: config_path = os.environ.get("DEFAULT_SOCORRO_CONFIG_PATH", "./config") if values_source_list is None: values_source_list = [ # pull in any configuration file ConfigFileFutureProxy, # get values from the environment environment, # use the command line to get the final overriding values command_line, ] # Pull base set of defaults from the config module if it is specified if cls.config_defaults is not None: values_source_list.insert(0, cls.config_defaults) config_definition = cls.get_required_config() if "application" not in config_definition: # FIXME(mkelly): We used to have a SocorroWelcomeApp that defined an # "application" option. We no longer have that. This section should # get reworked possibly as part of getting rid of application # defaults. application_config = Namespace() application_config.add_option( "application", doc="the fully qualified classname of the app to run", default=cls_to_pypath(cls), # the following setting means this option will NOT be # commented out when configman generates a config file likely_to_be_changed=True, from_string_converter=str_to_python_object, ) config_definition = application_config config_manager = ConfigurationManager( config_definition, app_name=cls.app_name, app_version=cls.app_version, app_description=cls.app_description, values_source_list=values_source_list, options_banned_from_help=[], config_pathname=config_path, ) def fix_exit_code(code): # some apps don't return a code so you might get None # which isn't good enough to send to sys.exit() if code is None: return 0 return code with config_manager.context() as config: setup_logging(config) setup_metrics(config) # Log revision information revision_data = get_revision_data() revision_items = sorted(revision_data.items()) mylogger.info( "version.json: {%s}", ", ".join( ["%r: %r" % (key, val) for key, val in revision_items]), ) config_manager.log_config(mylogger) # Add version to crash reports version = get_version(revision_data) setup_crash_reporting(config, version) # we finally know what app to actually run, instantiate it app_to_run = cls(config) app_to_run.config_manager = config_manager # whew, finally run the app that we wanted return_code = fix_exit_code(app_to_run.main()) return return_code
def _do_run(klass, config_path=None, values_source_list=None): # while this method is defined here, only derived classes are allowed # to call it. if klass is SocorroApp: raise NotImplementedError( "The SocorroApp class has no useable 'main' method") if config_path is None: config_path = os.environ.get('DEFAULT_SOCORRO_CONFIG_PATH', './config') if values_source_list is None: values_source_list = [ # pull in any configuration file ConfigFileFutureProxy, # get values from the environment environment, # use the command line to get the final overriding values command_line ] # Pull base set of defaults from the config module if it is specified if klass.config_defaults is not None: values_source_list.insert(0, klass.config_defaults) config_definition = klass.get_required_config() if 'application' not in config_definition: # FIXME(mkelly): We used to have a SocorroWelcomeApp that defined an # "application" option. We no longer have that. This section should # get reworked possibly as part of getting rid of application # defaults. application_config = Namespace() application_config.add_option( 'application', doc=('the fully qualified classname of the app to run'), default=klass_to_pypath(klass), # the following setting means this option will NOT be # commented out when configman generates a config file likely_to_be_changed=True, from_string_converter=str_to_python_object, ) config_definition = application_config config_manager = ConfigurationManager( config_definition, app_name=klass.app_name, app_version=klass.app_version, app_description=klass.app_description, values_source_list=values_source_list, options_banned_from_help=[], config_pathname=config_path) def fix_exit_code(code): # some apps don't return a code so you might get None # which isn't good enough to send to sys.exit() if code is None: return 0 return code with config_manager.context() as config: config.executor_identity = ( lambda: threading.currentThread().getName()) spit_out_version_json(config.logger) try: config_manager.log_config(config.logger) respond_to_SIGHUP_with_logging = functools.partial( respond_to_SIGHUP, logger=config.logger) # install the signal handler with logging signal.signal(signal.SIGHUP, respond_to_SIGHUP_with_logging) except KeyError: # config apparently doesn't have 'logger' # install the signal handler without logging signal.signal(signal.SIGHUP, respond_to_SIGHUP) # we finally know what app to actually run, instantiate it app_to_run = klass(config) app_to_run.config_manager = config_manager # whew, finally run the app that we wanted return_code = fix_exit_code(app_to_run.main()) return return_code
def run(cls, config_path=None, values_source_list=None): # NOTE(willkg): This is a classmethod, so we need a different logger. mylogger = logging.getLogger(__name__ + '.' + cls.__name__) if config_path is None: config_path = os.environ.get( 'DEFAULT_SOCORRO_CONFIG_PATH', './config' ) if values_source_list is None: values_source_list = [ # pull in any configuration file ConfigFileFutureProxy, # get values from the environment environment, # use the command line to get the final overriding values command_line ] # Pull base set of defaults from the config module if it is specified if cls.config_defaults is not None: values_source_list.insert(0, cls.config_defaults) config_definition = cls.get_required_config() if 'application' not in config_definition: # FIXME(mkelly): We used to have a SocorroWelcomeApp that defined an # "application" option. We no longer have that. This section should # get reworked possibly as part of getting rid of application # defaults. application_config = Namespace() application_config.add_option( 'application', doc=( 'the fully qualified classname of the app to run' ), default=cls_to_pypath(cls), # the following setting means this option will NOT be # commented out when configman generates a config file likely_to_be_changed=True, from_string_converter=str_to_python_object, ) config_definition = application_config config_manager = ConfigurationManager( config_definition, app_name=cls.app_name, app_version=cls.app_version, app_description=cls.app_description, values_source_list=values_source_list, options_banned_from_help=[], config_pathname=config_path ) def fix_exit_code(code): # some apps don't return a code so you might get None # which isn't good enough to send to sys.exit() if code is None: return 0 return code with config_manager.context() as config: setup_logging(config) setup_metrics(config) # Log revision information revision_data = get_revision_data() revision_items = sorted(revision_data.items()) mylogger.info( 'version.json: {%s}', ', '.join( ['%r: %r' % (key, val) for key, val in revision_items] ) ) config_manager.log_config(mylogger) # we finally know what app to actually run, instantiate it app_to_run = cls(config) app_to_run.config_manager = config_manager # whew, finally run the app that we wanted return_code = fix_exit_code(app_to_run.main()) return return_code
def _do_run(klass, config_path=None, values_source_list=None): # while this method is defined here, only derived classes are allowed # to call it. if klass is SocorroApp: raise NotImplementedError( "The SocorroApp class has no useable 'main' method" ) if config_path is None: config_path = os.environ.get( 'DEFAULT_SOCORRO_CONFIG_PATH', './config' ) if values_source_list is None: values_source_list = [ # pull in any configuration file ConfigFileFutureProxy, # get values from the environment environment, # use the command line to get the final overriding values command_line ] # Pull base set of defaults from the config module if it is specified if klass.config_defaults is not None: values_source_list.insert(0, klass.config_defaults) config_definition = klass.get_required_config() if 'application' not in config_definition: # FIXME(mkelly): We used to have a SocorroWelcomeApp that defined an # "application" option. We no longer have that. This section should # get reworked possibly as part of getting rid of application # defaults. application_config = Namespace() application_config.add_option( 'application', doc=( 'the fully qualified classname of the app to run' ), default=klass_to_pypath(klass), # the following setting means this option will NOT be # commented out when configman generates a config file likely_to_be_changed=True, from_string_converter=str_to_python_object, ) config_definition = application_config config_manager = ConfigurationManager( config_definition, app_name=klass.app_name, app_version=klass.app_version, app_description=klass.app_description, values_source_list=values_source_list, options_banned_from_help=[], config_pathname=config_path ) def fix_exit_code(code): # some apps don't return a code so you might get None # which isn't good enough to send to sys.exit() if code is None: return 0 return code with config_manager.context() as config: config.executor_identity = ( lambda: threading.currentThread().getName() ) spit_out_version_json(config.logger) try: config_manager.log_config(config.logger) respond_to_SIGHUP_with_logging = functools.partial( respond_to_SIGHUP, logger=config.logger ) # install the signal handler with logging signal.signal(signal.SIGHUP, respond_to_SIGHUP_with_logging) except KeyError: # config apparently doesn't have 'logger' # install the signal handler without logging signal.signal(signal.SIGHUP, respond_to_SIGHUP) # we finally know what app to actually run, instantiate it app_to_run = klass(config) app_to_run.config_manager = config_manager # whew, finally run the app that we wanted return_code = fix_exit_code(app_to_run.main()) return return_code