Skip to content

Commit

Permalink
fix(common.py/main.py): Fix global settings changes
Browse files Browse the repository at this point in the history
While doing global settings change due bad internet connection i
reversed to old version by mistake. This will fix kernelci#42
 and make it work as intended.

Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
  • Loading branch information
nuclearcat committed Nov 13, 2024
1 parent 34d7a98 commit db15a26
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
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

0 comments on commit db15a26

Please sign in to comment.