When a build fails, generate a status message showing which package
authorZac Medico <zmedico@gentoo.org>
Thu, 14 Aug 2008 20:28:33 +0000 (20:28 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 14 Aug 2008 20:28:33 +0000 (20:28 -0000)
failed and the path of the relevant log file if available. Thanks
to _neuron_ for the suggestion. Here is some sample output:

 >>> Emerging (1 of 1) foo-bar/baz-1.0
 >>> Failed to emerge foo-bar/baz-1.0, Log file:
 >>>  '/var/log/portage/foo-bar:baz-1.0:20080814-202327.log'

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

pym/_emerge/__init__.py

index 9bc06db221cf9c3ccbeddbd75b1e745cc3e2d519..a900dbb61cd6e9e7bc27758664e134d72965a483 100644 (file)
@@ -9428,27 +9428,12 @@ class Scheduler(PollScheduler):
 
                        log_paths = [failed_pkg.build_log]
 
-                       if not (build_dir and os.path.isdir(build_dir)):
-                               log_paths.append(failed_pkg.fetch_log)
-
-                       for log_path in log_paths:
-                               if not log_path:
-                                       continue
-
-                               try:
-                                       log_size = os.stat(log_path).st_size
-                               except OSError:
-                                       continue
-
-                               if log_size == 0:
-                                       continue
-
+                       log_path = self._locate_failure_log(failed_pkg)
+                       if log_path is not None:
                                try:
                                        log_file = open(log_path, 'rb')
                                except IOError:
-                                       continue
-
-                               break
+                                       pass
 
                        if log_file is not None:
                                try:
@@ -9505,6 +9490,32 @@ class Scheduler(PollScheduler):
                        self._failed_pkgs_die_msgs.append(
                                (mysettings, key, errors))
 
+       def _locate_failure_log(self, failed_pkg):
+
+               build_dir = failed_pkg.build_dir
+               log_file = None
+
+               log_paths = [failed_pkg.build_log]
+
+               if not (build_dir and os.path.isdir(build_dir)):
+                       log_paths.append(failed_pkg.fetch_log)
+
+               for log_path in log_paths:
+                       if not log_path:
+                               continue
+
+                       try:
+                               log_size = os.stat(log_path).st_size
+                       except OSError:
+                               continue
+
+                       if log_size == 0:
+                               continue
+
+                       return log_path
+
+               return None
+
        def _add_packages(self):
                pkg_queue = self._pkg_queue
                for pkg in self._mergelist:
@@ -9534,6 +9545,7 @@ class Scheduler(PollScheduler):
                                build_dir=build_dir, build_log=build_log,
                                fetch_log=fetch_log, pkg=pkg,
                                returncode=merge.returncode))
+                       self._failed_pkg_msg(self._failed_pkgs[-1], "install", "to")
 
                        self._status_display.failed = len(self._failed_pkgs)
                        return
@@ -9578,6 +9590,7 @@ class Scheduler(PollScheduler):
                                build_dir=build_dir, build_log=build_log,
                                fetch_log=fetch_log, pkg=build.pkg,
                                returncode=build.returncode))
+                       self._failed_pkg_msg(self._failed_pkgs[-1], "emerge", "for")
 
                        self._status_display.failed = len(self._failed_pkgs)
                        self._deallocate_config(build.settings)
@@ -9851,6 +9864,21 @@ class Scheduler(PollScheduler):
 
                return task
 
+       def _failed_pkg_msg(self, failed_pkg, action, preposition):
+               pkg = failed_pkg.pkg
+               msg = "%s to %s %s" % \
+                       (bad("Failed"), action, colorize("INFORM", pkg.cpv))
+               if pkg.root != "/":
+                       msg += " %s %s" % (preposition, pkg.root)
+
+               log_path = self._locate_failure_log(failed_pkg)
+               if log_path is not None:
+                       msg += ", Log file:"
+               self._status_msg(msg)
+
+               if log_path is not None:
+                       self._status_msg(" '%s'" % (colorize("INFORM", log_path),))
+
        def _status_msg(self, msg):
                """
                Display a brief status message (no newlines) in the status display.