def _handle_result( can_force, exitcode, options, qadata, repo_settings, scanner, vcs_settings, result ): commitmessage = None if options.commitmsg: commitmessage = options.commitmsg elif options.commitmsgfile: # we don't need the actual text of the commit message here # the filename will do for the next code block commitmessage = options.commitmsgfile # Save QA output so that it can be conveniently displayed # in $EDITOR while the user creates a commit message. # Otherwise, the user would not be able to see this output # once the editor has taken over the screen. qa_output = io.StringIO() style_file = ConsoleStyleFile(sys.stdout) if options.mode == "commit" and (not commitmessage or not commitmessage.strip()): style_file.write_listener = qa_output console_writer = StyleWriter(file=style_file, maxcol=9999) console_writer.style_listener = style_file.new_styles f = formatter.AbstractFormatter(console_writer) format_outputs = {"column": format_qa_output_column, "default": format_qa_output} format_output = format_outputs.get(options.output_style, format_outputs["default"]) format_output( f, vcs_settings.qatracker.fails, result["full"], result["fail"], options, qadata.qawarnings, ) style_file.flush() del console_writer, f, style_file # early out for manifest generation if options.mode == "manifest": return 1 if result["fail"] else 0 qa_output = qa_output.getvalue() qa_output = qa_output.splitlines(True) # output the results actions = Actions(repo_settings, options, scanner, vcs_settings) if actions.inform(can_force.get(), result): # perform any other actions actions.perform(qa_output) elif result["fail"]: return 1 return 0
def repoman_main(argv): config_root = os.environ.get("PORTAGE_CONFIGROOT") repoman_settings = portage.config(config_root=config_root, local_config=False) repoman_settings.valid_versions = VALID_VERSIONS if repoman_settings.get("NOCOLOR", "").lower() in ("yes", "true") or \ repoman_settings.get('TERM') == 'dumb' or \ not sys.stdout.isatty(): nocolor() options, arguments = parse_args( sys.argv, repoman_settings.get("REPOMAN_DEFAULT_OPTS", "")) if options.version: print("Repoman", VERSION, "(portage-%s)" % portage.VERSION) sys.exit(0) logger = logging.getLogger() if options.verbosity > 0: logger.setLevel(LOGLEVEL - 10 * options.verbosity) else: logger.setLevel(LOGLEVEL) # Set this to False when an extraordinary issue (generally # something other than a QA issue) makes it impossible to # commit (like if Manifest generation fails). can_force = ExtendedFuture(True) portdir, portdir_overlay, mydir = utilities.FindPortdir(repoman_settings) if portdir is None: sys.exit(1) myreporoot = os.path.basename(portdir_overlay) myreporoot += mydir[len(portdir_overlay):] # avoid a circular parameter repo_settings vcs_settings = VCSSettings(options, repoman_settings) qadata = QAData() logging.debug("repoman_main: RepoSettings init") repo_settings = RepoSettings(config_root, portdir, portdir_overlay, repoman_settings, vcs_settings, options, qadata) repoman_settings = repo_settings.repoman_settings repoman_settings.valid_versions = VALID_VERSIONS # Now set repo_settings vcs_settings.repo_settings = repo_settings # set QATracker qacats, qawarnings vcs_settings.qatracker.qacats = repo_settings.qadata.qacats vcs_settings.qatracker.qawarnings = repo_settings.qadata.qawarnings logging.debug("repoman_main: vcs_settings done") logging.debug("repoman_main: qadata: %s", repo_settings.qadata) if 'digest' in repoman_settings.features and options.digest != 'n': options.digest = 'y' logging.debug("vcs: %s" % (vcs_settings.vcs, )) logging.debug("repo config: %s" % (repo_settings.repo_config, )) logging.debug("options: %s" % (options, )) # It's confusing if these warnings are displayed without the user # being told which profile they come from, so disable them. env = os.environ.copy() env['FEATURES'] = env.get('FEATURES', '') + ' -unknown-features-warn' # Perform the main checks scanner = Scanner(repo_settings, myreporoot, config_root, options, vcs_settings, mydir, env) scanner.scan_pkgs(can_force) if options.if_modified == "y" and len(scanner.effective_scanlist) < 1: logging.warning( "--if-modified is enabled, but no modified packages were found!") result = { # fail will be true if we have failed in at least one non-warning category 'fail': 0, # warn will be true if we tripped any warnings 'warn': 0, # full will be true if we should print a "repoman full" informational message 'full': options.mode != 'full', } for x in qadata.qacats: if x not in vcs_settings.qatracker.fails: continue result['warn'] = 1 if x not in qadata.qawarnings: result['fail'] = 1 if result['fail'] or \ (result['warn'] and not (options.quiet or options.mode == "scan")): result['full'] = 0 commitmessage = None if options.commitmsg: commitmessage = options.commitmsg elif options.commitmsgfile: # we don't need the actual text of the commit message here # the filename will do for the next code block commitmessage = options.commitmsgfile # Save QA output so that it can be conveniently displayed # in $EDITOR while the user creates a commit message. # Otherwise, the user would not be able to see this output # once the editor has taken over the screen. qa_output = io.StringIO() style_file = ConsoleStyleFile(sys.stdout) if options.mode == 'commit' and \ (not commitmessage or not commitmessage.strip()): style_file.write_listener = qa_output console_writer = StyleWriter(file=style_file, maxcol=9999) console_writer.style_listener = style_file.new_styles f = formatter.AbstractFormatter(console_writer) format_outputs = { 'column': format_qa_output_column, 'default': format_qa_output } format_output = format_outputs.get(options.output_style, format_outputs['default']) format_output(f, vcs_settings.qatracker.fails, result['full'], result['fail'], options, qadata.qawarnings) style_file.flush() del console_writer, f, style_file # early out for manifest generation if options.mode == "manifest": return 1 if result['fail'] else 0 qa_output = qa_output.getvalue() qa_output = qa_output.splitlines(True) # output the results actions = Actions(repo_settings, options, scanner, vcs_settings) if actions.inform(can_force.get(), result): # perform any other actions actions.perform(qa_output) sys.exit(0)
def _display_status(self): # Don't use len(self._completed_tasks) here since that also # can include uninstall tasks. curval_str = "%s" % (self.curval, ) maxval_str = "%s" % (self.maxval, ) running_str = "%s" % (self.running, ) failed_str = "%s" % (self.failed, ) load_avg_str = self._load_avg_str() color_output = io.StringIO() plain_output = io.StringIO() style_file = portage.output.ConsoleStyleFile(color_output) style_file.write_listener = plain_output style_writer = portage.output.StyleWriter(file=style_file, maxcol=9999) style_writer.style_listener = style_file.new_styles f = formatter.AbstractFormatter(style_writer) number_style = "INFORM" f.add_literal_data("Jobs: ") f.push_style(number_style) f.add_literal_data(curval_str) f.pop_style() f.add_literal_data(" of ") f.push_style(number_style) f.add_literal_data(maxval_str) f.pop_style() f.add_literal_data(" complete") if self.running: f.add_literal_data(", ") f.push_style(number_style) f.add_literal_data(running_str) f.pop_style() f.add_literal_data(" running") if self.failed: f.add_literal_data(", ") f.push_style(number_style) f.add_literal_data(failed_str) f.pop_style() f.add_literal_data(" failed") padding = self._jobs_column_width - len(plain_output.getvalue()) if padding > 0: f.add_literal_data(padding * " ") f.add_literal_data("Load avg: ") f.add_literal_data(load_avg_str) # Truncate to fit width, to avoid making the terminal scroll if the # line overflows (happens when the load average is large). plain_output = plain_output.getvalue() if self._isatty and len(plain_output) > self.width: # Use plain_output here since it's easier to truncate # properly than the color output which contains console # color codes. self._update(plain_output[:self.width]) else: self._update(color_output.getvalue()) if self.xterm_titles: # If the HOSTNAME variable is exported, include it # in the xterm title, just like emergelog() does. # See bug #390699. title_str = " ".join(plain_output.split()) hostname = os.environ.get("HOSTNAME") if hostname is not None: title_str = "%s: %s" % (hostname, title_str) xtermTitle(title_str)