diff --git a/test/scripts/auto_xts_test/get_resource/config.yaml b/test/scripts/auto_xts_test/get_resource/config.yaml deleted file mode 100644 index 392a034452314cabfc3bd78b87720e5f69cf8bae..0000000000000000000000000000000000000000 --- a/test/scripts/auto_xts_test/get_resource/config.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -url_dailybuilds : "http://ci.openharmony.cn/api/ci-backend/ci-portal/v1/dailybuilds" -headers : - 'Accept': 'application/json, text/plain, */*' - 'Accept-Encoding': 'gzip, deflate' - 'Accept-Language': 'zh-CN,zh;q=0.8' - 'Access-Control-Allow-Credentials': 'true' - 'Access-Control-Allow-Methods': 'POST, GET, PUT, OPTIONS, DELETE, PATCH' - 'Access-Control-Allow-Origin': '*' - 'Connection': 'keep-alive' - 'Content-Length': '216' - 'Content-Type': 'application/json;charset=UTF-8' - 'Cookie': '_frid=d54846f4e88e415587e14aed0e4a9d63;\ - __51vcke__JhI7USZ6OfAHQZUm=0af50c49-e1b6-5ca4-9356-a986a785be93;\ - __51vuft__JhI7USZ6OfAHQZUm=1684307559015;\ - _fr_ssid=c60810a1808f447b9f696d9534294dcb;\ - __51uvsct__JhI7USZ6OfAHQZUm=5;\ - __vtins__JhI7USZ6OfAHQZUm=%7B%22sid%22%3A%20%22972e7520-a952-52ff-b0f4-0c3ca53da01b%22%2C%20%22vd%22%3A%205%2C%20%22stt%22%3A%201947502%2C%20%22dr%22%3A%20409887%2C%20%22expires%22%3A%201684921552594%2C%20%22ct%22%3A%201684919752594%7D;\ - _fr_pvid=3a57d4c932eb4e10814323c8d3758b0d' - 'hide': 'false' - 'Host': 'ci.openharmony.cn' - 'Origin': 'http://ci.openharmony.cn' - 'Referer': 'http://ci.openharmony.cn/dailys/dailybuilds' - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64) \ - AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0\ - Safari/537.36 Edg/113.0.1774.50' -data: - 'branch': "master" - 'buildFailReason': "" - 'buildStatus': "success" - 'component': "dayu200" - 'deviceLevel': "" - 'endTime': "" - 'hardwareBoard': "" - 'pageNum': 1 - 'pageSize': 8 - 'projectName': "openharmony" - 'startTime': "" - 'testResult': "" -url_dayu200: - - "http://download.ci.openharmony.cn/version/Daily_Version/dayu200/" - - "/version-Daily_Version-dayu200-" - - "-dayu200.tar.gz" -url_tools : 'http://123.60.114.105:9999/RKDevTool.zip' -path_xts_pack : 'D:\\AutoXTSTest\\dayu200_xts.tar.gz' -path_xts_dir : 'D:\\AutoXTSTest\\dayu200_xts' -path_configfile : 'D:\\AutoXTSTest\\dayu200_xts\\suites\\acts\\config\\user_config.xml' -path_xts_report : 'D:\\AutoXTSTest\\dayu200_xts\\suites\\acts\\reports' \ No newline at end of file diff --git a/test/scripts/auto_xts_test/get_resource/get_tool.py b/test/scripts/auto_xts_test/get_resource/get_tool.py deleted file mode 100755 index 02c781bde7fdcd3ba549aa0a96130050fb548621..0000000000000000000000000000000000000000 --- a/test/scripts/auto_xts_test/get_resource/get_tool.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import json -import os -import stat -import zipfile - -import requests -from tqdm import tqdm -import yaml - - -def get_tool(url): - print(f"Getting RKDevTool from {url}") - r = requests.get(url, stream=True) - total = int(r.headers.get('content-length'), 0) - flags = os.O_WRONLY | os.O_CREAT - modes = stat.S_IWUSR | stat.S_IRUSR - - with os.fdopen(os.open(r".\RKDevTool.zip", flags, modes), "wb") as f, tqdm( - desc="RKDevTool.zip", - total=total, - unit='iB', - unit_scale=True, - unit_divisor=1024, - ) as bar: - for byte in r.iter_content(chunk_size=1024): - size = f.write(byte) - bar.update(size) - with zipfile.ZipFile(".\\RKDevTool.zip", 'r') as zfile: - zfile.extractall(path=".\\RKDevTool") - - -if __name__ == "__main__": - with open(r".\get_resource\config.yaml", 'r') as config_file: - data = yaml.safe_load(config_file.read()) - get_tool(data['url_tools']) \ No newline at end of file diff --git a/test/scripts/auto_xts_test/get_resource/spider.py b/test/scripts/auto_xts_test/get_resource/spider.py deleted file mode 100755 index 2c06247719915f64b2ff8b62600107235333a452..0000000000000000000000000000000000000000 --- a/test/scripts/auto_xts_test/get_resource/spider.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import json -import logging -import os -import stat -import tarfile -import xml.etree.ElementTree as ET - -import requests -from tqdm import tqdm -import yaml - - -def get_images_and_testcases(url, download_path, extract_path): - print(f"Get new image from {url},please wait!") - r = requests.get(url, stream=True) - total = int(r.headers.get('content-length'), 0) - flags = os.O_WRONLY | os.O_CREAT - modes = stat.S_IWUSR | stat.S_IRUSR - - with os.fdopen(os.open(download_path, flags, modes), "wb") as f, tqdm( - desc="dayu200_xts.tar.gz", - total=total, - unit='iB', - unit_scale=True, - unit_divisor=1024, - ) as bar: - for byte in r.iter_content(chunk_size=1024): - size = f.write(byte) - bar.update(size) - - print("extracrting file") - with tarfile.open(download_path, "r") as tar: - for member in tqdm(desc='dayu200_xts', iterable=tar.getmembers(), total=len(tar.getmembers())): - tar.extract(path=extract_path, member=member) - logging.basicConfig(filename="log.log", level='INFO') - logging.info(f'Downloading Success, url:{url}') - - -def get_url(url, headers, json_data, url_2): - response = requests.post(url, json=json_data, headers=headers) - json_obj = json.loads(response.text) - start_time = json_obj['result']['dailyBuildVos'][0]['buildStartTime'] - start_time = start_time[:8] + "_" + start_time[8:] - return url_2[0] + start_time + url_2[1] + start_time + url_2[2] - - -def change_port(xml_path, xml_dw="./environment/device/port"): - doc = ET.parse(xml_path) - root = doc.getroot() - port = root.find(xml_dw) - port.text = "8710" - doc.write(xml_path) - - -if __name__ == '__main__': - with open(r".\get_resource\config.yaml", 'r') as config_file: - data = yaml.safe_load(config_file.read()) - dest_url = get_url(data['url_dailybuilds'], data['headers'], data['data'], data['url_dayu200']) - get_images_and_testcases(dest_url, data['path_xts_pack'], data['path_xts_dir']) - change_port(data['path_configfile']) - \ No newline at end of file diff --git a/test/scripts/auto_xts_test/run.bat b/test/scripts/auto_xts_test/run.bat index f372bb6b7858a27b502f85e1e6d1264770ac8013..9d7591c4dff5665c4d27090ac42c442c06f4fa19 100755 --- a/test/scripts/auto_xts_test/run.bat +++ b/test/scripts/auto_xts_test/run.bat @@ -18,36 +18,14 @@ REM change to work directory cd /d %~dp0 REM log -echo "------------------------------------------------" >> log.log - -REM get tool -if not exist .\RKDevTool ( -python .\get_resource\get_tool.py -.\RKDevTool\DriverAssitant_v5.1.1\DriverAssitant_v5.1.1\DriverInstall.exe -del /q .\RKDevTool.zip -) -if not exist .\RKDevTool\RKDevTool.exe (goto ToolError) - -REM get image & XTS testcases -set var=D:\AutoXTSTest -if not exist %var% (md %var%) -rd /s /q %var%\dayu200_xts -python .\get_resource\spider.py -del /q %var%\dayu200_xts.tar.gz -if not exist %var%\dayu200_xts\suites (goto ResourceError) - -REM load image to rk3568 -hdc shell reboot bootloader -cd RKDevTool -python ..\autoburn.py -cd .. -for /f "tokens=*" %%i in ('hdc list targets') do (set target=%%i) -if "%var%"=="[Empty]" (goto BurnError) +echo "------------------------------------------------" >> log.txt REM run XTStest +set var=D:\AutoXTSTest timeout /t 15 hdc shell "power-shell setmode 602" hdc shell "hilog -Q pidoff" +cd /d %~dp0 for /f "tokens=1,2 delims==" %%i in (running_modules.txt) do ( if "%%i"=="modules" set value=%%j ) @@ -55,25 +33,10 @@ call %var%\dayu200_xts\suites\acts\run.bat run -l %value% REM get result cd /d %~dp0 -echo "Successfully excute script" >> log.log +echo "Successfully excute script" >> log.txt if exist result (rd /s /q result) md result -python get_result.py +python result.py ENDLOCAL exit -REM error process -: ToolError -echo "Error happens while getting tool" >> log.log -ENDLOCAL -exit - -: ResourceError -echo "Error happens while getting dailybuilds resource" >> log.log -ENDLOCAL -exit - -: BurnError -echo "Error happens while burnning images" >> log.log -ENDLOCAL -exit \ No newline at end of file diff --git a/test/scripts/download/__pycache__/utils.cpython-310.pyc b/test/scripts/download/__pycache__/utils.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9e335e6f39dac23298a147b344098cd87b0412c6 Binary files /dev/null and b/test/scripts/download/__pycache__/utils.cpython-310.pyc differ diff --git a/test/scripts/download/config.yaml b/test/scripts/download/config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7ff05211e9ec6ff23c8355ac3cd31db69201906a --- /dev/null +++ b/test/scripts/download/config.yaml @@ -0,0 +1,33 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# test env config +deveco_path: D:\complier\DevEco Studio +deveco_sdk_path: D:\enviorment\SDK\openHarmony_SDK +node_js_path: D:\enviorment\nodejs-huawei +RKdevtool_download_path : 'http://123.60.114.105:9999/RKDevTool.zip' +RKdevtool_output_path: './auto_xts_test/RKDevTool' +pictures_download_path: 'http://123.60.114.105:9999/pictures_reference.zip' +pictures_output_path: './sdk_test/pictures_reference' +download_path: D:\download +# image download list +download_list: + - sdk: + name: sdk + path: D:\enviorment\SDK\openHarmony_SDK # The directory where the compressed files are stored + output_path: D:\enviorment\SDK\openHarmony_SDK\temp # File replacement path + - dayu200: + name: dayu200 + path: D:\AutoXTSTest + output_path: D:\AutoXTSTest\dayu200_xts + diff --git a/test/scripts/download/download.py b/test/scripts/download/download.py new file mode 100644 index 0000000000000000000000000000000000000000..6cf0e610ddafeac174acc3ee80ef407e68cabdb2 --- /dev/null +++ b/test/scripts/download/download.py @@ -0,0 +1,266 @@ +import argparse +import os +import shutil +import sys +import tarfile +import zipfile +import subprocess + +import yaml + + +import utils + + +configs = {} +arguments = {} + + +class downloadTask: + def __init__(self): + self.name = '' + self.path = '' + self.output_path = '' + + +def parse_configs(): + config_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.yaml') + with open(config_file_path, 'r', encoding='utf-8') as config_file: + global configs + configs = yaml.safe_load(config_file) + + +def clean_log(): + output_log_dic = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'result') + if os.path.exists(output_log_dic): + shutil.rmtree(output_log_dic) + + +def create_download_task(): + task_list = [] + download_list = configs.get('download_list') + for download_task in download_list: + task = downloadTask() + task.name = download_task['name'] + task.path = download_task['path'] + task.output_path = download_task['output_path'] + task_list.append(task) + + return task_list + + +def check_deveco_dev(): + if utils.is_linux(): + return False + + java_path = os.path.join(configs.get('deveco_path'), 'jbr') + if not os.path.exists(java_path): + print("Java not found!") + return False + + if not os.path.exists(configs.get('node_js_path')): + print("Node js not found!") + return False + + return True + + +def check_rkDevTool(): + rKDevTool_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../auto_xts_test/RKDevTool') + if not os.path.exists(rKDevTool_path): + url = configs.get('RKdevtool_download_path') + output_path = configs.get('RKdevtool_output_path') + utils.get_tool('RKDevTool.zip', url, output_path) + + rKDevTool_exe_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), + '../auto_xts_test/RKDevTool/RKDevTool.exe') + if not rKDevTool_exe_path: + return False + + return True + + +def check_pictures_reference(): + pictures_reference_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), + '../sdk_test/pictures_reference') + if not os.path.exists(pictures_reference_path): + url = configs.get('pictures_download_path') + output_path = configs.get('pictures_output_path') + utils.get_tool('pictures_references.zip', url, output_path) + if not os.path.exists(pictures_reference_path): + return False + + return True + + +def prepare_test_dev(): + clean_log() + prepared = check_deveco_dev() + prepared = prepared and check_rkDevTool() and check_pictures_reference() + return prepared + + +def download_simple(download_url): + download_name = utils.parse_file_name(download_url) + download_path = configs.get('download_path') + download_temp_file = os.path.join(download_path, download_name) + if not os.path.exists(download_path): + os.mkdir(download_path) + utils.download(download_url, download_temp_file, download_name) + + # 判断文件名后缀, 如果是gz则对文件进行解压 + file_extension = os.path.splitext(download_name)[-1] + if file_extension == '.gz': + with tarfile.open(download_temp_file, 'r:gz') as tar: + print(f'Unpacking {download_temp_file}') + tar.extractall(download_path) + print(f'Decompression {download_temp_file} completed') + + +def download_zip_file(task_name, download_url, path): + # 读取文件路径 + print(path) + temp_floder = path + '_temp' + download_name = utils.get_remote_download_name(task_name) + + download_temp_file = os.path.join(temp_floder, download_name) + if os.path.exists(temp_floder): + shutil.rmtree(temp_floder) + os.mkdir(temp_floder) + # 开始下载任务 + print(f'download {task_name} from {download_url}, please wait!!!') + utils.download(download_url, download_temp_file, download_name) + + # 校验是否正确获取到文件 + if not utils.check_gzip_file(download_temp_file): + print('The downloaded file is not a valid gzip file.') + return '', '' + + # 解压文件 + with tarfile.open(download_temp_file, 'r:gz') as tar: + print(f'Unpacking {download_temp_file}') + tar.extractall(temp_floder) + print(f'Decompression {download_temp_file} completed') + + if task_name == 'sdk': + sdk_zip_path_list = [temp_floder, 'ohos-sdk', 'windows'] + if utils.is_mac(): + sdk_zip_path_list = [temp_floder, 'sdk', + 'packages', 'ohos-sdk', 'darwin'] + sdk_floder = os.path.join(temp_floder, 'SDK_TEMP') + sdk_zip_path = os.path.join(*sdk_zip_path_list) + for item in os.listdir(sdk_zip_path): + if item != '.DS_Store': + print(f'Unpacking {item}') + with zipfile.ZipFile(os.path.join(sdk_zip_path, item)) as zip_file: + zip_file.extractall(os.path.join(sdk_floder)) + print(f'Decompression {item} completed') + + +def updata_to_output_path(task_name, path, output_path): + if task_name == 'sdk': + deveco_sdk_path = configs.get('deveco_sdk_path') + temp_floder = deveco_sdk_path + '_temp' + sdk_floder = os.path.join(temp_floder, 'SDK_TEMP') + api_version = utils.get_api_version(os.path.join( + *[sdk_floder, 'ets', 'oh-uni-package.json'])) + update_sdk_to_deveco(sdk_floder, api_version) + else: + if os.path.exists(output_path): + shutil.rmtree(output_path) + if os.path.exists(path): + shutil.move(path, output_path) + + +def update_sdk_to_deveco(sdk_path, api_version): + deveco_sdk_path = configs.get('deveco_sdk_path') + deveco_sdk_version_path = os.path.join(deveco_sdk_path, api_version) + for sdk_item in os.listdir(deveco_sdk_path): + if sdk_item.startswith(f'{api_version}-'): + shutil.rmtree(os.path.join(deveco_sdk_path, sdk_item)) + if os.path.exists(deveco_sdk_version_path): + shutil.move(deveco_sdk_version_path, + deveco_sdk_version_path + '-' + utils.get_time_string()) + for item in os.listdir(sdk_path): + if item != '.DS_Store': + if utils.is_mac(): + if item == 'toolchains': + utils.add_executable_permission( + os.path.join(sdk_path, item, 'restool')) + utils.add_executable_permission( + os.path.join(sdk_path, item, 'ark_disasm')) + elif item == 'ets': + utils.add_executable_permission(os.path.join(sdk_path, item, 'build-tools', + 'ets-loader', 'bin', 'ark', 'build-mac', 'bin', + 'es2abc')) + utils.add_executable_permission(os.path.join(sdk_path, item, 'build-tools', + 'ets-loader', 'bin', 'ark', 'build-mac', 'legacy_api8', + 'bin', 'js2abc')) + elif item == 'js': + utils.add_executable_permission(os.path.join(sdk_path, item, 'build-tools', + 'ace-loader', 'bin', 'ark', 'build-mac', 'bin', + 'es2abc')) + utils.add_executable_permission(os.path.join(sdk_path, item, 'build-tools', + 'ace-loader', 'bin', 'ark', 'build-mac', 'legacy_api8', + 'bin', 'js2abc')) + shutil.move(os.path.join(sdk_path, item), + os.path.join(deveco_sdk_version_path, item)) + # 关闭arkts语法规则校验 + utils.close_arkts_code_linter() + + +def burn_system_image(): + RKDevTool_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../auto_xts_test/RKDevTool') + os.chdir(RKDevTool_path) + cmd = 'hdc shell reboot bootloader' + subprocess.run(cmd, shell=False) + utils.auto_burn() + print('burn_system_image_success') + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--downloadUrl', type=str, dest='download_url', default=None, + nargs='+', + help='specify what you want to download') + return parser.parse_args() + + +if __name__ == '__main__': + # 1. 读取配置 && 参数解析 + parse_configs() + parse_args() + arguments = parse_args() + # 如果输入了参数(下载url)就会自动去下载文件到配置中指定的文件夹,并退出。 + if arguments.download_url is not None: + for download_url in arguments.download_url: + print(f'download url: {download_url}') + download_simple(download_url) + # 下载并解压完后退出程序 + sys.exit(1) + + # 2. 检查环境(deveco && 烧录工具) + if not prepare_test_dev(): + # logging.error('The test environment is incomplete, please check') + print("The test environment is incomplete, please check") + sys.exit(1) + + # 3. 下载镜像 + if os.path.exists('download_url.txt'): + os.remove('download_url.txt') + download_task_list = create_download_task() + with open('download_url.txt', 'a') as file: + for task in download_task_list: + print(task.name) + # a. 获取下载的url地址 + download_url = utils.get_download_url(task.name) + # b. 下载压缩包到指定目录 && 解压 + download_zip_file(task.name, download_url, task.path) + # c. 覆盖到对应文件夹 + temp_file = task.path + '_temp' + updata_to_output_path(task.name, temp_file, task.output_path) + file.write(f'{task.name}, {download_url}\n') + file.write('download all tasks successfully!!!') + # 4. 烧录镜像到板子中 + burn_system_image() + print('complete all tasks successfully') diff --git a/test/scripts/download/utils.py b/test/scripts/download/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..ce10babca9b080b6caa33732bc5322b64fc33997 --- /dev/null +++ b/test/scripts/download/utils.py @@ -0,0 +1,204 @@ +import gzip +import os +import sys +import logging +import datetime +import zipfile +from urllib.parse import urlparse, unquote +import time +import json +import stat + +import httpx +import requests +import tqdm +from pywinauto.application import Application + + +def is_windows(): + return sys.platform == 'win32' or sys.platform == 'cygwin' + + +def is_mac(): + return sys.platform == 'darwin' + + +def is_linux(): + return sys.platform == 'linux' + + +def get_time_string(): + return time.strftime('%Y%m%d-%H%M%S') + + +def get_encoding(): + if is_windows(): + return 'utf-8' + else: + return sys.getfilesystemencoding() + + +def get_tool(tar_name, url, output_path): + print(f"Getting {tar_name} from {url}") + r = requests.get(url, stream=True) + total = int(r.headers.get('content-length'), 0) + flags = os.O_WRONLY | os.O_CREAT + modes = stat.S_IWUSR | stat.S_IRUSR + with os.fdopen(os.open(f"{output_path}.zip", flags, modes), "wb") as f, tqdm( + desc=f"{tar_name}", + total=total, + unit='iB', + unit_scale=True, + unit_divisor=1024, + ) as bar: + for byte in r.iter_content(chunk_size=1024): + size = f.write(byte) + bar.update(size) + with zipfile.ZipFile(f"{output_path}.zip", 'r') as zfile: + zfile.extractall(path=f"{output_path}") + + +def get_download_url(task_name): + now_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S') + last_hour = (datetime.datetime.now() + + datetime.timedelta(hours=-24)).strftime('%Y%m%d%H%M%S') + url = 'http://ci.openharmony.cn/api/daily_build/build/tasks' + downnload_job = { + 'pageNum': 1, + 'pageSize': 1000, + 'startTime': '', + 'endTime': '', + 'projectName': 'openharmony', + 'branch': 'master', + 'component': '', + 'deviceLevel': '', + 'hardwareBoard': '', + 'buildStatus': '', + 'buildFailReason': '', + 'testResult': '', + } + downnload_job['startTime'] = str(last_hour) + downnload_job['endTime'] = str(now_time) + post_result = requests.post(url, json=downnload_job) + post_data = json.loads(post_result.text) + sdk_url_suffix = '' + for ohos_sdk_list in post_data['data']['dailyBuildVos']: + try: + if get_remote_download_name(task_name) in ohos_sdk_list['obsPath']: + sdk_url_suffix = ohos_sdk_list['obsPath'] + break + except BaseException as err: + logging.error(err) + download_url = 'http://download.ci.openharmony.cn/' + sdk_url_suffix + return download_url + + +def download(download_url, temp_file, temp_file_name): + with httpx.stream('GET', download_url) as response: + with open(temp_file, "wb") as temp: + total_length = int(response.headers.get("content-length")) + with tqdm.tqdm(total=total_length, unit="B", unit_scale=True) as pbar: + pbar.set_description(temp_file_name) + chunk_sum = 0 + count = 0 + for chunk in response.iter_bytes(): + temp.write(chunk) + chunk_sum += len(chunk) + percentage = chunk_sum / total_length * 100 + while str(percentage).startswith(str(count)): + if str(percentage).startswith('100'): + logging.info(f'{temp_file_name} Download Complete {percentage: .1f}%') + break + else: + logging.info(f'{temp_file_name} Downloading... {percentage: .1f}%') + count += 1 + pbar.update(len(chunk)) + + +def end_burn(dlg): + timeout = 300 + while True: + if timeout < 0: + return + mode = dlg.window(control_type="Tab").window_text() + if mode == 'Found One MASKROM Device': + dlg.Button16.click() + print("image burnning finished") + return + else: + print("please wait for a while...") + time.sleep(5) + timeout -= 5 + + +def auto_burn(): + app = Application(backend='uia').start('RKDevTool.exe') + dlg = app.top_window() + + while True: + mode = dlg.window(control_type="Tab").window_text() + if mode == 'Found One LOADER Device': + print('start burning') + dlg.window(title="Run").click() + time.sleep(100) + end_burn(dlg) + return + else: + time.sleep(1) + + +def check_gzip_file(file_path): + try: + with gzip.open(file_path, 'rb') as gzfile: + gzfile.read(1) + except Exception as e: + logging.exception(e) + return False + return True + + +def get_remote_download_name(task_name): + if is_windows(): + if task_name == 'sdk': + return 'ohos-sdk-full.tar.gz' + if task_name == 'dayu200': + return 'dayu200.tar.gz' + elif is_mac(): + if task_name == 'sdk': + return 'L2-MAC-SDK-FULL.tar.gz' + else: + print('Unsuport platform to get sdk from daily build') + return '' + + +def get_api_version(json_path): + with open(json_path, 'r') as uni: + uni_cont = uni.read() + uni_data = json.loads(uni_cont) + api_version = uni_data['apiVersion'] + return api_version + + +def add_executable_permission(file_path): + current_mode = os.stat(file_path).st_mode + new_mode = current_mode | 0o111 + os.chmod(file_path, new_mode) + + +def parse_file_name(url): + parsed_url = urlparse(url) + path = unquote(parsed_url.path) + file_name = os.path.basename(path) + return file_name + + +def close_arkts_code_linter(): + ets_checker_path = 'D:\\enviorment\\SDK\\openHarmony_SDK\\11\\ets\\build-tools\\ets-loader\\lib\\ets_checker.js' + with open(ets_checker_path, 'r+') as modified_file: + content = modified_file.read() + content = content.replace( + 'return _main.partialUpdateConfig.executeArkTSLinter?_main.partialUpdateConfig.standardArkTSLinter&&isStandardMode()?_do_arkTS_linter.ArkTSLinterMode.STANDARD_MODE:_do_arkTS_linter.ArkTSLinterMode.COMPATIBLE_MODE:_do_arkTS_linter.ArkTSLinterMode.NOT_USE', + 'return _do_arkTS_linter.ArkTSLinterMode.COMPATIBLE_MODE') + modified_file.seek(0) + modified_file.write(content) + modified_file.truncate() diff --git a/test/scripts/get_commit_log/__pycache__/result.cpython-310.pyc b/test/scripts/get_commit_log/__pycache__/result.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d43ad9b5d72d499af3f6f8f85875676a4e4b570e Binary files /dev/null and b/test/scripts/get_commit_log/__pycache__/result.cpython-310.pyc differ diff --git a/test/scripts/get_commit_log/config.yaml b/test/scripts/get_commit_log/config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9da7db50667787ca547e4b544ef45084fd9e8b7a --- /dev/null +++ b/test/scripts/get_commit_log/config.yaml @@ -0,0 +1,7 @@ +crawl_max_page: 10 +# repo list +repo_list: + - 'arkcompiler_ets_frontend' + - 'developtools_ace_ets2bundle' + - 'third_party_typescript' + - 'arkcompiler_runtime_core' \ No newline at end of file diff --git a/test/scripts/get_commit_log/get_commit_log.py b/test/scripts/get_commit_log/get_commit_log.py new file mode 100644 index 0000000000000000000000000000000000000000..b7314e473cbc7bfbc64bfc418d21afac5db1e33c --- /dev/null +++ b/test/scripts/get_commit_log/get_commit_log.py @@ -0,0 +1,105 @@ +import argparse +import os + +import yaml +import requests +from lxml import etree +from datetime import datetime, timedelta, time + +from result import get_result + + +configs = {} + + +def parse_config(): + config_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.yaml') + with open(config_file_path, 'r', encoding='utf-8') as config_file: + global configs + configs = yaml.safe_load(config_file) + + +def get_url(name, page): + url_prefix = 'https://gitee.com/openharmony/' + url_suffix = f'/pulls?assignee_id=&author_id=&label_ids=&label_text=&milestone_id=&page={page}&priority=&project_type=&scope=&search=&single_label_id=&single_label_text=&sort=closed_at+desc&status=merged&target_project=&tester_id=' + url = url_prefix + name + url_suffix + + return url + + +def get_html(url): + headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' + } + try: + response = requests.get(url, headers=headers, verify=False) + if response.status_code == 200: + return response.text + except Exception as e: + print(e) + return None + + +def crawl_committer(repo_list, start_time, end_time): + crawl_max_page = configs.get('crawl_max_page') + data_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data.txt') + if os.path.exists(data_file): + os.remove(data_file) + for repo_name in repo_list: + for i in range(1, crawl_max_page + 1): + url = get_url(repo_name, str(i)) + print(url) + html = get_html(url) + tree = etree.HTML(html) + commit_list = tree.xpath('/html/body/div[2]/div[2]/div[2]/div[2]/div') + for commit_task in commit_list: + title = commit_task.xpath('.//div[1]/a/text()')[0] + committer = commit_task.xpath('.//div[3]/span[2]/a/span/text()')[0] + commit_time_str = commit_task.xpath('.//div[3]/span[4]/span/text()')[0].strip() + pr_link = commit_task.xpath('.//div[1]/a/@href')[0] + + time = datetime.strptime(commit_time_str, '%Y-%m-%d %H:%M') + if start_time <= time <= end_time: + print("在预期的时间段内") + print(title) + print(committer) + print(commit_time_str) + print(pr_link) + print('---------------------------------') + with open(data_file, 'a', encoding='utf-8') as file: + file.write(f"{repo_name}, {title}, {committer}, {commit_time_str}, {pr_link}\n") + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--startTime', type=str, dest='start_time', default=None, + help='specify crawl start time') + parser.add_argument('--repoName', type=str, dest='repo_name', default=None, + nargs='+', + help='specify which repo you want to crawl') + return parser.parse_args() + + +if __name__ == '__main__': + parse_config() + end_time = datetime.now() + yesterday = end_time - timedelta(days=1) + start_time = datetime(yesterday.year, yesterday.month, yesterday.day, 0, 0, 0) + repo_list = configs.get('repo_list') + + arguments = parse_args() + if arguments.start_time is not None: + time_str = datetime.strptime(arguments.start_time, '%Y-%m-%d') + start_time = datetime.combine(time_str, time.min) + end_time = start_time + timedelta(days=1) + print('爬取开始时间', start_time) + print('爬取结束时间', end_time) + if arguments.repo_name is not None: + repo_list = arguments.repo_name + print(repo_list) + + crawl_committer(repo_list, start_time, end_time) + get_result() + + + diff --git a/test/scripts/get_commit_log/result.py b/test/scripts/get_commit_log/result.py new file mode 100644 index 0000000000000000000000000000000000000000..df910449ceb346a8896b46aa1ff50d13b1b4cb26 --- /dev/null +++ b/test/scripts/get_commit_log/result.py @@ -0,0 +1,36 @@ +import os + +from jinja2 import Environment, FileSystemLoader + + +def get_result(): + data_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data.txt') + with open(data_file, 'r', encoding='utf-8') as file: + lines = file.readlines() + + data = [] + for line in lines: + line = line.strip() + values = line.split(',') + + item = { + 'project': values[0], + 'description': values[1], + 'author': values[2], + 'time': values[3], + 'link': f'https://gitee.com//{values[4]}'.replace(' ', '') + } + data.append(item) + + template_dir = os.path.dirname(__file__) + env = Environment(loader=FileSystemLoader(template_dir)) + template = env.get_template('template.html') + output = template.render(data=data) + + commit_log_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'commit_log.html') + with open(commit_log_file, 'w', encoding='utf-8') as file: + file.write(output) + + +if __name__ == '__main__': + get_result() diff --git a/test/scripts/get_commit_log/template.html b/test/scripts/get_commit_log/template.html new file mode 100644 index 0000000000000000000000000000000000000000..a3e29f842647d02a72708b4d3b0e5a4d0b48fade --- /dev/null +++ b/test/scripts/get_commit_log/template.html @@ -0,0 +1,97 @@ + + +
+ +项目 | +描述 | +作者 | +时间 | +链接 | +
---|---|---|---|---|
{{ item.project }} | +{{ item.description }} | +{{ item.author }} | +{{ item.time }} | +点击查看 | +
{test_part} not complete yet
' - return content - if not os.path.exists(file_name): - content += f'{test_part} run failed
' - return content - with open(file_name, 'r', encoding='utf-8') as f: - content += f.read() - return content - - -def add_attachment(msg, file_list): - for file in file_list: - if os.path.exists(file): - with open(file, 'rb') as f: - attachment = MIMEText(f.read(), 'base64', 'utf-8') - attachment['Content-Disposition'] = f'attachment; filename="{os.path.basename(file)}"' - msg.attach(attachment) - - -def add_image(msg, img_dic): - for path in img_dic: - if os.path.exists(path): - with open(path, 'rb') as f: - img = MIMEImage(f.read()) - img.add_header('Content-ID', img_dic[path]) - msg.attach(img) - - -def send_email(): - with open(r".\email_config.yaml", 'r') as f: - data = yaml.safe_load(f.read()) - - user_name = data["user_name"] - sender = data["sender_email_address"] - auth_code = data["auth_code"] - receiver = data["receiver_list"] - smtp_server = data["smtp_server"] - smtp_port = data["smtp_port"] - xts_test = data["xts_report_file"] - sdk_test = data["sdk_report_file"] - perf_test = data["perf_report_file"] - attachment_files = data["attatchment_files"] - image_files = data["image_files"] - - msg = MIMEMultipart() - msg['From'] = sender - msg['To'] = ", ".join(receiver) - msg['Subject'] = "Arkcompiler Test" - - html = "" - dividing_line = '{test_part} not complete yet
' + return content + if not os.path.exists(file_name): + content += f'{test_part} run failed
' + return content + with open(file_name, 'r', encoding='utf-8') as f: + content += f.read() + return content + + +def add_attachment(msg, file_list): + for file in file_list: + if os.path.exists(file): + with open(file, 'rb') as f: + attachment = MIMEText(f.read(), 'base64', 'utf-8') + attachment['Content-Disposition'] = f'attachment; filename="{os.path.basename(file)}"' + msg.attach(attachment) + + +def add_image(msg, img_dic): + for path in img_dic: + if os.path.exists(path): + with open(path, 'rb') as f: + img = MIMEImage(f.read()) + img.add_header('Content-ID', img_dic[path]) + msg.attach(img) + + +def send_email(): + with open(r"email_config.yaml", 'r') as f: + data = yaml.safe_load(f.read()) + + user_name = data["user_name"] + sender = data["sender_email_address"] + auth_code = data["auth_code"] + receiver = data["receiver_list"] + smtp_server = data["smtp_server"] + smtp_port = data["smtp_port"] + xts_test = data["xts_report_file"] + sdk_test = data["sdk_report_file"] + perf_test = data["perf_report_file"] + attachment_files = data["attatchment_files"] + image_files = data["image_files"] + + msg = MIMEMultipart() + msg['From'] = sender + msg['To'] = ", ".join(receiver) + msg['Subject'] = "Arkcompiler Test" + + html = "" + dividing_line = '