From 45e2a7c1d0ce8e9ef7bba0cae4b4648a5d764540 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Sat, 30 Dec 2023 15:37:35 +0200 Subject: argparse: better handling of ~/.bugzrc Signed-off-by: Arthur Zamarin --- 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()) -- cgit v1.2.3-65-gdbad