Gentoo Archives: gentoo-portage-dev

From: Brian Dolbec <dolsen@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] emaint: add more meaningful error messages to the logs module
Date: Thu, 19 Jan 2017 20:22:37
Message-Id: 20170119122229.1267f153.dolsen@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] emaint: add more meaningful error messages to the logs module by Alexandru Elisei
1 On Thu, 19 Jan 2017 20:53:02 +0200
2 Alexandru Elisei <alexandru.elisei@×××××.com> wrote:
3
4 > The logs module can fail for a variety of reasons: the PORT_LOGDIR
5 > variable isn't set in make.conf or it doesn't point to a directory;
6 > the PORT_LOGDIR_CLEAN command uses a binary which isn't present in the
7 > system or the binary itself failed during execution. There is only one
8 > generic error message for all these cases. The patch adds error
9 > messages that better describe the reason for the failure.
10 > ---
11 > pym/portage/emaint/modules/logs/logs.py | 14 +++++++++++---
12 > 1 file changed, 11 insertions(+), 3 deletions(-)
13 >
14 > diff --git a/pym/portage/emaint/modules/logs/logs.py
15 > b/pym/portage/emaint/modules/logs/logs.py
16 > index fe65cf5..7633741 100644
17 > --- a/pym/portage/emaint/modules/logs/logs.py
18 > +++ b/pym/portage/emaint/modules/logs/logs.py
19 > @@ -8,6 +8,11 @@ from portage.util import shlex_split, varexpand
20 > ## default clean command from make.globals
21 > ## PORT_LOGDIR_CLEAN = 'find "${PORT_LOGDIR}" -type f ! -name
22 > "summary.log*" -mtime +7 -delete'
23 >
24 > +ERROR_MESSAGES = {
25 > + 78 : "PORT_LOGDIR variable not set or PORT_LOGDIR not
26 > 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 > @@ -80,7 +85,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
42 > clean_cmd] @@ -96,8 +101,11 @@ class CleanLogs(object):
43 > def _convert_errors(rval):
44 > msg = []
45 > if rval != os.EX_OK:
46 > - msg.append("PORT_LOGDIR_CLEAN command
47 > returned %s"
48 > - % ("%d" % rval if rval else "None"))
49 > + if rval in ERROR_MESSAGES:
50 > + msg.append(ERROR_MESSAGES[rval])
51 > + else:
52 > + msg.append("PORT_LOGDIR_CLEAN
53 > command returned %s"
54 > + % ("%d" % rval if rval else
55 > "None")) msg.append("See the make.conf(5) man page for "
56 > "PORT_LOGDIR_CLEAN usage
57 > instructions.") return msg
58
59 Thank you, looks good
60
61 --
62 Brian Dolbec <dolsen>