commit:     086e4ebc09b6e158ecf7cadd1906c73e9784e12b
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Fri Jan 20 18:34:08 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Fri Jan 20 18:34:08 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=086e4ebc

scan: suppress non-error results in quiet mode

When in quiet mode, include in scan only results of error level.

Resolves: https://github.com/pkgcore/pkgcheck/issues/413
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcheck/scripts/pkgcheck_scan.py |  5 ++++-
 tests/scripts/test_pkgcheck_scan.py   | 13 +++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/pkgcheck/scripts/pkgcheck_scan.py 
b/src/pkgcheck/scripts/pkgcheck_scan.py
index 1d583407..b19afafb 100644
--- a/src/pkgcheck/scripts/pkgcheck_scan.py
+++ b/src/pkgcheck/scripts/pkgcheck_scan.py
@@ -475,7 +475,10 @@ def _default_enabled_checks(namespace, attr):
 @scan.bind_delayed_default(1000, "filtered_keywords")
 def _default_filtered_keywords(namespace, attr):
     """Enable all keywords to be shown by default."""
-    setattr(namespace, attr, set(objects.KEYWORDS.values()))
+    filtered_keywords = set(objects.KEYWORDS.values())
+    if namespace.verbosity < 0:  # quiet mode, include only errors
+        filtered_keywords = {x for x in filtered_keywords if x.level == 
"error"}
+    setattr(namespace, attr, filtered_keywords)
 
 
 @scan.bind_delayed_default(9999, "restrictions")

diff --git a/tests/scripts/test_pkgcheck_scan.py 
b/tests/scripts/test_pkgcheck_scan.py
index 84030760..7d191ee5 100644
--- a/tests/scripts/test_pkgcheck_scan.py
+++ b/tests/scripts/test_pkgcheck_scan.py
@@ -486,6 +486,19 @@ class TestPkgcheckScan:
         results = list(self.scan(self.scan_args + ["-r", repo.location, 
"cat/unknown"]))
         assert not results
 
+    def test_scan_quiet(self, repo):
+        # create an ebuild referencing variable in homepage
+        repo.create_ebuild("cat/pkg-0", homepage="https://example.com/${PN}";)
+
+        # in non-quiet mode, the result is shown
+        results = list(self.scan(self.scan_args + ["-r", repo.location]))
+        assert len(results) == 1
+
+        # in quiet mode, the result is suppressed
+        for arg in ("-q", "--quiet"):
+            results = list(self.scan(self.scan_args + ["-r", repo.location, 
arg]))
+            assert not results
+
     def test_explict_skip_check(self):
         """SkipCheck exceptions are raised when triggered for explicitly 
enabled checks."""
         error = "network checks not enabled"

Reply via email to