Skip to content

Commit

Permalink
Merge pull request #42 from nuclearcat/add-global-config
Browse files Browse the repository at this point in the history
Add global config
  • Loading branch information
aliceinwire authored Nov 13, 2024
2 parents 5863b6b + e25a0b7 commit 34d7a98
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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

0 comments on commit 34d7a98

Please sign in to comment.