From 0816e0db36fbc5898278a34bf2249975bc99da30 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 18 Oct 2009 04:04:45 +0000 Subject: Automatically create a fallback setconfig, so emerge isn't crippled due to misssing/corrupt/outdated sets.conf. This is especially important since WorldSet has been renamed to WorldSelectedSet, and thus new and old sets.conf files are incompatible. (trunk r14630) svn path=/main/branches/2.1.7/; revision=14658 --- pym/_emerge/main.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'pym/_emerge/main.py') diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py index 10e605e56..5007ecfef 100644 --- a/pym/_emerge/main.py +++ b/pym/_emerge/main.py @@ -778,6 +778,55 @@ def ionice(settings): out.eerror("PORTAGE_IONICE_COMMAND returned %d" % (rval,)) out.eerror("See the make.conf(5) man page for PORTAGE_IONICE_COMMAND usage instructions.") +def setconfig_fallback(root_config): + from portage._sets.base import DummyPackageSet + from portage._sets.files import WorldSelectedSet + from portage._sets.profiles import PackagesSystemSet + setconfig = root_config.setconfig + setconfig.psets['world'] = DummyPackageSet(atoms=['@selected', '@system']) + setconfig.psets['selected'] = WorldSelectedSet(root_config.root) + setconfig.psets['system'] = \ + PackagesSystemSet(root_config.settings.profiles) + root_config.sets = setconfig.getSets() + +def get_missing_sets(root_config): + # emerge requires existence of "world", "selected", and "system" + missing_sets = [] + + for s in ("selected", "system", "world",): + if s not in root_config.sets: + missing_sets.append(s) + + return missing_sets + +def missing_sets_warning(root_config, missing_sets): + if len(missing_sets) > 2: + missing_sets_str = ", ".join('"%s"' % s for s in missing_sets[:-1]) + missing_sets_str += ', and "%s"' % missing_sets[-1] + elif len(missing_sets) == 2: + missing_sets_str = '"%s" and "%s"' % tuple(missing_sets) + else: + missing_sets_str = '"%s"' % missing_sets[-1] + msg = ["emerge: incomplete set configuration, " + \ + "missing set(s): %s" % missing_sets_str] + if root_config.sets: + msg.append(" sets defined: %s" % ", ".join(root_config.sets)) + msg.append(" This usually means that '%s'" % \ + (os.path.join(portage.const.GLOBAL_CONFIG_PATH, "sets.conf"),)) + msg.append(" is missing or corrupt.") + for line in msg: + writemsg_level(line + "\n", level=logging.ERROR, noiselevel=-1) + +def ensure_required_sets(trees): + warning_shown = False + for root_trees in trees.values(): + missing_sets = get_missing_sets(root_trees["root_config"]) + if missing_sets and not warning_shown: + warning_shown = True + missing_sets_warning(root_trees["root_config"], missing_sets) + if missing_sets: + setconfig_fallback(root_trees["root_config"]) + def expand_set_arguments(myfiles, myaction, root_config): if myaction != "search": @@ -996,6 +1045,8 @@ def emerge_main(): root_config = trees[settings["ROOT"]]["root_config"] + ensure_required_sets(trees) + # only expand sets for actions taking package arguments oldargs = myfiles[:] if myaction in ("clean", "config", "depclean", "info", "prune", "unmerge", None): -- cgit v1.2.3-1-g7c22