def __init__(self, cli_conf=None): """ Initialize the application :param cli_conf: CLI object with configuration gathered from commandline :return: """ OutputLogger.clear() self.conf = cli_conf if self.conf.verbose: LoggerHelper.add_stream_handler(logger, logging.DEBUG) else: LoggerHelper.add_stream_handler(logger, logging.INFO) # The directory in which rebase-helper was executed if self.conf.results_dir is None: self.execution_dir = os.getcwd() else: self.execution_dir = self.conf.results_dir # Temporary workspace for Builder, checks, ... self.kwargs['workspace_dir'] = self.workspace_dir = os.path.join(self.execution_dir, settings.REBASE_HELPER_WORKSPACE_DIR) # Directory where results should be put self.kwargs['results_dir'] = self.results_dir = os.path.join(self.execution_dir, settings.REBASE_HELPER_RESULTS_DIR) self.kwargs['non_interactive'] = self.conf.non_interactive # if not continuing, check the results dir if not self.conf.cont and not self.conf.build_only and not self.conf.comparepkgs: self._check_results_dir() # This is used if user executes rebase-helper with --continue # parameter even when directory does not exist if not os.path.exists(self.results_dir): os.makedirs(self.results_dir) os.makedirs(os.path.join(self.results_dir, settings.REBASE_HELPER_LOGS)) self._add_debug_log_file() self._add_report_log_file() logger.debug("Rebase-helper version: %s" % version.VERSION) if self.conf.build_tasks is None: self._get_spec_file() self._prepare_spec_objects() # check the workspace dir if not self.conf.cont: self._check_workspace_dir() # TODO: Remove the value from kwargs and use only CLI attribute! self.kwargs['continue'] = self.conf.cont self._initialize_data() if self.conf.cont or self.conf.build_only: self._delete_old_builds()
def run(): debug_log_file = None try: # be verbose until debug_log_file is created handler = LoggerHelper.add_stream_handler(logger, logging.DEBUG) if "--builder-options" in sys.argv[1:]: raise RebaseHelperError( "Wrong format of --builder-options. It must be in the following form:" ' --builder-options="--desired-builder-option".' ) cli = CLI() execution_dir, results_dir, debug_log_file, report_log_file = Application.setup(cli) if not cli.verbose: handler.setLevel(logging.INFO) app = Application(cli, execution_dir, results_dir, debug_log_file, report_log_file) app.run() except KeyboardInterrupt: logger.info("\nInterrupted by user") except RebaseHelperError as e: if e.args: logger.error("\n%s", e.args[0] % e.args[1:]) else: logger.error("\n%s", six.text_type(e)) sys.exit(1) except SystemExit as e: sys.exit(e.code) except BaseException: if debug_log_file: logger.error( "\nrebase-helper failed due to an unexpected error. Please report this problem" "\nusing the following link: %s" "\nand include the content of" "\n'%s'" "\nfile in the report." "\nThank you!", NEW_ISSUE_LINK, debug_log_file, ) else: logger.error( "\nrebase-helper failed due to an unexpected error. Please report this problem" "\nusing the following link: %s" "\nand include the traceback following this message in the report." "\nThank you!", NEW_ISSUE_LINK, ) logger.debug("\n", exc_info=1) sys.exit(1) sys.exit(0)
def run(): debug_log_file = None try: # be verbose until debug_log_file is created handler = LoggerHelper.add_stream_handler(logger, logging.DEBUG) if "--builder-options" in sys.argv[1:]: raise RebaseHelperError( 'Wrong format of --builder-options. It must be in the following form:' ' --builder-options="--desired-builder-option".') cli = CLI() if cli.version: logger.info(VERSION) sys.exit(0) ConsoleHelper.use_colors = ConsoleHelper.should_use_colors(cli) execution_dir, results_dir, debug_log_file = Application.setup(cli) if not cli.verbose: handler.setLevel(logging.INFO) app = Application(cli, execution_dir, results_dir, debug_log_file) app.run() except KeyboardInterrupt: logger.info('\nInterrupted by user') except RebaseHelperError as e: if e.msg: logger.error('\n%s', e.msg) else: logger.error('\n%s', six.text_type(e)) sys.exit(1) except SystemExit as e: sys.exit(e.code) except BaseException: if debug_log_file: logger.error( '\nrebase-helper failed due to an unexpected error. Please report this problem' '\nusing the following link: %s' '\nand include the content of' '\n\'%s\'' '\nfile in the report.' '\nThank you!', NEW_ISSUE_LINK, debug_log_file) else: logger.error( '\nrebase-helper failed due to an unexpected error. Please report this problem' '\nusing the following link: %s' '\nand include the traceback following this message in the report.' '\nThank you!', NEW_ISSUE_LINK) logger.debug('\n', exc_info=1) sys.exit(1) sys.exit(0)
def run(cls): results_dir = None start_dir = os.getcwd() try: LoggerHelper.setup_memory_handler() main_handler, output_tool_handler = LoggerHelper.create_stream_handlers( ) cli = CLI() if hasattr(cli, 'version'): print(VERSION) sys.exit(0) logger.info('rebase-helper version %s', VERSION) config = Config(getattr(cli, 'config-file', None)) config.merge(cli) for handler in [main_handler, output_tool_handler]: handler.set_terminal_background(config.background) if config.verbose == 0: main_handler.setLevel(logging.INFO) elif config.verbose == 1: main_handler.setLevel(CustomLogger.VERBOSE) else: main_handler.setLevel(logging.DEBUG) ConsoleHelper.use_colors = ConsoleHelper.should_use_colors(config) if config.bugzilla_id: repo_path, config.config[ 'sources'] = BugzillaHelper.prepare_rebase_repository( config.bugzilla_id) try: os.chdir(repo_path) except OSError as e: raise RebaseHelperError( 'Could not change directory to the cloned repository' ) from e # update relative paths in config for option in ('results_dir', 'workspace_dir'): path = getattr(config, option) if path and not os.path.isabs(path): config.config[option] = os.path.join( os.path.relpath(start_dir, os.getcwd()), path) if config.config['rpmmacros']: macros = ' -D ' + ' -D '.join( '"{}"'.format(s) for s in config.config['rpmmacros']) for option in ('builder_options', 'srpm_builder_options'): if config.config[option]: config.config[option] += macros else: config.config[option] = macros config.config['rpmmacros'] = cls.convert_macros_to_dict( config.rpmmacros) execution_dir, results_dir = Application.setup(config) app = Application(config, start_dir, execution_dir, results_dir) app.run() except KeyboardInterrupt: logger.info('Interrupted by user') except RebaseHelperError as e: if e.msg: logger.error('%s', e.msg) else: logger.error('%s', str(e)) sys.exit(1) except SystemExit as e: sys.exit(e.code) except BaseException: logger_traceback: CustomLogger = cast( CustomLogger, logging.getLogger('rebasehelper.traceback')) logger_traceback.propagate = False logger_traceback.setLevel(CustomLogger.TRACE) if results_dir: debug_log = os.path.join(results_dir, LOGS_DIR, DEBUG_LOG) traceback_log = os.path.join(results_dir, LOGS_DIR, TRACEBACK_LOG) logger.error( 'rebase-helper failed due to an unexpected error. Please report this problem' '\nusing the following link: %s' '\nand include the content of' '\n\'%s\' and' '\n\'%s\'' '\nin the report.' '\nThank you!', NEW_ISSUE_LINK, debug_log, traceback_log) LoggerHelper.add_file_handler(logger_traceback, traceback_log) else: logger.error( 'rebase-helper failed due to an unexpected error. Please report this problem' '\nusing the following link: %s' '\nand include the following traceback in the report.' '\nThank you!', NEW_ISSUE_LINK) LoggerHelper.add_stream_handler(logger_traceback, CustomLogger.TRACE) logger_traceback.trace('', exc_info=1) sys.exit(1) sys.exit(0)