diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01a42a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.kci-dev.toml +__pycache__/ +poetry.lock diff --git a/.kci-dev.toml.example b/.kci-dev.toml.example new file mode 100644 index 0000000..b89ba3d --- /dev/null +++ b/.kci-dev.toml.example @@ -0,0 +1,3 @@ +[connection] +host="https://127.0.0.1" +token="example" diff --git a/README.md b/README.md new file mode 100644 index 0000000..266dafc --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# kci-dev + +Stand alone tool for Linux Kernel developers and maintainers that can test local Linux Kernel commits or patch (*.mbox, *.patch) on a enabled KernelCI server + +## Quickstart + +```sh +poetry install +poetry run kci-dev +``` + +or + +```sh +python kci-dev/kci-dev.py +``` + diff --git a/kci-dev/__init__.py b/kci-dev/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kci-dev/kci-dev.py b/kci-dev/kci-dev.py new file mode 100755 index 0000000..1ea1c65 --- /dev/null +++ b/kci-dev/kci-dev.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import click +from subcommands import commit +from subcommands import patch + + +@click.group( + 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(): + pass + + +def run(): + cli.add_command(commit.commit) + cli.add_command(patch.patch) + cli() + + +if __name__ == "__main__": + run() diff --git a/kci-dev/subcommands/__init__.py b/kci-dev/subcommands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kci-dev/subcommands/commit.py b/kci-dev/subcommands/commit.py new file mode 100644 index 0000000..c3e2a7f --- /dev/null +++ b/kci-dev/subcommands/commit.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import click +import toml +import requests +import json +from git import Repo + + +def api_connection(host): + click.secho("api connect: " + host, fg="green") + return host + + +def find_diff(path, branch, repository): + repo = Repo(path) + assert not repo.bare + hcommit = repo.iter_commits("origin/master.." + branch) + commits = [] + for i in hcommit: + commits.append(repo.git.show(i)) + return commits + + +def send_build(url, patch, branch, treeurl, token): + headers = { + "Content-Type": "application/json; charset=utf-8", + "Authorization": "Bearer {}".format(token), + } + values = { + "treeurl": treeurl, + "branch": branch, + "commit": "example", + "kbuildname": "example", + "testname": "example", + } + response = requests.post(url, headers=headers, files={"patch": patch}, data=values) + click.secho(response.status_code, fg="green") + 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", + default="mainline", + help="define the kernel upstream repository where to test local changes", +) +@click.option("--branch", default="master", help="define the repository branch") +@click.option( + "--private", + default=False, + is_flag=True, + help="define if the test results will be published", +) +@click.option( + "--path", + 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) + url = api_connection(config["connection"]["host"]) + diff = find_diff(path, branch, repository) + send_build(url, diff, branch, repository, config["connection"]["token"]) + + +if __name__ == "__main__": + main_kcidev() diff --git a/kci-dev/subcommands/patch.py b/kci-dev/subcommands/patch.py new file mode 100644 index 0000000..1f81e9a --- /dev/null +++ b/kci-dev/subcommands/patch.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import click +import toml +import requests +import json +from git import Repo + + +def api_connection(host): + click.secho("api connect: " + host, fg="green") + return host + + +def send_build(url, patch, branch, treeurl, token): + headers = { + "Content-Type": "application/json; charset=utf-8", + "Authorization": "Bearer {}".format(token), + } + values = { + "treeurl": treeurl, + "branch": branch, + "commit": "example", + "kbuildname": "example", + "testname": "example", + } + response = requests.post(url, headers=headers, files={"patch": patch}, data=values) + click.secho(response.status_code, fg="green") + 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", + default="mainline", + help="define the kernel upstream repository where to test local changes", +) +@click.option("--branch", default="master", help="define the repository branch") +@click.option( + "--private", + default=False, + is_flag=True, + 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) + url = api_connection(config["connection"]["host"]) + patch = open(patch, "rb") + send_build(url, patch, branch, repository, config["connection"]["token"]) + + +if __name__ == "__main__": + main_kcidev() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..29d63a4 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,47 @@ +[tool.poetry] +name = "kci-dev" +version = "0.0.1" +description = "Stand alone tool for Linux Kernel developers and maintainers that can test local Linux Kernel changes on a enabled KernelCI server" +authors = ["Arisu Tachibana "] +license = "LGPL-2.1-or-later" +readme = "README.md" +packages = [ +{include = "kci-dev"}, +{include = "subcommands", from="kci-dev"}, +] +repository = "https://github.com/kernelci/kci-dev" +classifiers = [ + 'Development Status :: 1 - Planning', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'Operating System :: OS Independent', + 'Topic :: Software Development', + 'Topic :: Software Development :: Libraries', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy' + ] + +[tool.poetry.dependencies] +python = "^3.12" +click = "^8.1.7" +requests = "^2.32.3" +toml = "^0.10.2" +gitpython = "^3.1.43" + +[tool.poetry.scripts] +kci-dev = 'kci-dev.kci-dev:run' + +[tool.poetry.urls] +"Issue Tracker" = "https://github.com/kernelci/kci-dev/issues" + +[tool.poetry.group.ci.dependencies] +black = "^24.8.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"