Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions kcidev/libs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion kcidev/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading