Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global config #42

Merged
merged 2 commits into from
Nov 13, 2024
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
8 changes: 7 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ poetry run kci-dev

## Configuration

kci-dev uses a configuration file .kci-dev.toml in the program directory.
kci-dev searches for and loads a configuration file in the following order of priority:
1) The global configuration file located at /etc/kci-dev.toml.
2) The user-specific configuration file at ~/.config/kci-dev/kci-dev.toml
3) A site-specific configuration file, which is .kci-dev.toml by default, but can be overridden with the --settings option.

Priority: The configuration files are loaded in the order listed above, with each subsequent file overriding the settings from the previous one. If a user-specific file is present, it will override the global configuration. The site-specific file, whether default or specified by --settings, takes precedence over both the global and user-specific configuration files.

```toml
default_instance="local"

Expand Down
10 changes: 10 additions & 0 deletions kcidev/libs/common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os

import toml


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)
return config
2 changes: 1 addition & 1 deletion kcidev/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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=".kci-dev.toml", help="path of toml setting file")
@click.option("--settings", default=None, help="path of toml setting file")
@click.option("--instance", help="API instance to use", required=False)
@click.pass_context
def cli(ctx, settings, instance):
Expand Down
Loading