Merge branch 'linuxdeepin:master' into master
This commit is contained in:
commit
2b219d8f2d
11
RELEASE.md
11
RELEASE.md
|
@ -1,10 +1,17 @@
|
|||
# 版本更新记录
|
||||
|
||||
## 2.5.0(dev)
|
||||
## 2.5.1(dev)
|
||||
|
||||
**New**
|
||||
|
||||
- `startapp` 初始化工程新增 `.gitignore` 文件;[@mikigo](https://github.com/mikigo)
|
||||
- `startapp` 初始化应用新增 2 条示例用例和一个方法;[issues #46](https://github.com/linuxdeepin/deepin-autotest-framework/issues/46) by [@mikigo](https://github.com/mikigo)
|
||||
- 新增子命令 `youqu manage.py git` 可用于拉取 git 仓库代码到 apps 目录下,支持统计分析仓库新增修复的用例或方法数量;[issues #40](https://github.com/linuxdeepin/deepin-autotest-framework/issues/40) by [@mikigo](https://github.com/mikigo)
|
||||
|
||||
## 2.5.0(2024/03/04)
|
||||
|
||||
**New**
|
||||
|
||||
- `startapp` 初始化工程新增 `.gitignore` 文件;[issues #43](https://github.com/linuxdeepin/deepin-autotest-framework/issues/43) by [@mikigo](https://github.com/mikigo)
|
||||
|
||||
**Fix**
|
||||
|
||||
|
|
16
manage.py
16
manage.py
|
@ -89,6 +89,8 @@ class Manage:
|
|||
url=None,
|
||||
commit1=None,
|
||||
commit2=None,
|
||||
startdate=None,
|
||||
enddate=None,
|
||||
git_user=None,
|
||||
git_password=None,
|
||||
depth=None,
|
||||
|
@ -140,6 +142,8 @@ class Manage:
|
|||
self.default_url = url
|
||||
self.default_commit1 = commit1
|
||||
self.default_commit2 = commit2
|
||||
self.default_startdate = startdate
|
||||
self.default_enddate = enddate
|
||||
self.default_git_user = git_user
|
||||
self.default_git_password = git_password
|
||||
self.default_depth = depth
|
||||
|
@ -498,7 +502,7 @@ class Manage:
|
|||
)
|
||||
|
||||
def git_control(self, parser=None, sub_parser_csv=None):
|
||||
"""csv相关功能命令参数"""
|
||||
"""git相关功能命令参数"""
|
||||
sub_parser_csv.add_argument(
|
||||
"-a", "--app", default="",
|
||||
help="应用名称:apps/autotest_deepin_music 或 autotest_deepin_music"
|
||||
|
@ -524,6 +528,12 @@ class Manage:
|
|||
sub_parser_csv.add_argument(
|
||||
"-c2", "--commit2", default="", help="commit2"
|
||||
)
|
||||
sub_parser_csv.add_argument(
|
||||
"-s", "--startdate", default="", help="统计开始时间"
|
||||
)
|
||||
sub_parser_csv.add_argument(
|
||||
"-e", "--enddate", default="", help="统计结束时间"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
git_kwargs = {
|
||||
Args.app_name.value: args.app or self.default_app,
|
||||
|
@ -534,6 +544,8 @@ class Manage:
|
|||
Args.depth.value: args.depth or self.default_depth,
|
||||
Args.commit1.value: args.commit1 or self.default_commit1,
|
||||
Args.commit2.value: args.commit2 or self.default_commit2,
|
||||
Args.startdate.value: args.startdate or self.default_startdate,
|
||||
Args.enddate.value: args.enddate or self.default_enddate,
|
||||
}
|
||||
|
||||
from src.git.check import check_git_installed
|
||||
|
@ -557,6 +569,8 @@ class Manage:
|
|||
git_kwargs.get(Args.app_name.value),
|
||||
git_kwargs.get(Args.commit1.value),
|
||||
git_kwargs.get(Args.commit2.value),
|
||||
git_kwargs.get(Args.startdate.value),
|
||||
git_kwargs.get(Args.enddate.value),
|
||||
]
|
||||
):
|
||||
from src.git.code_statistics import CodeStatistics
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
##from apps.${APP_NAME}.case.base_case import BaseCase
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env python3
|
||||
# _*_ coding:utf-8 _*_
|
||||
"""
|
||||
:Author:${USER}
|
||||
:Date :${DATE} ${TIME}
|
||||
"""
|
||||
##from apps.${APP_NAME}.case import BaseCase
|
||||
##from apps.${APP_NAME}.widget import ${AppName}Widget
|
||||
|
||||
##class TestMyCase(BaseCase):
|
||||
|
||||
## def test_mycase_001(self):
|
||||
## """this is my test case"""
|
||||
## # 用例步骤,调用方法层封装好的方法进行操作
|
||||
## ${AppName}Widget().click_xxx_by_attr()
|
||||
## # 在关键节点进行断言
|
||||
## self.assert_true(True)
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env python3
|
||||
# _*_ coding:utf-8 _*_
|
||||
"""
|
||||
:Author:${USER}
|
||||
:Date :${DATE} ${TIME}
|
||||
"""
|
||||
##from apps.${APP_NAME}.case import BaseCase
|
||||
##from apps.${APP_NAME}.widget import ${AppName}Widget
|
||||
##from src import sleep
|
||||
|
||||
##class TestMyCase(BaseCase):
|
||||
|
||||
## def test_mycase_002(self):
|
||||
## """快捷键 ctrl + alt + t 启动终端"""
|
||||
## # 用例步骤,调用方法层封装好的方法进行操作
|
||||
## ${AppName}Widget.ctrl_alt_t()
|
||||
## # 在关键节点进行断言
|
||||
## # 等待 2 秒,判断终端是否启动
|
||||
## sleep(2)
|
||||
## self.assert_process_status(True, "deepin-terminal")
|
|
@ -1 +1,3 @@
|
|||
${FIXEDCSVTITLE}
|
||||
001,
|
||||
002,
|
|
@ -12,3 +12,7 @@
|
|||
##@log
|
||||
##class ${AppName}Widget(BaseWidget):
|
||||
## """应用方法主类"""
|
||||
|
||||
## def click_xxx_by_attr(self):
|
||||
## """click xxx button by attribute"""
|
||||
## self.dog.find_element_by_attr("xxx").click()
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
##from apps.${APP_NAME}.widget.${app_name}_widget import ${AppName}Widget
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
##class BaseWidget(Src):
|
||||
## """应用的方法基类"""
|
||||
## # 注意这里需要修改为应用的包名
|
||||
## APP_NAME = "${APP-NAME}"
|
||||
## DESC = "/usr/bin/${APP-NAME}"
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
import os
|
||||
import sys
|
||||
from setting import conf
|
||||
|
||||
|
||||
def check_git_installed():
|
||||
if not os.popen("git --version").read().startswith("git version"):
|
||||
print("git 没有安装,我们将尝试安装")
|
||||
|
|
|
@ -7,12 +7,12 @@ from setting import conf
|
|||
|
||||
|
||||
def sslclone(
|
||||
url: str = None,
|
||||
user: str = None,
|
||||
password: str = None,
|
||||
branch: str = None,
|
||||
depth: [str, int] = None,
|
||||
**kwargs
|
||||
url: str = None,
|
||||
user: str = None,
|
||||
password: str = None,
|
||||
branch: str = None,
|
||||
depth: [str, int] = None,
|
||||
**kwargs,
|
||||
):
|
||||
os.system(
|
||||
f"cd {conf.ROOT_DIR}/src/utils && "
|
||||
|
@ -20,12 +20,7 @@ def sslclone(
|
|||
)
|
||||
|
||||
|
||||
def clone(
|
||||
url: str = None,
|
||||
branch: str = "",
|
||||
depth: [str, int] = "",
|
||||
**kwargs
|
||||
):
|
||||
def clone(url: str = None, branch: str = "", depth: [str, int] = "", **kwargs):
|
||||
os.system(
|
||||
f"cd {conf.APPS_PATH} && git clone {url} "
|
||||
f"{f'-b {branch}' if branch else ''} {f'--depth {depth}' if depth else ''}"
|
||||
|
|
|
@ -4,30 +4,49 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
import os
|
||||
import json
|
||||
|
||||
from setting import conf
|
||||
from difflib import unified_diff
|
||||
|
||||
from setting import conf
|
||||
from src.rtk._base import transform_app_name
|
||||
from src.git.commit import Commit
|
||||
|
||||
|
||||
class CodeStatistics:
|
||||
class CodeStatistics(Commit):
|
||||
__author__ = "mikigo<huangmingqiang@uniontech.com>"
|
||||
|
||||
def __init__(self, app_name: str, commit_new: str, commit_old: str, **kwargs):
|
||||
def __init__(
|
||||
self,
|
||||
app_name: str,
|
||||
commit1: str = None,
|
||||
commit2: str = None,
|
||||
startdate: str = None,
|
||||
enddate: str = None,
|
||||
**kwargs,
|
||||
):
|
||||
if (commit1 or commit2) and startdate:
|
||||
raise ValueError("commitid 和 startdate是两种不同的方式,不能同时使用")
|
||||
if (commit1 and commit2 is None) or (commit1 is None and commit2):
|
||||
raise ValueError("commit1 和 commit2 两个参数必须同时传入")
|
||||
self.app_name = transform_app_name(app_name)
|
||||
self.repo_path = f"{conf.APPS_PATH}/{self.app_name}"
|
||||
self.commit_new = commit_new
|
||||
self.commit_old = commit_old
|
||||
self.commit1 = commit1
|
||||
self.commit2 = commit2
|
||||
if startdate:
|
||||
super().__init__(app_name, startdate=startdate, enddate=enddate)
|
||||
commitids = self.commit_id()
|
||||
if isinstance(commitids, tuple):
|
||||
self.commit1, self.commit2 = commitids
|
||||
self.ignore_txt = ["from", "import", ""]
|
||||
|
||||
for i in range(100):
|
||||
self.ignore_txt.append(" " * i + "#")
|
||||
|
||||
self._debug = []
|
||||
|
||||
def get_git_files(self):
|
||||
diffs = os.popen(f"cd {self.repo_path};git diff {self.commit_old} {self.commit_new}").read().split("\n")
|
||||
diffs = (
|
||||
os.popen(f"cd {self.repo_path};git diff {self.commit2} {self.commit1}")
|
||||
.read()
|
||||
.split("\n")
|
||||
)
|
||||
git_files = []
|
||||
file_info = {}
|
||||
for diff in diffs:
|
||||
|
@ -45,6 +64,8 @@ class CodeStatistics:
|
|||
return git_files
|
||||
|
||||
def compare_files(self):
|
||||
_fix_debug = []
|
||||
_new_debug = []
|
||||
new_test_case_num = 0
|
||||
del_test_case_num = 0
|
||||
fix_test_case_num = 0
|
||||
|
@ -53,16 +74,26 @@ class CodeStatistics:
|
|||
fix_method_num = 0
|
||||
git_files = self.get_git_files()
|
||||
for git_file in git_files:
|
||||
filepath = git_file.get("file").split(" ")[-1].strip('b/')
|
||||
filepath = git_file.get("file").split(" ")[-1].strip("b/")
|
||||
filename = filepath.split("/")[-1]
|
||||
|
||||
if not filename.endswith(".py"):
|
||||
print("===== ignoring:", filepath, "\n")
|
||||
print("===== ignored:", filepath, "\n")
|
||||
continue
|
||||
|
||||
print("filepath:", filepath, "\n")
|
||||
old_code = os.popen(f"cd {self.repo_path}/;git show {self.commit_old}:{filepath}").read().splitlines() or ""
|
||||
new_code = os.popen(f"cd {self.repo_path}/;git show {self.commit_new}:{filepath}").read().splitlines() or ""
|
||||
old_code = (
|
||||
os.popen(f"cd {self.repo_path}/;git show {self.commit2}:{filepath}")
|
||||
.read()
|
||||
.splitlines()
|
||||
or ""
|
||||
)
|
||||
new_code = (
|
||||
os.popen(f"cd {self.repo_path}/;git show {self.commit1}:{filepath}")
|
||||
.read()
|
||||
.splitlines()
|
||||
or ""
|
||||
)
|
||||
dif_gen = unified_diff(old_code, new_code)
|
||||
print("=" * 100)
|
||||
# case
|
||||
|
@ -84,9 +115,7 @@ class CodeStatistics:
|
|||
methods = []
|
||||
method_info = {}
|
||||
for line in dif_txt.splitlines():
|
||||
if line.startswith(
|
||||
("---", "+++", "@@", "@")
|
||||
):
|
||||
if line.startswith(("---", "+++", "@@", "@")):
|
||||
continue
|
||||
if "def " in line:
|
||||
if method_info:
|
||||
|
@ -109,13 +138,14 @@ class CodeStatistics:
|
|||
if content.startswith(("-", "+")):
|
||||
if content[1:].startswith(tuple(self.ignore_txt)):
|
||||
continue
|
||||
self._debug.append(method)
|
||||
_fix_debug.append(method)
|
||||
fix_method_num += 1
|
||||
break
|
||||
|
||||
# 正常出现的方法
|
||||
# 方法名称是+开头,直接视为新增方法
|
||||
elif method_name.startswith("+"):
|
||||
_new_debug.append(method)
|
||||
new_method_num += 1
|
||||
# 方法名称是-开头,直接视为删除方法
|
||||
elif method_name.startswith("-"):
|
||||
|
@ -124,7 +154,7 @@ class CodeStatistics:
|
|||
if method_content:
|
||||
for content in method_content:
|
||||
if content.startswith(("-", "+")):
|
||||
self._debug.append(method)
|
||||
_fix_debug.append(method)
|
||||
fix_method_num += 1
|
||||
break
|
||||
|
||||
|
@ -140,12 +170,24 @@ class CodeStatistics:
|
|||
|
||||
def write_result(self):
|
||||
res = self.compare_files()
|
||||
with open(os.path.join(conf.REPORT_PATH, f"{self.app_name}_git_compare_result.json"), "w", encoding="utf-8") as f:
|
||||
if not os.path.exists(conf.REPORT_PATH):
|
||||
os.makedirs(conf.REPORT_PATH)
|
||||
result_file = os.path.join(conf.REPORT_PATH, f"{self.app_name}_git_compare_result.json")
|
||||
with open(result_file, "w", encoding="utf-8") as f:
|
||||
f.write(json.dumps(res, ensure_ascii=False, indent=2))
|
||||
|
||||
with open(result_file, "r", encoding="utf-8") as f:
|
||||
print(f.read())
|
||||
|
||||
if __name__ == '__main__':
|
||||
repo = '/home/mikigo/github/deepin-autotest-framework/apps/autotest_deepin_downloader'
|
||||
commit_n = '059632e9e2dfc7fe580abefe3c51f15d8672d213'
|
||||
commit_o = 'c30572e113a2e90cf340426a8c16c44b7605bfd7'
|
||||
CodeStatistics(repo, commit_n, commit_o).write_result()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app_name = "apps/autotest_deepin_downloader"
|
||||
commit1 = "059632e9e2dfc7fe580abefe3c51f15d8672d213"
|
||||
commit2 = "c30572e113a2e90cf340426a8c16c44b7605bfd7"
|
||||
CodeStatistics(
|
||||
app_name=app_name,
|
||||
# commit1=commit1,
|
||||
# commit2=commit2,
|
||||
startdate="2024-02-25",
|
||||
enddate="2024-02-27",
|
||||
).write_result()
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env python3
|
||||
# _*_ coding:utf-8 _*_
|
||||
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
import os
|
||||
import re
|
||||
import locale
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from setting import conf
|
||||
from src.rtk._base import transform_app_name
|
||||
|
||||
locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
|
||||
|
||||
|
||||
class Commit:
|
||||
__author__ = "mikigo<huangmingqiang@uniontech.com>"
|
||||
|
||||
def __init__(self, app_name: str, startdate: str, enddate: str = None):
|
||||
self.app_name = transform_app_name(app_name)
|
||||
self.startdate = datetime.strptime(startdate, "%Y-%m-%d")
|
||||
self.enddate = (
|
||||
self.now_dt
|
||||
if enddate is None
|
||||
else datetime.strptime(enddate, "%Y-%m-%d") + timedelta(days=1)
|
||||
)
|
||||
|
||||
@property
|
||||
def now_dt(self):
|
||||
return datetime.strptime(datetime.now().strftime("%Y-%m-%d-%H-%M"), "%Y-%m-%d-%H-%M")
|
||||
|
||||
@property
|
||||
def git_logs(self) -> list:
|
||||
git_logs = re.findall(
|
||||
r"commit (.*?)\nAuthor: (.*?)\nDate: (.*?)\n",
|
||||
os.popen(f"cd {conf.APPS_PATH}/{self.app_name} && git log").read(),
|
||||
)
|
||||
return git_logs
|
||||
|
||||
def commit_id(self):
|
||||
start_commit_id = None
|
||||
start_commit_date = None
|
||||
end_commit_id = None
|
||||
end_commit_date = None
|
||||
for commit, author, _time_str in self.git_logs:
|
||||
time_str = " ".join(_time_str.split(" ")[:-1])
|
||||
git_dt = datetime.strptime(time_str, "%a %b %d %H:%M:%S %Y")
|
||||
|
||||
if self.startdate <= git_dt <= self.enddate:
|
||||
if end_commit_id is None:
|
||||
end_commit_id = commit
|
||||
end_commit_date = git_dt
|
||||
else:
|
||||
if end_commit_id and start_commit_id is None:
|
||||
start_commit_id = commit
|
||||
start_commit_date = git_dt
|
||||
|
||||
if start_commit_id and end_commit_id:
|
||||
return end_commit_id, start_commit_id
|
||||
|
||||
raise ValueError(f"{self.startdate} 到 {self.enddate} 没有获取到有效的 commit id")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Commit(
|
||||
app_name="apps/autotest_deepin_downloader", startdate="2024-02-25", enddate="2024-02-26"
|
||||
).commit_id()
|
|
@ -73,6 +73,8 @@ class Args(Enum):
|
|||
url = "url"
|
||||
commit1 = "commit1"
|
||||
commit2 = "commit2"
|
||||
startdate = "startdate"
|
||||
enddate = "enddate"
|
||||
user = "user"
|
||||
password = "password"
|
||||
depth = "depth"
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#!/bin/bash
|
||||
# _*_ coding:utf-8 _*_
|
||||
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
CODE_PATH=$1
|
||||
URL=$2
|
||||
|
|
Loading…
Reference in New Issue