Skip to content

Commit 45e2a7c

Browse files
committed
argparse: better handling of ~/.bugzrc
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent d12a4a8 commit 45e2a7c

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/pkgdev/scripts/argparsers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import subprocess
33
from configparser import ConfigParser
4+
from contextlib import suppress
45
from pathlib import Path
56

67
from pkgcore.repository import errors as repo_errors
@@ -75,8 +76,13 @@ def _default_api_key(namespace, attr):
7576
try:
7677
config = ConfigParser(default_section="default")
7778
config.read(bugz_rc_file)
78-
setattr(namespace, attr, config.get("default", "key"))
7979
except Exception as e:
8080
raise ValueError(f"failed parsing {bugz_rc_file}: {e}")
81-
elif (bugz_token_file := Path.home() / ".bugz_token").is_file():
81+
82+
for category in ("default", "gentoo", "Gentoo"):
83+
with suppress(Exception):
84+
setattr(namespace, attr, config.get(category, "key"))
85+
return
86+
87+
if (bugz_token_file := Path.home() / ".bugz_token").is_file():
8288
setattr(namespace, attr, bugz_token_file.read_text().strip())

0 commit comments

Comments
 (0)