From 4acc13584e1168ac5fa0a2168efba80d60164c27 Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Tue, 10 Sep 2024 13:35:42 +0300 Subject: [PATCH 1/3] feat(shebang): Update python to python3 Many distributions don't have python by default, but have python3. Update shebang to reflect that. Signed-off-by: Denys Fedoryshchenko --- kci-dev/kci-dev.py | 2 +- kci-dev/subcommands/commit.py | 2 +- kci-dev/subcommands/patch.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kci-dev/kci-dev.py b/kci-dev/kci-dev.py index 14c889d..3663edc 100755 --- a/kci-dev/kci-dev.py +++ b/kci-dev/kci-dev.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- import click diff --git a/kci-dev/subcommands/commit.py b/kci-dev/subcommands/commit.py index 29d9c07..d6cab92 100644 --- a/kci-dev/subcommands/commit.py +++ b/kci-dev/subcommands/commit.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- import json diff --git a/kci-dev/subcommands/patch.py b/kci-dev/subcommands/patch.py index ed29f22..12177dc 100644 --- a/kci-dev/subcommands/patch.py +++ b/kci-dev/subcommands/patch.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- import json From 89284aee439ff0b8e775087da289333082ee85ac Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Wed, 11 Sep 2024 17:04:32 +0300 Subject: [PATCH 2/3] feat(common.py): Create common library and move load_toml Following DRY principle creating common library and moving load_toml there to deduplicate functions. Signed-off-by: Denys Fedoryshchenko --- kci-dev/libs/__init__.py | 0 kci-dev/libs/common.py | 10 ++++++++++ kci-dev/subcommands/commit.py | 8 ++------ kci-dev/subcommands/patch.py | 8 ++------ 4 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 kci-dev/libs/__init__.py create mode 100644 kci-dev/libs/common.py diff --git a/kci-dev/libs/__init__.py b/kci-dev/libs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kci-dev/libs/common.py b/kci-dev/libs/common.py new file mode 100644 index 0000000..ea5361e --- /dev/null +++ b/kci-dev/libs/common.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import toml + + +def load_toml(settings): + with open(settings) as fp: + config = toml.load(fp) + return config diff --git a/kci-dev/subcommands/commit.py b/kci-dev/subcommands/commit.py index d6cab92..25c1cbf 100644 --- a/kci-dev/subcommands/commit.py +++ b/kci-dev/subcommands/commit.py @@ -8,6 +8,8 @@ import toml from git import Repo +from libs.common import * + def api_connection(host): click.secho("api connect: " + host, fg="green") @@ -41,12 +43,6 @@ def send_build(url, patch, branch, treeurl, token): click.secho(response.json(), fg="green") -def load_toml(settings): - with open(settings) as fp: - config = toml.load(fp) - return config - - @click.command(help="Test commits from a local Kernel repository") @click.option( "--repository", diff --git a/kci-dev/subcommands/patch.py b/kci-dev/subcommands/patch.py index 12177dc..fa77b6f 100644 --- a/kci-dev/subcommands/patch.py +++ b/kci-dev/subcommands/patch.py @@ -8,6 +8,8 @@ import toml from git import Repo +from libs.common import * + def api_connection(host): click.secho("api connect: " + host, fg="green") @@ -31,12 +33,6 @@ def send_build(url, patch, branch, treeurl, token): click.secho(response.json(), fg="green") -def load_toml(settings): - with open(settings) as fp: - config = toml.load(fp) - return config - - @click.command(help="Test a patch or a mbox file") @click.option( "--repository", From ee9e7bed80c429d99bbba3eab6a9c47b5d17690a Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Wed, 11 Sep 2024 17:11:33 +0300 Subject: [PATCH 3/3] feat(settings): Make parameter --settings global As we use same settings file for all subcommands it make sense to make it global, parse in the beginning, and pass to subcommands already parsed result. Signed-off-by: Denys Fedoryshchenko --- kci-dev/kci-dev.py | 6 +++++- kci-dev/subcommands/commit.py | 8 +++----- kci-dev/subcommands/patch.py | 8 +++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/kci-dev/kci-dev.py b/kci-dev/kci-dev.py index 3663edc..1e2f09a 100755 --- a/kci-dev/kci-dev.py +++ b/kci-dev/kci-dev.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import click +from libs.common import * from subcommands import commit, patch @@ -9,7 +10,10 @@ 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.0.1", prog_name="kci-dev") -def cli(): +@click.option("--settings", default=".kci-dev.toml", help="path of toml setting file") +@click.pass_context +def cli(ctx, settings): + ctx.obj = {"CFG": load_toml(settings)} pass diff --git a/kci-dev/subcommands/commit.py b/kci-dev/subcommands/commit.py index 25c1cbf..911a4cc 100644 --- a/kci-dev/subcommands/commit.py +++ b/kci-dev/subcommands/commit.py @@ -8,8 +8,6 @@ import toml from git import Repo -from libs.common import * - def api_connection(host): click.secho("api connect: " + host, fg="green") @@ -61,9 +59,9 @@ def send_build(url, patch, branch, treeurl, token): default=".", help="define the directory of the local tree with local changes", ) -@click.option("--settings", default=".kci-dev.toml", help="path of toml setting file") -def commit(repository, branch, private, path, settings): - config = load_toml(settings) +@click.pass_context +def commit(ctx, repository, branch, private, path): + config = ctx.obj.get("CFG") url = api_connection(config["connection"]["host"]) diff = find_diff(path, branch, repository) send_build(url, diff, branch, repository, config["connection"]["token"]) diff --git a/kci-dev/subcommands/patch.py b/kci-dev/subcommands/patch.py index fa77b6f..1b6c7c2 100644 --- a/kci-dev/subcommands/patch.py +++ b/kci-dev/subcommands/patch.py @@ -8,8 +8,6 @@ import toml from git import Repo -from libs.common import * - def api_connection(host): click.secho("api connect: " + host, fg="green") @@ -47,9 +45,9 @@ def send_build(url, patch, branch, treeurl, token): help="define if the test results will be published", ) @click.option("--patch", required=True, help="mbox or patch file path") -@click.option("--settings", default=".kci-dev.toml", help="path of toml setting file") -def patch(repository, branch, private, patch, settings): - config = load_toml(settings) +@click.pass_context +def patch(ctx, repository, branch, private, patch): + config = ctx.obj.get("CFG") url = api_connection(config["connection"]["host"]) patch = open(patch, "rb") send_build(url, patch, branch, repository, config["connection"]["token"])