fix: 1、修复基于 `Python` 标准库`difflib` 做 `commit` 文件对比时,输出原始数据错误的问题;2、尝试进一步演进remotectl模块的功能,以适应域管的用例需求;

Description:

Log:
This commit is contained in:
mikigo 2024-03-20 21:16:36 +08:00
parent ade32b3326
commit c46db0d4ac
4 changed files with 24 additions and 30 deletions

View File

@ -1,10 +1,11 @@
# 版本更新记录
## 2.5.1dev
## 2.5.2dev
**Fix**
- 修复统计用例和方法数量功能在子项目为 `gitlab` 时,无法获取到 `commit` 详细记录的问题;[@mikigo](https://github.com/mikigo)
- 修复基于 `Python` 标准库`difflib` 做 `commit` 文件对比时,输出原始数据错误的问题;[@mikigo](https://github.com/mikigo)
## 2.5.12024/03/14

View File

@ -5,7 +5,6 @@
import os
import json
from copy import deepcopy
from difflib import unified_diff
from datetime import datetime
from setting import conf
@ -61,20 +60,7 @@ class CodeStatistics(Commit):
for filepath in git_files:
filename = filepath.split("/")[-1]
print("filepath:", filepath, "\n")
start_code = (
os.popen(f"cd {self.repo_path}/;git show {start_commit_id}:{filepath}")
.read()
.splitlines()
or ""
)
end_code = (
os.popen(f"cd {self.repo_path}/;git show {end_commit_id}:{filepath}")
.read()
.splitlines()
or ""
)
dif_gen = unified_diff(start_code, end_code, fromfile="start", tofile="end")
dif_txt = "\n".join(dif_gen)
dif_txt = os.popen(f"cd {self.repo_path}/;git diff {start_commit_id}..{end_commit_id} {filepath}").read()
print("=" * 100)
# case
if filename.startswith("test_"):
@ -236,10 +222,10 @@ class CodeStatistics(Commit):
if __name__ == "__main__":
app_name = "apps/autotest_deepin_downloader"
app_name = "apps/autotest_public"
CodeStatistics(
app_name=app_name,
branch="master",
startdate="2024-02-25",
startdate="2024-03-04",
# enddate="2024-02-23",
).codex()

View File

View File

@ -1,17 +1,17 @@
#!/usr/bin/env python3
# _*_ coding:utf-8 _*_
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
# SPDX-License-Identifier: GPL-2.0-only
import functools
# SPDX-License-Identifier: GPL-2.0-only
import os
import sys
import time
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from os.path import dirname
from os.path import basename
from setting import conf
sys.path.append(dirname(dirname(dirname(os.path.abspath(__file__)))))
try:
import zerorpc
@ -21,22 +21,26 @@ except ImportError:
import zerorpc
def _context_manager(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
tool_status = os.popen(
f'''sshpass -p '{conf.PASSWORD}' ssh {kwargs['user']}@{kwargs['ip']} "ps -aux | grep remote_mousekey | grep -v grep"'''
f'''sshpass -p '{conf.PASSWORD}' ssh {kwargs['user']}@{kwargs['ip']} "ps -aux | grep {basename(__file__)} | grep -v grep"'''
).read()
if not tool_status:
client_project_path = "/".join(conf.ROOT_DIR.split("/")[3:])
sudo = f"echo '{conf.PASSWORD}' | sudo -S"
if "StrictHostKeyChecking no" not in os.popen("cat /etc/ssh/ssh_config").read():
os.system(
f'{sudo} sed -i "s/# StrictHostKeyChecking ask/ StrictHostKeyChecking no/g" /etc/ssh/ssh_config'
)
if "/home/" not in conf.ROOT_DIR:
raise EnvironmentError
client_project_path = "/".join(conf.ROOT_DIR.split("/")[3:])
os.system(
f'''sshpass -p '{conf.PASSWORD}' ssh {kwargs['user']}@{kwargs['ip']} "mkdir -p ~/{client_project_path}"''')
exclude = ""
@ -63,13 +67,13 @@ def _context_manager(func):
)
os.system(
f"sshpass -p '{conf.PASSWORD}' ssh {kwargs['user']}@{kwargs['ip']} "
f'"cd ~/{client_project_path}/;'
f'"cd ~/{client_project_path}/ && '
f'bash env.sh"'
)
_cmd = (
f"nohup sshpass -p '{conf.PASSWORD}' ssh {kwargs['user']}@{kwargs['ip']} "
f'"cd ~/{client_project_path}/src/;'
f'pipenv run python remotectl.py" > /tmp/remote_result.log 2>&1 &'
f'"cd ~/{client_project_path}/src/remotectl/ && '
f'pipenv run python {basename(__file__)}" > /tmp/{basename(__file__)}.log 2>&1 &'
)
print(_cmd)
res = os.popen(_cmd).read()
@ -81,15 +85,18 @@ def _context_manager(func):
@_context_manager
def remotectl(user, ip):
def remote_dogtail_ctl(user=None, ip=None, password=None, app_name=None, desc=None, **kwargs):
r = zerorpc.Client(timeout=50, heartbeat=None)
r.connect(f"tcp://{ip}:4242")
return r
if __name__ == '__main__':
from src import Src
from os import environ
from setting import conf
environ["XAUTHORITY"] = f"/home/{conf.USERNAME}/.Xauthority"
from src.dogtail_utils import DogtailUtils
server = zerorpc.Server(Src())
server = zerorpc.Server(DogtailUtils())
server.bind("tcp://0.0.0.0:4242")
server.run()