def test_type_strictness_default(caplog, tmpdir, inputdata, error): mconfig_file = tmpdir.join("Mconfig") mconfig = template_type_strictness_default_mconfig.format(**inputdata) mconfig_file.write(mconfig, "wt") general.init_config(str(mconfig_file), False) if error is not None: assert error in caplog.text else: assert caplog.text == ""
def main(): args = parse_args() if args.new: init_config(args.database, args.ignore_missing) else: read_config(args.database, args.config, args.ignore_missing) files = [] setters = [] for arg in args.args: key, value = parse_config_arg(arg) if key: set_config_if_prompt(key, value, True) else: logger.info("Reading %s" % arg) read_profile_file(arg) enforce_dependent_values() check_values_as_requested(args.args) for plugin in args.plugin: path, name = os.path.split(plugin) if path.startswith('/'): sys.path.insert(0, path) else: sys.path.insert(0, os.path.join(os.getcwd(), path)) sys.path.append(os.path.dirname(sys.argv[0])) try: mod = importlib.import_module(name) mod.plugin_exec() except ImportError as err: logger.error("Could not import %s plugin: %s" % (name, err)) except Exception as err: logger.error("Problem encountered in %s plugin: %s" % (name, repr(err))) import traceback traceback.print_tb(sys.exc_info()[2]) write_config(args.config) if args.json is not None: config_json.write_config(args.json) error_count = counter.errors() + counter.criticals() error_path = args.config + ".error" if error_count == 0: try: os.remove(error_path) except OSError: pass else: with open(error_path, 'w'): pass if args.json is not None: try: os.remove(args.json) except OSError: pass return error_count
def main(): args = parse_args() if args.new: init_config(args.database, args.ignore_missing) else: read_config(args.database, args.config, args.ignore_missing) files = [] setters = [] for arg in args.args: key, value = parse_config_arg(arg) if key: set_config_if_prompt(key, value, True) else: logger.info("Reading %s" % arg) read_profile_file(arg) # Prior to calling plugins, ensure that values are consistent as # possible. After this call, there may still be inconsistencies # from selects enabling options with disabled dependencies. The # user generally does not need to know about bool inconsistencies, # but log them to INFO so they can see if we're seeing them. enforce_dependent_values("Inconsistency prior to plugins: ", error_level=logging.INFO) for plugin in args.plugin: path, name = os.path.split(plugin) if path.startswith('/'): sys.path.insert(0, path) else: sys.path.insert(0, os.path.join(os.getcwd(), path)) sys.path.append(os.path.dirname(sys.argv[0])) try: mod = importlib.import_module(name) mod.plugin_exec() except ImportError as err: logger.error("Could not import %s plugin: %s" % (name, err)) except Exception as err: logger.error("Problem encountered in %s plugin: %s" % (name, repr(err))) import traceback traceback.print_tb(sys.exc_info()[2]) # If any bool values are still inconsistent, force the user to fix enforce_dependent_values("Inconsistent values: ", error_level=logging.ERROR) check_values_as_requested(args.args) write_config(args.config) if args.json is not None: config_json.write_config(args.json) if args.depfile is not None: write_depfile(args.depfile, args.config) error_count = counter.errors() + counter.criticals() error_path = args.config + ".error" if error_count == 0: try: os.remove(error_path) except OSError: pass else: with open(error_path, 'w'): pass if args.json is not None: try: os.remove(args.json) except OSError: pass return error_count