From 7a134b961444056dc153fe9816a42099239e1abb Mon Sep 17 00:00:00 2001 From: jingfelix Date: Sun, 13 Oct 2024 22:11:46 +0800 Subject: [PATCH] deps: remove unused deps Signed-off-by: jingfelix --- diff_with_gnu_patch.py | 155 +++++++++++++++++++++++++++++++++++++++++ pdm.lock | 13 +--- pyproject.toml | 1 - requirements.txt | 1 - 4 files changed, 156 insertions(+), 14 deletions(-) create mode 100644 diff_with_gnu_patch.py diff --git a/diff_with_gnu_patch.py b/diff_with_gnu_patch.py new file mode 100644 index 0000000..9b0bb5c --- /dev/null +++ b/diff_with_gnu_patch.py @@ -0,0 +1,155 @@ +import logging +import os +import subprocess +from subprocess import CompletedProcess + +from rich.logging import RichHandler + +logging.basicConfig( + level=logging.INFO, format="%(message)s", datefmt="[%X]", handlers=[RichHandler()] +) + +LOG_DIR = "/home/laboratory/workspace/repos/Patche/test_logs" +PATCHES_DIR = "/home/laboratory/workspace/archive/patches" +KERNEL_DIR = "/home/laboratory/workspace/exps/ppatch/linux-stable" + +logger = logging.getLogger(__name__) + + +def test_ppatch_apply(exec: str, poc_index: str) -> int: + + res: CompletedProcess = None + + if exec == "ppatch": + # ppatch apply -R -F 3 ~/workspace/archive/patches/poc_1005.patch + res = subprocess.run( + [ + f"patche", + "apply", + "-R", + "-F", + "3", + f"{PATCHES_DIR}/poc_{poc_index}.patch", + ], + check=False, + capture_output=True, + ) + + elif exec == "patch": + # patch -R -F 3 -p 1 -f -i ~/workspace/archive/patches/poc_1005.patch && git diff > ../poc_1005.diff && gclean + res = subprocess.run( + [ + f"patch", + "-R", + "-F", + "3", + "-p", + "1", + "-f", + "-i", + f"{PATCHES_DIR}/poc_{poc_index}.patch", + ], + check=False, + capture_output=True, + ) + else: + logger.error("Unknown executable") + return 2 + + # 将 stdout 和 stderr 输出到文件中 + with open(f"{LOG_DIR}/{exec}_apply_{poc_index}_stdout.log", "w") as f: + f.write(res.stdout.decode("utf-8", errors="ignore")) + + with open(f"{LOG_DIR}/{exec}_apply_{poc_index}_stderr.log", "w") as f: + f.write(res.stderr.decode("utf-8", errors="ignore")) + + if res.returncode != 0: + logger.error(f"{exec} apply poc_{poc_index} failed") + # git restore --stage . && git clean -f -q && git restore . + # subprocess.run(["git", "clean", "-f", "-q"], check=False) + subprocess.run(["git", "restore", "."], check=False) + + return 1 + else: + # 将 git diff 信息输出到文件中 + res = subprocess.run(["git", "diff"], check=True, stdout=subprocess.PIPE) + with open(f"{LOG_DIR}/{exec}_apply_{poc_index}_diff.log", "w") as f: + f.write(res.stdout.decode("utf-8", errors="ignore")) + + # subprocess.run(["git", "clean", "-f", "-q"], check=False) + subprocess.run(["git", "restore", "."], check=False) + + return 0 + + +if __name__ == "__main__": + + # 切换目录到 linux-stable + os.chdir("/home/laboratory/workspace/exps/ppatch/linux-stable") + + same_poc_list = [] + diff_poc_list = [] + strange_poc_list = [] + + poc_index_list = [] + + for file in os.listdir(PATCHES_DIR): + + if file.endswith(".patch"): + poc_index = file.split("_")[1].split(".")[0] + poc_index_list.append(poc_index) + + else: + continue + + # 使用排序后的 poc_index_list + poc_index_list.sort(key=lambda x: int(x)) + + for poc_index in poc_index_list: + + ppatch_ret = test_ppatch_apply("ppatch", poc_index) + patch_ret = test_ppatch_apply("patch", poc_index) + + if not ppatch_ret and not patch_ret: + # 测试两者的 diff 是否一致 + res = subprocess.run( + [ + "diff", + f"{LOG_DIR}/ppatch_apply_{poc_index}_diff.log", + f"{LOG_DIR}/patch_apply_{poc_index}_diff.log", + ], + check=False, + capture_output=True, + ) + + if res.returncode != 0: + diff_poc_list.append(poc_index) + logger.warning(f"poc_{poc_index} diff is different") + else: + same_poc_list.append(poc_index) + + continue + + logger.info(f"ppatch_ret: {ppatch_ret}, patch_ret: {patch_ret}") + + if ppatch_ret and not patch_ret: + diff_poc_list.append(poc_index) + logger.warning(f"poc_{poc_index} diff is different: ppatch failed") + + elif (not ppatch_ret) and patch_ret: + diff_poc_list.append(poc_index) + logger.warning(f"poc_{poc_index} diff is different: patch failed") + + else: + strange_poc_list.append(poc_index) + logger.warning(f"poc_{poc_index} diff is strange") + + # 分别将 same_poc_list, diff_poc_list, strange_poc_list 写入文件 + with open(f"{LOG_DIR}/same_poc_list.log", "w") as f: + f.write("\n".join(same_poc_list)) + + with open(f"{LOG_DIR}/diff_poc_list.log", "w") as f: + f.write("\n".join(diff_poc_list)) + + with open(f"{LOG_DIR}/strange_poc_list.log", "w") as f: + f.write("\n".join(strange_poc_list)) diff --git a/pdm.lock b/pdm.lock index 62d1a91..b65f8a8 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:6555696240de046378cde17536e2701e6f633824f840d48863c2781c5abaff22" +content_hash = "sha256:56a8358de351a7dfd84d1df557b731add72277efa46eeccdfa67496b71595e63" [[metadata.targets]] requires_python = ">=3.10" @@ -251,17 +251,6 @@ files = [ {file = "shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de"}, ] -[[package]] -name = "structlog" -version = "24.4.0" -requires_python = ">=3.8" -summary = "Structured Logging for Python" -groups = ["default"] -files = [ - {file = "structlog-24.4.0-py3-none-any.whl", hash = "sha256:597f61e80a91cc0749a9fd2a098ed76715a1c8a01f73e336b746504d1aad7610"}, - {file = "structlog-24.4.0.tar.gz", hash = "sha256:b27bfecede327a6d2da5fbc96bd859f114ecc398a6389d664f62085ee7ae6fc4"}, -] - [[package]] name = "typer" version = "0.12.3" diff --git a/pyproject.toml b/pyproject.toml index fef76ff..4ea4823 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,6 @@ dependencies = [ "pydantic-settings>=2.2.1", "cscopy>=0.0.1", "whatthepatch-pydantic==1.0.6a2", - "structlog>=24.2.0", ] requires-python = ">=3.10" readme = "README.md" diff --git a/requirements.txt b/requirements.txt index 8268d1f..0b7a41a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,6 @@ pygments==2.18.0 python-dotenv==1.0.1 rich==13.7.1 shellingham==1.5.4 -structlog==24.4.0 typer==0.12.3 typer[all]==0.12.3 typing-extensions==4.12.2