Gentoo Archives: gentoo-portage-dev

From: Alexandru Elisei <alexandru.elisei@×××××.com>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] emaint: add more meaningful error messages to the logs module
Date: Thu, 19 Jan 2017 18:53:04
Message-Id: CAB-4s4ktW=nTKhnuXoYmAEe4VX=boXC53CKXW2z6_ZhqjVC_4w@mail.gmail.com
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 pym/portage/emaint/modules/logs/logs.py | 14 +++++++++++---
9 1 file changed, 11 insertions(+), 3 deletions(-)
10
11 diff --git a/pym/portage/emaint/modules/logs/logs.py
12 b/pym/portage/emaint/modules/logs/logs.py
13 index fe65cf5..7633741 100644
14 --- a/pym/portage/emaint/modules/logs/logs.py
15 +++ b/pym/portage/emaint/modules/logs/logs.py
16 @@ -8,6 +8,11 @@ from portage.util import shlex_split, varexpand
17 ## default clean command from make.globals
18 ## PORT_LOGDIR_CLEAN = 'find "${PORT_LOGDIR}" -type f ! -name
19 "summary.log*" -mtime +7 -delete'
20
21 +ERROR_MESSAGES = {
22 + 78 : "PORT_LOGDIR variable not set or PORT_LOGDIR not a directory.",
23 + 127 : "PORT_LOGDIR_CLEAN command not found."
24 +}
25 +
26 class CleanLogs(object):
27
28 short_desc = "Clean PORT_LOGDIR logs"
29 @@ -80,7 +85,7 @@ class CleanLogs(object):
30 def _clean_logs(clean_cmd, settings):
31 logdir = settings.get("PORT_LOGDIR")
32 if logdir is None or not os.path.isdir(logdir):
33 - return
34 + return 78
35
36 variables = {"PORT_LOGDIR" : logdir}
37 cmd = [varexpand(x, mydict=variables) for x in clean_cmd]
38 @@ -96,8 +101,11 @@ class CleanLogs(object):
39 def _convert_errors(rval):
40 msg = []
41 if rval != os.EX_OK:
42 - msg.append("PORT_LOGDIR_CLEAN command returned %s"
43 - % ("%d" % rval if rval else "None"))
44 + if rval in ERROR_MESSAGES:
45 + msg.append(ERROR_MESSAGES[rval])
46 + else:
47 + msg.append("PORT_LOGDIR_CLEAN command returned %s"
48 + % ("%d" % rval if rval else "None"))
49 msg.append("See the make.conf(5) man page for "
50 "PORT_LOGDIR_CLEAN usage instructions.")
51 return msg
52 --
53 2.10.2

Replies