Skip to content

Commit 6ef73f3

Browse files
committed
✨指定result.json保存到RESULT_DIR环境变量指定的目录下
1 parent d8484a2 commit 6ef73f3

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- 输出:将判断结果输出到`check_result.json`文件中,文件内容为`{"usable": true}``{"usable": false}`
1010
- `run_cmd`
1111
- 功能:扫描代码,执行自定义检查器逻辑。
12-
- 输出:按照指定格式,输出结果到`result.json`文件中,文件格式:
12+
- 输出:按照指定格式,输出结果到`RESULT_DIR`环境变量指定的目录下的`result.json`文件中,文件格式:
1313
```
1414
[
1515
{
@@ -38,5 +38,6 @@
3838
## 本地调试步骤
3939
4040
1. 修改`test.sh`中的`SOURCE_DIR`环境变量为需要扫描的代码目录。
41-
2. 按需修改`task_request.json`文件中`task_params`字段的内容,将工具代码中用到的字段替换为实际值。
42-
3. 命令行`cd`到项目根目录,执行`test.sh`脚本:`bash test.sh`。
41+
2. 修改`test.sh`中的`RESULT_DIR`环境变量,指定某个本地目录为结果保存目录。
42+
3. 按需修改`task_request.json`文件中`task_params`字段的内容,将工具代码中用到的字段替换为实际值。
43+
4. 命令行`cd`到项目根目录,执行`test.sh`脚本:`bash test.sh`。

src/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,10 @@ def __scan(self):
216216
}
217217
]
218218

219-
# 输出结果到指定的json文件
220-
with open("result.json", "w") as fp:
219+
# 输出结果json文件到RESULT_DIR指定的目录下
220+
result_dir = os.getenv("RESULT_DIR", os.getcwd())
221+
result_path = os.path.join(result_dir, "result.json")
222+
with open(result_path, "w") as fp:
221223
json.dump(result, fp, indent=2)
222224

223225
def __check_usable(self):

test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export SOURCE_DIR="/xxx/xxx"
2+
export RESULT_DIR="/xxx/xxx"
23
export TASK_REQUEST="task_request.json"
34

45
echo "- * - * - * - * - * - * - * - * - * - * - * - * -* -* -* -* -* -* -"

0 commit comments

Comments
 (0)