def main(): root_logger = logging.getLogger() root_logger.setLevel(logging.WARNING) # The eventual destination is stdout with the above formatting errHandler = logging.StreamHandler(sys.stderr) formatter = log_handlers.ColorFormatter("%(levelname)s: %(message)s", errHandler.stream.isatty()) errHandler.setFormatter(formatter) # Setup a buffer to store messages msgBuffer = log_handlers.InfBufferHandler(8192, target=errHandler) root_logger.addHandler(msgBuffer) # Also count each type of message counter = log_handlers.ErrorCounterHandler() root_logger.addHandler(counter) args = parse_args() if args.debug: root_logger.setLevel(logging.DEBUG) # Update root logger general.read_config(args.database, args.config, args.ignore_missing) menustack.append(general.get_root_menu()) should_save = curses.wrapper(gui_main) if should_save: general.enforce_dependent_values() 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.warning("Problem encountered in %s plugin: %s" % (name, repr(err))) import traceback traceback.print_tb(sys.exc_info()[2]) general.write_config(args.config) if args.json is not None: config_json.write_config(args.json) # Flush all log messages on exit msgBuffer.close() error_count = counter.errors() + counter.criticals() if should_save: 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) 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(): root_logger = logging.getLogger() root_logger.setLevel(logging.WARNING) # The eventual destination is stdout with the above formatting errHandler = logging.StreamHandler(sys.stderr) formatter = log_handlers.ColorFormatter("%(levelname)s: %(message)s", errHandler.stream.isatty()) errHandler.setFormatter(formatter) # Setup a buffer to store messages msgBuffer = log_handlers.InfBufferHandler(8192, target=errHandler) root_logger.addHandler(msgBuffer) # Also count each type of message counter = log_handlers.ErrorCounterHandler() root_logger.addHandler(counter) args = parse_args() if args.debug: root_logger.setLevel(logging.DEBUG) # Update root logger general.read_config(args.database, args.config, args.ignore_missing) menustack.append(general.get_root_menu()) should_save = curses.wrapper(gui_main) if should_save: # 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. general.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 general.enforce_dependent_values("Inconsistent values: ", error_level=logging.ERROR) general.write_config(args.config) if args.json is not None: config_json.write_config(args.json) if args.depfile is not None: general.write_depfile(args.depfile, args.config) # Flush all log messages on exit msgBuffer.close() error_count = counter.errors() + counter.criticals() if should_save: 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() read_config(args.database, args.config, args.ignore_missing) print_user_config()
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