diff --git a/kcidev/libs/common.py b/kcidev/libs/common.py index 307494a..482dc97 100644 --- a/kcidev/libs/common.py +++ b/kcidev/libs/common.py @@ -7,14 +7,25 @@ def load_toml(settings): - if not settings: - if os.path.exists(".kci-dev.toml"): - settings = ".kci-dev.toml" - else: - homedir = os.path.expanduser("~") - settings = os.path.join(homedir, ".config", "kci-dev.toml") - if not os.path.exists(settings): - raise FileNotFoundError(f"Settings file {settings} not found") - with open(settings) as fp: - config = toml.load(fp) + fname = "kci-dev.toml" + config = None + + global_path = os.path.join("/", "etc", fname) + if os.path.exists(global_path): + with open(global_path, "r") as f: + config = toml.load(f) + + home_dir = os.path.expanduser("~") + user_path = os.path.join(home_dir, ".config", "kci-dev", fname) + if os.path.exists(user_path): + with open(user_path, "r") as f: + config = toml.load(f) + + if os.path.exists(settings): + with open(settings, "r") as f: + config = toml.load(f) + + if not config: + raise FileNotFoundError("No configuration file found") + return config diff --git a/kcidev/main.py b/kcidev/main.py index dd2d1fd..69473e3 100755 --- a/kcidev/main.py +++ b/kcidev/main.py @@ -11,7 +11,12 @@ help="Stand alone tool for Linux Kernel developers and maintainers that can test local Linux Kernel changes on a enabled KernelCI server" ) @click.version_option("0.1.0", prog_name="kci-dev") -@click.option("--settings", default=None, help="path of toml setting file") +@click.option( + "--settings", + default=".kci-dev.toml", + help="Local settings file to use", + required=False, +) @click.option("--instance", help="API instance to use", required=False) @click.pass_context def cli(ctx, settings, instance):