Skip to content

Commit e3e5546

Browse files
committed
use fire
1 parent 40e3807 commit e3e5546

1 file changed

Lines changed: 19 additions & 24 deletions

File tree

fuzz/clean_fuzz_dir.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
11
#!/usr/bin/env python3
22
import os
33
import shutil
4-
import argparse
4+
import fire
55

6-
# Default root directory
7-
DEFAULT_ROOT_DIR = "/home/jiayiguo/FuzzAug/fuzz/oss-fuzz/projects"
6+
def clean_project_dirs(root_dir="/home/jiayiguo/FuzzAug/fuzz/oss-fuzz/projects"):
7+
"""
8+
清理 oss-fuzz 项目目录下的 fuzz_inputs 和 tests-gen 文件夹
89
9-
def clean_project_dirs(root_dir):
10+
Args:
11+
root_dir (str): 项目的根目录路径
12+
"""
1013
removed_files = 0
1114
removed_dirs = 0
1215

13-
# Walk through the root directory
1416
for project in os.listdir(root_dir):
1517
project_path = os.path.join(root_dir, project)
1618
if not os.path.isdir(project_path):
1719
continue
1820

19-
# Delete fuzz_inputs directories
21+
# 删除 fuzz_inputs 文件夹
2022
fuzz_inputs_path = os.path.join(project_path, "fuzz_inputs")
2123
if os.path.isdir(fuzz_inputs_path):
2224
shutil.rmtree(fuzz_inputs_path)
2325
print(f"🗑️ Removed dir: {fuzz_inputs_path}")
2426
removed_dirs += 1
2527

26-
# Delete tests-gen directories
28+
# 删除 tests-gen 文件夹
2729
tests_gen_path = os.path.join(project_path, "tests-gen")
2830
if os.path.isdir(tests_gen_path):
2931
shutil.rmtree(tests_gen_path)
3032
print(f"🗑️ Removed dir: {tests_gen_path}")
3133
removed_dirs += 1
3234

33-
print(f"\n✅ Done. Removed {removed_dirs} directories in total.")
35+
# 如果需要删除 .inputs.py 文件,取消注释以下代码
36+
# for fname in os.listdir(project_path):
37+
# if fname.endswith(".inputs.py"):
38+
# file_path = os.path.join(project_path, fname)
39+
# os.remove(file_path)
40+
# print(f"🗑️ Removed file: {file_path}")
41+
# removed_files += 1
42+
43+
print(f"\n✅ Done. Removed {removed_files} files and {removed_dirs} directories.")
3444

3545
if __name__ == "__main__":
36-
# Set up command line arguments
37-
parser = argparse.ArgumentParser(
38-
description='Clean project directories by removing fuzz_inputs and tests-gen folders',
39-
formatter_class=argparse.ArgumentDefaultsHelpFormatter
40-
)
41-
parser.add_argument('--root_dir', default=DEFAULT_ROOT_DIR,
42-
help='Root directory containing project folders')
43-
args = parser.parse_args()
44-
45-
# Validate the root directory exists
46-
if not os.path.isdir(args.root_dir):
47-
print(f"❌ Error: Specified root directory does not exist: {args.root_dir}")
48-
exit(1)
49-
50-
print(f"Cleaning projects in: {args.root_dir}")
51-
clean_project_dirs(args.root_dir)
46+
fire.Fire(clean_project_dirs)

0 commit comments

Comments
 (0)