Gentoo Archives: gentoo-portage-dev

From: Alexandru Elisei <alexandru.elisei@×××××.com>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] Re: [PATCH V2] emaint: add more meaningful error messages to the logs module
Date: Thu, 19 Jan 2017 21:02:33
Message-Id: CAB-4s4nrDTp8XGT8_cFOZF8L+2CVuFPRqv-_umAAOU_V1ugv5A@mail.gmail.com
In Reply to: [gentoo-portage-dev] [PATCH] emaint: add more meaningful error messages to the logs module by Alexandru Elisei
1 The logs module can fail for a variety of reasons: the PORT_LOGDIR
2 variable isn't set in make.conf or it doesn't point to a directory; the
3 PORT_LOGDIR_CLEAN command uses a binary which isn't present in the
4 system or the binary itself failed during execution. There is only one
5 generic error message for all these cases. The patch adds error messages
6 that better describe the reason for the failure.
7 ---
8 #
9 # I've removed the check for rval being None because the only code path that
10 # made that possible has been changed to return error code 78.
11 #
12 pym/portage/emaint/modules/logs/logs.py | 13 ++++++++++---
13 1 file changed, 10 insertions(+), 3 deletions(-)
14
15 diff --git a/pym/portage/emaint/modules/logs/logs.py
16 b/pym/portage/emaint/modules/logs/logs.py
17 index 028084a..1b39d42 100644
18 --- a/pym/portage/emaint/modules/logs/logs.py
19 +++ b/pym/portage/emaint/modules/logs/logs.py
20 @@ -8,6 +8,11 @@ from portage.util import shlex_split, varexpand
21 ## default clean command from make.globals
22 ## PORT_LOGDIR_CLEAN = 'find "${PORT_LOGDIR}" -type f ! -name
23 "summary.log*" -mtime +7 -delete'
24
25 +ERROR_MESSAGES = {
26 + 78 : "PORT_LOGDIR variable not set or PORT_LOGDIR not a directory.",
27 + 127 : "PORT_LOGDIR_CLEAN command not found."
28 +}
29 +
30 class CleanLogs(object):
31
32 short_desc = "Clean PORT_LOGDIR logs"
33 @@ -81,7 +86,7 @@ class CleanLogs(object):
34 def _clean_logs(clean_cmd, settings):
35 logdir = settings.get("PORT_LOGDIR")
36 if logdir is None or not os.path.isdir(logdir):
37 - return
38 + return 78
39
40 variables = {"PORT_LOGDIR" : logdir}
41 cmd = [varexpand(x, mydict=variables) for x in clean_cmd]
42 @@ -97,8 +102,10 @@ class CleanLogs(object):
43 def _convert_errors(rval):
44 msg = []
45 if rval != os.EX_OK:
46 - msg.append("PORT_LOGDIR_CLEAN command returned %s"
47 - % ("%d" % rval if rval else "None"))
48 + if rval in ERROR_MESSAGES:
49 + msg.append(ERROR_MESSAGES[rval])
50 + else:
51 + msg.append("PORT_LOGDIR_CLEAN command returned %s" % rval)
52 msg.append("See the make.conf(5) man page for "
53 "PORT_LOGDIR_CLEAN usage instructions.")
54 return msg
55 --
56 2.10.2

Replies