commit:     45e2a7c1d0ce8e9ef7bba0cae4b4648a5d764540
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 30 13:37:35 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sat Dec 30 13:37:35 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=45e2a7c1

argparse: better handling of ~/.bugzrc

Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgdev/scripts/argparsers.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/pkgdev/scripts/argparsers.py b/src/pkgdev/scripts/argparsers.py
index 5cefeca..9ab58da 100644
--- a/src/pkgdev/scripts/argparsers.py
+++ b/src/pkgdev/scripts/argparsers.py
@@ -1,6 +1,7 @@
 import os
 import subprocess
 from configparser import ConfigParser
+from contextlib import suppress
 from pathlib import Path
 
 from pkgcore.repository import errors as repo_errors
@@ -75,8 +76,13 @@ class BugzillaApiKey:
             try:
                 config = ConfigParser(default_section="default")
                 config.read(bugz_rc_file)
-                setattr(namespace, attr, config.get("default", "key"))
             except Exception as e:
                 raise ValueError(f"failed parsing {bugz_rc_file}: {e}")
-        elif (bugz_token_file := Path.home() / ".bugz_token").is_file():
+
+            for category in ("default", "gentoo", "Gentoo"):
+                with suppress(Exception):
+                    setattr(namespace, attr, config.get(category, "key"))
+                    return
+
+        if (bugz_token_file := Path.home() / ".bugz_token").is_file():
             setattr(namespace, attr, bugz_token_file.read_text().strip())

Reply via email to