Make emerge detect an invalid profile an bail out for anything except
authorZac Medico <zmedico@gentoo.org>
Mon, 24 Nov 2008 00:34:17 +0000 (00:34 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 24 Nov 2008 00:34:17 +0000 (00:34 -0000)
--help, --info, --sync, and --version actions. When bailing out, suggest
to revert back to the previous profile configuration advise the user which
actions are allowed with an invalid profile. (trunk r12064:12066)

svn path=/main/branches/2.1.6/; revision=12067

pym/_emerge/__init__.py
pym/portage/__init__.py

index e73455023ab9af3ef9fec0611a7442c0c5e68748..ff24576b24e950279d29f6aa27e6f9cfcc6620fa 100644 (file)
@@ -13462,6 +13462,25 @@ def ambiguous_package_name(arg, atoms, root_config, spinner, myopts):
        print "!!! The short ebuild name \"%s\" is ambiguous. Please specify" % arg
        print "!!! one of the above fully-qualified ebuild names instead.\n"
 
+def profile_check(trees, myaction, myopts):
+       if myaction in ("info", "sync"):
+               return os.EX_OK
+       elif "--version" in myopts or "--help" in myopts:
+               return os.EX_OK
+       for root, root_trees in trees.iteritems():
+               if root_trees["root_config"].settings.profiles:
+                       continue
+               # generate some profile related warning messages
+               validate_ebuild_environment(trees)
+               msg = "If you have just changed your profile configuration, you " + \
+                       "should revert back to the previous configuration. Due to " + \
+                       "your current profile being invalid, allowed actions are " + \
+                       "limited to --help, --info, --sync, and --version."
+               writemsg_level("".join("!!! %s\n" % l for l in textwrap.wrap(msg, 70)),
+                       level=logging.ERROR, noiselevel=-1)
+               return 1
+       return os.EX_OK
+
 def emerge_main():
        global portage  # NFC why this is necessary now - genone
        portage._disable_legacy_globals()
@@ -13482,6 +13501,9 @@ def emerge_main():
        os.umask(022)
        settings, trees, mtimedb = load_emerge_config()
        portdb = trees[settings["ROOT"]]["porttree"].dbapi
+       rval = profile_check(trees, myaction, myopts)
+       if rval != os.EX_OK:
+               return rval
 
        if portage._global_updates(trees, mtimedb["updates"]):
                mtimedb.commit()
index ff40f2f5c7d2b886369c0cb54499dad36b2e1f77..929b82ad2ce0958a0cf1fb830617754ccb10f29e 100644 (file)
@@ -1220,7 +1220,7 @@ class config(object):
                                        writemsg("!!! ParseError: %s\n" % str(e), noiselevel=-1)
                                        del e
                                        self.profiles = []
-                       if local_config:
+                       if local_config and self.profiles:
                                custom_prof = os.path.join(
                                        config_root, CUSTOM_PROFILE_PATH.lstrip(os.path.sep))
                                if os.path.exists(custom_prof):