Instead of calling sys.exit when a ParseError occurs in the config
authorZac Medico <zmedico@gentoo.org>
Tue, 11 Dec 2007 23:26:05 +0000 (23:26 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 11 Dec 2007 23:26:05 +0000 (23:26 -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.

svn path=/main/trunk/; revision=8884

bin/emerge
bin/portageq
pym/_emerge/__init__.py
pym/portage/__init__.py

index 5901c23790dcb360942f5d8b8f47bce47eb4db16..1ef575e1304be6243f4530b53a13759dc5fc48db 100755 (executable)
@@ -13,10 +13,13 @@ except ImportError:
 
 if __name__ == "__main__":
        import sys
-       from portage.exception import PermissionDenied
+       from portage.exception import ParseError, PermissionDenied
        try:
                retval = _emerge.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 0b7eab6fef9542a65d42155de4519f16d9d4328e..972a38392968dce41f240866c88f79293a667048 100755 (executable)
@@ -459,6 +459,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 f5aa7763196b76e32292965f86c5f934bfed567f..0bebfef605f5001900572149092be4ac6d4d1b61 100644 (file)
@@ -7188,7 +7188,3 @@ def emerge_main():
                if "--pretend" in myopts:
                        display_news_notification(trees)
                return retval
-
-if __name__ == "__main__":
-       retval = emerge_main()
-       sys.exit(retval)
index bbb0c57a0425d0224bcedcb1c1d0a1b42efb812a..e32e168391d8ed4be7cb00998869a3c3ec778e95 100644 (file)
@@ -1213,74 +1213,36 @@ class config(object):
 
                        # 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(