Gentoo Archives: gentoo-portage-dev

From: Brian Dolbec <dolsen@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] Re: [PATCH V2] emaint: add more meaningful error messages to the logs module
Date: Thu, 19 Jan 2017 21:21:10
Message-Id: 20170119132105.08dadffa.dolsen@gentoo.org
In Reply to: [gentoo-portage-dev] Re: [PATCH V2] emaint: add more meaningful error messages to the logs module by Alexandru Elisei
1 On Thu, 19 Jan 2017 23:02:28 +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 > #
12 > # I've removed the check for rval being None because the only code
13 > path that # made that possible has been changed to return error code
14 > 78. #
15 > pym/portage/emaint/modules/logs/logs.py | 13 ++++++++++---
16 > 1 file changed, 10 insertions(+), 3 deletions(-)
17 >
18 > diff --git a/pym/portage/emaint/modules/logs/logs.py
19 > b/pym/portage/emaint/modules/logs/logs.py
20 > index 028084a..1b39d42 100644
21 > --- a/pym/portage/emaint/modules/logs/logs.py
22 > +++ b/pym/portage/emaint/modules/logs/logs.py
23 > @@ -8,6 +8,11 @@ from portage.util import shlex_split, varexpand
24 > ## default clean command from make.globals
25 > ## PORT_LOGDIR_CLEAN = 'find "${PORT_LOGDIR}" -type f ! -name
26 > "summary.log*" -mtime +7 -delete'
27 >
28 > +ERROR_MESSAGES = {
29 > + 78 : "PORT_LOGDIR variable not set or PORT_LOGDIR not
30 > a directory.",
31 > + 127 : "PORT_LOGDIR_CLEAN command not found."
32 > +}
33 > +
34 > class CleanLogs(object):
35 >
36 > short_desc = "Clean PORT_LOGDIR logs"
37 > @@ -81,7 +86,7 @@ class CleanLogs(object):
38 > def _clean_logs(clean_cmd, settings):
39 > logdir = settings.get("PORT_LOGDIR")
40 > if logdir is None or not os.path.isdir(logdir):
41 > - return
42 > + return 78
43 >
44 > variables = {"PORT_LOGDIR" : logdir}
45 > cmd = [varexpand(x, mydict=variables) for x in
46 > clean_cmd] @@ -97,8 +102,10 @@ class CleanLogs(object):
47 > def _convert_errors(rval):
48 > msg = []
49 > if rval != os.EX_OK:
50 > - msg.append("PORT_LOGDIR_CLEAN command
51 > returned %s"
52 > - % ("%d" % rval if rval else "None"))
53 > + if rval in ERROR_MESSAGES:
54 > + msg.append(ERROR_MESSAGES[rval])
55 > + else:
56 > + msg.append("PORT_LOGDIR_CLEAN
57 > command returned %s" % rval) msg.append("See the make.conf(5) man
58 > page for " "PORT_LOGDIR_CLEAN usage instructions.")
59 > return msg
60
61
62 Thanks, applied by hand. Seems it was not rebased onto your previous
63 patches. My editor also did a bit on whitespace cleanup. So you will
64 likely have to force your branch to the new master since your commit
65 will likely not like mine.
66
67 --
68 Brian Dolbec <dolsen>