commit:     afe8e736d3de4c7c5519f6495cc5455e0d860383
Author:     Alexandru Elisei <alexandru.elisei <AT> gmail <DOT> com>
AuthorDate: Thu Jan 19 21:12:33 2017 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Jan 19 21:14:15 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=afe8e736

emaint: add more meaningful error messages to the logs module

The logs module can fail for a variety of reasons: the PORT_LOGDIR
variable isn't set in make.conf or it doesn't point to a directory; the
PORT_LOGDIR_CLEAN command uses a binary which isn't present in the
system or the binary itself failed during execution. There is only one
generic error message for all these cases. The patch adds error messages
that better describe the reason for the failure.

 pym/portage/emaint/modules/logs/logs.py | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/pym/portage/emaint/modules/logs/logs.py 
b/pym/portage/emaint/modules/logs/logs.py
index 028084a..631aeef 100644
--- a/pym/portage/emaint/modules/logs/logs.py
+++ b/pym/portage/emaint/modules/logs/logs.py
@@ -8,6 +8,12 @@ from portage.util import shlex_split, varexpand
 ## default clean command from make.globals
 ## PORT_LOGDIR_CLEAN = 'find "${PORT_LOGDIR}" -type f ! -name "summary.log*" 
-mtime +7 -delete'
 
+ERROR_MESSAGES = {
+       78      : "PORT_LOGDIR variable not set or PORT_LOGDIR not a 
directory.",
+       127     : "PORT_LOGDIR_CLEAN command not found."
+}
+
+
 class CleanLogs(object):
 
        short_desc = "Clean PORT_LOGDIR logs"
@@ -31,12 +37,12 @@ class CleanLogs(object):
 
        def clean(self, **kwargs):
                """Log directory cleaning function
-               
+
                @param **kwargs: optional dictionary of values used in this 
function are:
                        settings: portage settings instance: defaults to 
portage.settings
                                "PORT_LOGDIR": directory to clean
                                "PORT_LOGDIR_CLEAN": command for cleaning the 
logs.
-                       options: dict: 
+                       options: dict:
                                'NUM': int: number of days
                                'pretend': boolean
                """
@@ -81,7 +87,7 @@ class CleanLogs(object):
        def _clean_logs(clean_cmd, settings):
                logdir = settings.get("PORT_LOGDIR")
                if logdir is None or not os.path.isdir(logdir):
-                       return
+                       return 78
 
                variables = {"PORT_LOGDIR" : logdir}
                cmd = [varexpand(x, mydict=variables) for x in clean_cmd]
@@ -97,8 +103,10 @@ class CleanLogs(object):
        def _convert_errors(rval):
                msg = []
                if rval != os.EX_OK:
-                       msg.append("PORT_LOGDIR_CLEAN command returned %s"
-                               % ("%d" % rval if rval else "None"))
+                       if rval in ERROR_MESSAGES:
+                               msg.append(ERROR_MESSAGES[rval])
+                       else:
+                               msg.append("PORT_LOGDIR_CLEAN command returned 
%s" % rval)
                        msg.append("See the make.conf(5) man page for "
                                "PORT_LOGDIR_CLEAN usage instructions.")
                return msg

Reply via email to