commit:     57e5ea479030de69e43252bd8dc6c93e6a87369a
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Aug 29 17:49:54 2019 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Aug 29 19:27:19 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=57e5ea47

glsa-check: Add --quiet option

This patch is a forward port of the following commit:

https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=cd5a8e80f949f649b6d2b174bc899f1f092684fd

commit cd5a8e80f949f649b6d2b174bc899f1f092684fd
Author:     fuzzyray <fuzzyray <AT> gentoo.org>
AuthorDate: 2009-05-07 22:15:50 +0000
Commit:     fuzzyray <fuzzyray <AT> gentoo.org>
CommitDate: 2009-05-07 22:15:50 +0000

    Add patch from Robert Buchholz: Add quiet option
    Incorporate option to quiet down glsa-check, based on a patch by Thilo
    Bangert <bangert <AT> gentoo.org> in bug #170784.
    This option will also suppress sending of empty mail, based on a patch
    by Christian Gut <cycloon <AT> is-root.org> in bug #182990.

    svn path=/trunk/gentoolkit/; revision=633

Bug: https://bugs.gentoo.org/692872
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 bin/glsa-check   | 17 +++++++++++------
 man/glsa-check.1 |  3 +++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/bin/glsa-check b/bin/glsa-check
index 83ea6b7c3..bfcbaa61f 100755
--- a/bin/glsa-check
+++ b/bin/glsa-check
@@ -57,6 +57,8 @@ modes.add_argument("-m", "--mail", action="store_const",
                help="Send a mail with the given GLSAs to the administrator")
 parser.add_argument("-V", "--version", action="store_true",
                help="Show information about glsa-check")
+parser.add_argument("-q", "--quiet", action="store_true", dest="quiet",
+               help="Be less verbose and do not send empty mail")
 parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
                help="Print more messages")
 parser.add_argument("-n", "--nocolor", action="store_true",
@@ -80,6 +82,7 @@ if options.version:
 mode = options.mode
 least_change = options.least_change
 list_cve = options.list_cve
+quiet = options.quiet
 verbose = options.verbose
 
 # Sanity checking
@@ -153,9 +156,10 @@ def summarylist(myglsalist, fd1=sys.stdout, 
fd2=sys.stderr, encoding="utf-8"):
                fd2 = fd2.buffer
        fd1 = codecs.getwriter(encoding)(fd1)
        fd2 = codecs.getwriter(encoding)(fd2)
-       fd2.write(white("[A]")+" means this GLSA was marked as applied 
(injected),\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 marked as applied 
(injected),\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:
@@ -231,7 +235,7 @@ if mode in ["dump", "fix", "inject", "pretend"]:
                                        # using emerge for the actual merging 
as it contains the dependency
                                        # code and we want to be consistent in 
behaviour. Also this functionality
                                        # will be integrated in emerge later, 
so it shouldn't hurt much.
-                                       emergecmd = "emerge --oneshot " + " =" 
+ pkg
+                                       emergecmd = "emerge --oneshot" + (" 
--quiet" if quiet else "") + " =" + pkg
                                        if verbose:
                                                sys.stderr.write(emergecmd+"\n")
                                        exitcode = os.system(emergecmd)
@@ -331,8 +335,9 @@ if mode == "mail":
                myattachments.append(MIMEText(attachment, _charset="utf8"))
                myfd.close()
 
-       mymessage = portage.mail.create_message(myfrom, myrecipient, mysubject, 
summary, myattachments)
-       portage.mail.send_mail(portage.settings, mymessage)
+       if glsalist or not quiet:
+               mymessage = portage.mail.create_message(myfrom, myrecipient, 
mysubject, summary, myattachments)
+               portage.mail.send_mail(portage.settings, mymessage)
 
        sys.exit(0)
 

diff --git a/man/glsa-check.1 b/man/glsa-check.1
index a0d49d4dd..f1041737f 100644
--- a/man/glsa-check.1
+++ b/man/glsa-check.1
@@ -37,6 +37,9 @@
 \fBV\fR, \fB\-\-version\fR Show information about \fBglsa\-check\fR\.
 .
 .P
+\fB\-q\fR, \fB\-\-quiet\fR Be less verbose and do not send empty mail\.
+.
+.P
 \fB\-v\fR, \fB\-\-verbose\fR Print more messages\.
 .
 .P

Reply via email to