def _set_future(dynamic_data, key, data): '''Set a dynamic_data key to a new ExtendedFuture instance @param dynamic_data: dictionary @param key: tuple of (dictionary-key, default-value) ''' if data[0] in ['Future', 'ExtendedFuture']: if data[1] in ['UNSET']: dynamic_data[key] = ExtendedFuture() else: if data[1] in DATA_TYPES: default = DATA_TYPES[data[1]]() else: default = data[1] dynamic_data[key] = ExtendedFuture(default)
def _set_future(dynamic_data, key, data): """Set a dynamic_data key to a new ExtendedFuture instance @param dynamic_data: dictionary @param key: tuple of (dictionary-key, default-value) """ if data[0] in ["Future", "ExtendedFuture"]: if data[1] in ["UNSET"]: dynamic_data[key] = ExtendedFuture() else: if data[1] in DATA_TYPES: default = DATA_TYPES[data[1]]() else: default = data[1] dynamic_data[key] = ExtendedFuture(default)
def _repoman_init(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( argv, repoman_settings.get("REPOMAN_DEFAULT_OPTS", "")) if options.version: print("Repoman", VERSION, "(portage-%s)" % portage.VERSION) return _repoman_main_vars(None, 0, None, None, None, None, None) 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) repo_settings, vcs_settings, scanner, qadata = _create_scanner( options, can_force, config_root, repoman_settings) return _repoman_main_vars(can_force, None, options, qadata, repo_settings, scanner, vcs_settings)
def scan_pkgs(self, can_force): for xpkg in self.effective_scanlist: xpkg_continue = False # ebuilds and digests added to cvs respectively. logging.info("checking package %s", xpkg) # save memory by discarding xmatch caches from previous package(s) self.caches['arch_xmatch'].clear() catdir, pkgdir = xpkg.split("/") checkdir = self.repo_settings.repodir + "/" + xpkg checkdir_relative = "" if self.repolevel < 3: checkdir_relative = os.path.join(pkgdir, checkdir_relative) if self.repolevel < 2: checkdir_relative = os.path.join(catdir, checkdir_relative) checkdir_relative = os.path.join(".", checkdir_relative) # Run the status check if self.kwargs['checks']['ebuild_notadded']: self.vcs_settings.status.check(checkdir, checkdir_relative, xpkg) if self.generate_manifest: if not manifest.Manifest( **self.kwargs).update_manifest(checkdir): self.qatracker.add_error("manifest.bad", os.path.join(xpkg, 'Manifest')) if self.options.mode == 'manifest': continue checkdirlist = os.listdir(checkdir) dynamic_data = { 'changelog_modified': False, 'checkdirlist': ExtendedFuture(checkdirlist), 'checkdir': checkdir, 'xpkg': xpkg, 'changed': self.changed, 'checkdir_relative': checkdir_relative, 'can_force': can_force, 'repolevel': self.repolevel, 'catdir': catdir, 'pkgdir': pkgdir, 'validity_future': ExtendedFuture(True), 'y_ebuild': None, # this needs to be reset at the pkg level only, # easiest is to just initialize it here 'muselist': ExtendedFuture(set()), 'src_uri_error': ExtendedFuture(), } self.pkg_level_futures = [ 'checkdirlist', 'muselist', 'pkgs', 'src_uri_error', 'validity_future', ] # need to set it up for ==> self.modules or some other ordered list logging.debug("***** starting pkgs_loop: %s", self.moduleconfig.pkgs_loop) for mod in self.moduleconfig.pkgs_loop: mod_class = self.moduleconfig.controller.get_class(mod) logging.debug("Initializing class name: %s", mod_class.__name__) self.modules[mod_class.__name__] = mod_class( **self.set_kwargs(mod)) logging.debug("scan_pkgs; module: %s", mod_class.__name__) do_it, functions = self.modules[mod_class.__name__].runInPkgs if do_it: for func in functions: _continue = func( **self.set_func_kwargs(mod, dynamic_data)) if _continue: # If we can't access all the metadata then it's totally unsafe to # commit since there's no way to generate a correct Manifest. # Do not try to do any more QA checks on this package since missing # metadata leads to false positives for several checks, and false # positives confuse users. xpkg_continue = True break if xpkg_continue: continue # Sort ebuilds in ascending order for the KEYWORDS.dropped check. pkgs = dynamic_data['pkgs'].get() ebuildlist = sorted(pkgs.values()) ebuildlist = [pkg.pf for pkg in ebuildlist] if self.kwargs['checks'][ 'changelog'] and "ChangeLog" not in checkdirlist: self.qatracker.add_error("changelog.missing", xpkg + "/ChangeLog") changelog_path = os.path.join(checkdir_relative, "ChangeLog") dynamic_data[ "changelog_modified"] = changelog_path in self.changed.changelogs self._scan_ebuilds(ebuildlist, dynamic_data)
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 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', } # early out for manifest generation if options.mode == "manifest": sys.exit(result['fail']) 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 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)