def main(): # pragma: no cover configure_signals() args = parse_arguments(*sys.argv[1:]) logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s') if args.version: print(pkg_resources.require('borgmatic')[0].version) sys.exit(0) config_filenames = tuple( collect.collect_config_filenames(args.config_paths)) logger.debug('Ensuring legacy configuration is upgraded') convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames) summary_logs = tuple( collect_configuration_run_summary_logs(config_filenames, args)) logger.info('\nsummary:') [ logger.handle(log) for log in summary_logs if log.levelno >= logger.getEffectiveLevel() ] if any(log.levelno == logging.CRITICAL for log in summary_logs): logger.critical( '\nNeed some help? https://torsion.org/borgmatic/#issues') sys.exit(1)
def main(): # pragma: no cover try: configure_signals() args = parse_arguments(*sys.argv[1:]) logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s') config_filenames = tuple( collect.collect_config_filenames(args.config_paths)) logger.debug('Ensuring legacy configuration is upgraded') convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames) if len(config_filenames) == 0: raise ValueError( 'Error: No configuration files found in: {}'.format(' '.join( args.config_paths))) for config_filename in config_filenames: run_configuration(config_filename, args) except (ValueError, OSError, CalledProcessError) as error: print(error, file=sys.stderr) print(file=sys.stderr) print('Need some help? https://torsion.org/borgmatic/#issues', file=sys.stderr) sys.exit(1)
def main(): # pragma: no cover configure_signals() try: args = parse_arguments(*sys.argv[1:]) except ValueError as error: logging.basicConfig(level=logging.CRITICAL, format='%(message)s') logger.critical(error) exit_with_help_link() logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s') if args.version: print(pkg_resources.require('borgmatic')[0].version) sys.exit(0) config_filenames = tuple(collect.collect_config_filenames(args.config_paths)) logger.debug('Ensuring legacy configuration is upgraded') convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames) summary_logs = tuple(collect_configuration_run_summary_logs(config_filenames, args)) logger.info('\nsummary:') [logger.handle(log) for log in summary_logs if log.levelno >= logger.getEffectiveLevel()] if any(log.levelno == logging.CRITICAL for log in summary_logs): exit_with_help_link()
def main(): # pragma: no cover configure_signals() try: arguments = parse_arguments(*sys.argv[1:]) except ValueError as error: configure_logging(logging.CRITICAL) logger.critical(error) exit_with_help_link() except SystemExit as error: if error.code == 0: raise error configure_logging(logging.CRITICAL) logger.critical('Error parsing arguments: {}'.format(' '.join( sys.argv))) exit_with_help_link() global_arguments = arguments['global'] if global_arguments.version: print(pkg_resources.require('borgmatic')[0].version) sys.exit(0) config_filenames = tuple( collect.collect_config_filenames(global_arguments.config_paths)) configs, parse_logs = load_configurations(config_filenames) colorama.init( autoreset=True, strip=not should_do_markup(global_arguments.no_color, configs)) configure_logging( verbosity_to_log_level(global_arguments.verbosity), verbosity_to_log_level(global_arguments.syslog_verbosity), ) logger.debug('Ensuring legacy configuration is upgraded') convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames) summary_logs = list( collect_configuration_run_summary_logs(configs, arguments)) logger.info('') logger.info('summary:') [ logger.handle(log) for log in parse_logs + summary_logs if log.levelno >= logger.getEffectiveLevel() ] if any(log.levelno == logging.CRITICAL for log in summary_logs): exit_with_help_link()
def main(): # pragma: no cover try: configure_signals() args = parse_arguments(*sys.argv[1:]) logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s') config_filenames = tuple(collect.collect_config_filenames(args.config_paths)) logger.debug('Ensuring legacy configuration is upgraded') convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames) if len(config_filenames) == 0: raise ValueError('Error: No configuration files found in: {}'.format(' '.join(args.config_paths))) for config_filename in config_filenames: run_configuration(config_filename, args) except (ValueError, OSError, CalledProcessError) as error: print(error, file=sys.stderr) sys.exit(1)
def main(): # pragma: no cover configure_signals() try: arguments = parse_arguments(*sys.argv[1:]) except ValueError as error: configure_logging(logging.CRITICAL) logger.critical(error) exit_with_help_link() except SystemExit as error: if error.code == 0: raise error configure_logging(logging.CRITICAL) logger.critical('Error parsing arguments: {}'.format(' '.join( sys.argv))) exit_with_help_link() global_arguments = arguments['global'] if global_arguments.version: print(pkg_resources.require('borgmatic')[0].version) sys.exit(0) config_filenames = tuple( collect.collect_config_filenames(global_arguments.config_paths)) configs, parse_logs = load_configurations(config_filenames, global_arguments.overrides) any_json_flags = any( getattr(sub_arguments, 'json', False) for sub_arguments in arguments.values()) colorama.init( autoreset=True, strip=not should_do_markup(global_arguments.no_color or any_json_flags, configs), ) try: configure_logging( verbosity_to_log_level(global_arguments.verbosity), verbosity_to_log_level(global_arguments.syslog_verbosity), verbosity_to_log_level(global_arguments.log_file_verbosity), verbosity_to_log_level(global_arguments.monitoring_verbosity), global_arguments.log_file, ) except (FileNotFoundError, PermissionError) as error: configure_logging(logging.CRITICAL) logger.critical('Error configuring logging: {}'.format(error)) exit_with_help_link() logger.debug('Ensuring legacy configuration is upgraded') convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames) summary_logs = parse_logs + list( collect_configuration_run_summary_logs(configs, arguments)) summary_logs_max_level = max(log.levelno for log in summary_logs) for message in ('', 'summary:'): log_record( levelno=summary_logs_max_level, levelname=logging.getLevelName(summary_logs_max_level), msg=message, ) for log in summary_logs: logger.handle(log) if summary_logs_max_level >= logging.CRITICAL: exit_with_help_link()