MCPcopy Index your code
hub / github.com/StackStorm/st2 / setup

Function setup

st2common/st2common/script_setup.py:47–111  ·  view source on GitHub ↗

Common setup function. Currently it performs the following operations: 1. Parses config and CLI arguments 2. Establishes DB connection 3. Suppress DEBUG log level if --verbose flag is not used 4. Registers RabbitMQ exchanges 5. Registers internal trigger types (optiona

(
    config,
    setup_db=True,
    register_mq_exchanges=True,
    register_internal_trigger_types=False,
    ignore_register_config_opts_errors=False,
)

Source from the content-addressed store, hash-verified

45
46
47def setup(
48 config,
49 setup_db=True,
50 register_mq_exchanges=True,
51 register_internal_trigger_types=False,
52 ignore_register_config_opts_errors=False,
53):
54 """
55 Common setup function.
56
57 Currently it performs the following operations:
58
59 1. Parses config and CLI arguments
60 2. Establishes DB connection
61 3. Suppress DEBUG log level if --verbose flag is not used
62 4. Registers RabbitMQ exchanges
63 5. Registers internal trigger types (optional, disabled by default)
64
65 :param config: Config object to use to parse args.
66 """
67 # Register common CLI options
68 register_common_cli_options()
69
70 # Parse args to setup config
71 # NOTE: This code is not the best, but it's only realistic option we have at this point.
72 # Refactoring all the code and config modules to avoid import time side affects would be a big
73 # rabbit hole. Luckily registering same options twice is not really a big deal or fatal error
74 # so we simply ignore such errors.
75 if config.__name__ == "st2common.config" and ignore_register_config_opts_errors:
76 config.parse_args(ignore_errors=True)
77 else:
78 config.parse_args()
79
80 if cfg.CONF.debug:
81 cfg.CONF.verbose = True
82
83 # Set up logging
84 log_level = stdlib_logging.DEBUG
85 stdlib_logging.basicConfig(
86 format="%(asctime)s %(levelname)s [-] %(message)s", level=log_level
87 )
88
89 if not cfg.CONF.verbose:
90 # Note: We still want to print things at the following log levels: INFO, ERROR, CRITICAL
91 exclude_log_levels = [stdlib_logging.AUDIT, stdlib_logging.DEBUG]
92 handlers = stdlib_logging.getLoggerClass().manager.root.handlers
93
94 for handler in handlers:
95 handler.addFilter(LogLevelFilter(log_levels=exclude_log_levels))
96
97 # NOTE: statsd logger logs everything by default under INFO so we ignore those log
98 # messages unless verbose / debug mode is used
99 logging.ignore_statsd_log_messages()
100
101 logging.ignore_lib2to3_log_messages()
102
103 # All other setup code which requires config to be parsed and logging to be correctly setup
104 if setup_db:

Callers

nothing calls this directly

Calls 4

LogLevelFilterClass · 0.90
db_setupFunction · 0.90

Tested by

no test coverage detected