From cd5a8e80f949f649b6d2b174bc899f1f092684fd Mon Sep 17 00:00:00 2001 From: fuzzyray Date: Thu, 7 May 2009 22:15:50 +0000 Subject: [PATCH] Add patch from Robert Buchholz: Add quiet option Incorporate option to quiet down glsa-check, based on a patch by Thilo Bangert in bug #170784. This option will also suppress sending of empty mail, based on a patch by Christian Gut in bug #182990. svn path=/trunk/gentoolkit/; revision=633 --- bin/glsa-check | 28 ++++++++++++++++++++-------- man/glsa-check.1 | 5 ++++- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/bin/glsa-check b/bin/glsa-check index c106c12..f33bc23 100644 --- a/bin/glsa-check +++ b/bin/glsa-check @@ -35,7 +35,8 @@ optionmap = [ ["-V", "--version", "some information about this tool"], ["-v", "--verbose", "print more information (option)"], ["-c", "--cve", "show CVE ids in listing mode (option)"], -["-m", "--mail", "send a mail with the given GLSAs to the administrator"] +["-q", "--quiet", "be less verbose and do not send empty mail (option)"], +["-m", "--mail", "send a mail with the given GLSAs to the administrator"], ] # print a warning as this is beta code (but proven by now, so no more warning) @@ -52,7 +53,6 @@ params = [] try: args, params = getopt(sys.argv[1:], "".join([o[0][1] for o in optionmap]), \ [x[2:] for x in reduce(lambda x,y: x+y, [z[1:-1] for z in optionmap])]) -# ["dump", "print", "list", "pretend", "fix", "inject", "help", "verbose", "version", "test", "nocolor", "cve", "mail"]) args = [a for a,b in args] for option in ["--nocolor", "-n"]: @@ -78,6 +78,13 @@ try: least_change = False args.remove(option) + quiet = False + for option in ["--quiet", "-q"]: + if option in args: + quiet = True + args.remove(option) + + # sanity checking if len(args) <= 0: sys.stderr.write("no option given: what should I do ?\n") @@ -143,6 +150,9 @@ from gentoolkit.glsa import * glsaconfig = checkconfig(portage.config(clone=portage.settings)) +if quiet: + glsaconfig["EMERGE_OPTS"] += " --quiet" + vardb = portage.db["/"]["vartree"].dbapi portdb = portage.db["/"]["porttree"].dbapi @@ -190,9 +200,10 @@ for p in params[:]: glsalist.extend([g for g in params if g not in glsalist]) def summarylist(myglsalist, fd1=sys.stdout, fd2=sys.stderr): - fd2.write(white("[A]")+" means this GLSA was already applied,\n") - fd2.write(green("[U]")+" means the system is not affected and\n") - fd2.write(red("[N]")+" indicates that the system might be affected.\n\n") + if not quiet: + fd2.write(white("[A]")+" means this GLSA was already applied,\n") + fd2.write(green("[U]")+" means the system is not affected and\n") + fd2.write(red("[N]")+" indicates that the system might be affected.\n\n") myglsalist.sort() for myid in myglsalist: @@ -363,9 +374,10 @@ if mode == "mail": myglsa.dump(outstream=myfd) myattachments.append(MIMEText(str(myfd.getvalue()), _charset="utf8")) myfd.close() - - mymessage = portage_mail.create_message(myfrom, myrecipient, mysubject, summary, myattachments) - portage_mail.send_mail(glsaconfig, mymessage) + + if glsalist or not quiet: + mymessage = portage_mail.create_message(myfrom, myrecipient, mysubject, summary, myattachments) + portage_mail.send_mail(glsaconfig, mymessage) sys.exit(0) diff --git a/man/glsa-check.1 b/man/glsa-check.1 index bf5bc15..3cfca23 100644 --- a/man/glsa-check.1 +++ b/man/glsa-check.1 @@ -1,7 +1,7 @@ .TH "glsa-check" "1" "0.6" "Marius Mauch" "gentoolkit" .SH "NAME" .LP -glsa\-check \- Gentoo: Tool to locally monitor and manage GLSA's +glsa\-check \- Gentoo: Tool to locally monitor and manage GLSAs .SH "SYNTAX" .LP glsa\-check <\fIoption\fP> [\fIglsa\-list\fP] @@ -52,6 +52,9 @@ print more messages (option) .TP .B \-c, \-\-cve show CVE ids in listing mode (option) +.TP +.B \-q, \-\-quiet +be less verbose and do not send empty mail (option) .TP .B \-m, \-\-mail send a mail with the given GLSAs to the administrator -- 2.26.2