[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-portage-dev
Subject:    Re: [gentoo-portage-dev] [PATCH] emaint: add more meaningful error messages to the logs module
From:       Brian Dolbec <dolsen () gentoo ! org>
Date:       2017-01-19 20:22:29
Message-ID: 20170119122229.1267f153.dolsen () gentoo ! org
[Download RAW message or body]

On Thu, 19 Jan 2017 20:53:02 +0200
Alexandru Elisei <alexandru.elisei@gmail.com> wrote:

> 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 | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/pym/portage/emaint/modules/logs/logs.py
> b/pym/portage/emaint/modules/logs/logs.py
> index fe65cf5..7633741 100644
> --- a/pym/portage/emaint/modules/logs/logs.py
> +++ b/pym/portage/emaint/modules/logs/logs.py
> @@ -8,6 +8,11 @@ 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"
> @@ -80,7 +85,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] @@ -96,8 +101,11 @@ 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"
> +					% ("%d" % rval if rval else
> "None")) msg.append("See the make.conf(5) man page for "
>  				"PORT_LOGDIR_CLEAN usage
> instructions.") return msg

Thank you, looks good

-- 
Brian Dolbec <dolsen>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic