From f8c01e25588886818749ae41dd0a712beb3ee691 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Sep 25 2018 16:41:07 +0000 Subject: [python][cli] better errors with --config --- diff --git a/cli/copr_cli/main.py b/cli/copr_cli/main.py index 7ce171c..9e00e0a 100644 --- a/cli/copr_cli/main.py +++ b/cli/copr_cli/main.py @@ -61,13 +61,12 @@ except NameError: class Commands(object): def __init__(self, config_path): - try: - self.config_path = config_path - self.config = config_from_file(config_path) + self.config_path = config_path or '~/.config/copr' - except (CoprNoConfigException, - CoprConfigException): - sys.stderr.write(no_config_warning.format(config_path or "~/.config/copr")) + try: + self.config = config_from_file(self.config_path) + except (CoprNoConfigException, CoprConfigException): + sys.stderr.write(no_config_warning.format(self.config_path)) self.config = {"copr_url": "http://copr.fedoraproject.org", "no_config": True} self.client = Client(self.config) @@ -95,13 +94,13 @@ class Commands(object): if "no_config" in self.config and args.username is None: sys.stderr.write( "Error: Operation requires username\n" - "Pass username to command or create `~/.config/copr`\n") + "Pass username to command or create `{0}`\n".format(self.config_path)) sys.exit(6) if args.username is None and self.config["username"] is None: sys.stderr.write( "Error: Operation requires username\n" - "Pass username to command or add it to `~/.config/copr`\n") + "Pass username to command or add it to `{0}`\n".format(self.config_path)) sys.exit(6) return func(self, args) diff --git a/python/copr/v3/helpers.py b/python/copr/v3/helpers.py index d200a5a..1bf15b9 100644 --- a/python/copr/v3/helpers.py +++ b/python/copr/v3/helpers.py @@ -13,7 +13,7 @@ class List(list): def config_from_file(path=None): raw_config = configparser.ConfigParser() - path = path or os.path.join(os.path.expanduser("~"), ".config", "copr") + path = os.path.expanduser(path or os.path.join("~", ".config", "copr")) config = {} try: