Instead of calling sys.exit when a ParseError occurs in the config
authorZac Medico <zmedico@gentoo.org>
Tue, 11 Dec 2007 23:46:11 +0000 (23:46 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 11 Dec 2007 23:46:11 +0000 (23:46 -0000)
constructor, raise a ParseError and make emerge and portageq handle
the error. This way consumers of the portage api can handle the
ParseError rather than have their application exit. Thanks to lxnay
for reporting. (trunk r8884)

svn path=/main/branches/2.1.2/; revision=8886

bin/emerge
bin/portageq
pym/portage.py

index 7c59ece9ae42d30e01dbf275649c7f508cc1d8c1..0c29b187b40d02581a30880571174ddd4c98db24 100755 (executable)
@@ -6635,10 +6635,13 @@ def emerge_main():
                return retval
 
 if __name__ == "__main__":
-       from portage_exception import PermissionDenied
+       from portage_exception import ParseError, PermissionDenied
        try:
                retval = emerge_main()
        except PermissionDenied, e:
                sys.stderr.write("Permission denied: '%s'\n" % str(e))
                sys.exit(e.errno)
+       except ParseError, e:
+               sys.stderr.write("%s\n" % str(e))
+               sys.exit(1)
        sys.exit(retval)
index 056502e399e6844138a37a382638ceb315a95e59..b097889ae38c36dd8626193a570771e1486dbb6f 100755 (executable)
@@ -411,6 +411,9 @@ def main():
        except portage_exception.PermissionDenied, e:
                sys.stderr.write("Permission denied: '%s'\n" % str(e))
                sys.exit(e.errno)
+       except portage_exception.ParseError, e:
+               sys.stderr.write("%s\n" % str(e))
+               sys.exit(1)
        except ValueError, e:
                if not e.args or \
                        not hasattr(e.args[0], "__len__") or \
index 11965f17666a08a565261031e4e4164bdcd225e5..01a2736d360391e8df73b30dfb3c4cd5246f976a 100644 (file)
@@ -1346,74 +1346,36 @@ class config:
 
                        # make.globals should not be relative to config_root
                        # because it only contains constants.
-                       try:
-                               self.mygcfg   = getconfig(os.path.join("/etc", "make.globals"))
+                       self.mygcfg   = getconfig(os.path.join("/etc", "make.globals"))
+
+                       if self.mygcfg is None:
+                               self.mygcfg = {}
 
-                               if self.mygcfg is None:
-                                       self.mygcfg = {}
-                       except SystemExit, e:
-                               raise
-                       except Exception, e:
-                               if debug:
-                                       raise
-                               writemsg("!!! %s\n" % (e), noiselevel=-1)
-                               if not isinstance(e, EnvironmentError):
-                                       writemsg("!!! Incorrect multiline literals can cause " + \
-                                               "this. Do not use them.\n", noiselevel=-1)
-                               sys.exit(1)
                        self.configlist.append(self.mygcfg)
                        self.configdict["globals"]=self.configlist[-1]
 
                        self.make_defaults_use = []
                        self.mygcfg = {}
                        if self.profiles:
-                               try:
-                                       mygcfg_dlists = [getconfig(os.path.join(x, "make.defaults")) for x in self.profiles]
-                                       for cfg in mygcfg_dlists:
-                                               if cfg:
-                                                       self.make_defaults_use.append(cfg.get("USE", ""))
-                                               else:
-                                                       self.make_defaults_use.append("")
-                                       self.mygcfg   = stack_dicts(mygcfg_dlists, incrementals=portage_const.INCREMENTALS, ignore_none=1)
-                                       #self.mygcfg = grab_stacked("make.defaults", self.profiles, getconfig)
-                                       if self.mygcfg is None:
-                                               self.mygcfg = {}
-                               except SystemExit, e:
-                                       raise
-                               except Exception, e:
-                                       if debug:
-                                               raise
-                                       writemsg("!!! %s\n" % (e), noiselevel=-1)
-                                       if not isinstance(e, EnvironmentError):
-                                               writemsg("!!! 'rm -Rf /usr/portage/profiles; " + \
-                                                       "emerge sync' may fix this. If it does\n",
-                                                       noiselevel=-1)
-                                               writemsg("!!! not then please report this to " + \
-                                                       "bugs.gentoo.org and, if possible, a dev\n",
-                                                               noiselevel=-1)
-                                               writemsg("!!! on #gentoo (irc.freenode.org)\n",
-                                                       noiselevel=-1)
-                                       sys.exit(1)
-                       self.configlist.append(self.mygcfg)
-                       self.configdict["defaults"]=self.configlist[-1]
-
-                       try:
-                               self.mygcfg = getconfig(
-                                       os.path.join(config_root, MAKE_CONF_FILE.lstrip(os.path.sep)),
-                                       allow_sourcing=True)
+                               mygcfg_dlists = [getconfig(os.path.join(x, "make.defaults")) \
+                                       for x in self.profiles]
+                               for cfg in mygcfg_dlists:
+                                       if cfg:
+                                               self.make_defaults_use.append(cfg.get("USE", ""))
+                                       else:
+                                               self.make_defaults_use.append("")
+                               self.mygcfg = stack_dicts(mygcfg_dlists,
+                                       incrementals=portage_const.INCREMENTALS, ignore_none=1)
                                if self.mygcfg is None:
                                        self.mygcfg = {}
-                       except SystemExit, e:
-                               raise
-                       except Exception, e:
-                               if debug:
-                                       raise
-                               writemsg("!!! %s\n" % (e), noiselevel=-1)
-                               if not isinstance(e, EnvironmentError):
-                                       writemsg("!!! Incorrect multiline literals can cause " + \
-                                               "this. Do not use them.\n", noiselevel=-1)
-                               sys.exit(1)
+                       self.configlist.append(self.mygcfg)
+                       self.configdict["defaults"]=self.configlist[-1]
 
+                       self.mygcfg = getconfig(
+                               os.path.join(config_root, MAKE_CONF_FILE.lstrip(os.path.sep)),
+                               allow_sourcing=True)
+                       if self.mygcfg is None:
+                               self.mygcfg = {}
 
                        # Don't allow the user to override certain variables in make.conf
                        profile_only_variables = self.configdict["defaults"].get(