diff --git a/tools/porting_advisor/batch_scan.py b/tools/porting_advisor/batch_scan.py new file mode 100644 index 0000000000000000000000000000000000000000..6364f705bbd0d6f0ff3870703be98de6e08c8c3f --- /dev/null +++ b/tools/porting_advisor/batch_scan.py @@ -0,0 +1,37 @@ +import os +import time + +import requests + +os.environ['http_proxy'] = "http://w3账号:密码@proxycn2.huawei.com:8080/" +os.environ['https_proxy'] = "http://w3账号:密码@proxycn2.huawei.com:8080/" +try: + from urllib import urlencode +except ImportError: + from urllib.parse import urlencode + +repo_owner = 'src-openeuler' # 获取那个组织的仓库 +requests.packages.urllib3.disable_warnings() +body = "/source_scan" +data = {"access_token": 'token实际的值', "body": "/source_scan"} +for i in range(10, 101): # 从第几页开始扫描 + comment_pr_url = "https://gitee.com/api/v5/orgs/{}/repos?type=all&page={}&per_page=100".format(repo_owner, i) + res = requests.get(comment_pr_url, verify=False, timeout=50) + print("获取仓库") + root_dict = res.json() + for j in range(0, 100): + repo = root_dict[j]["name"] + print("页数") + print(i) + print("仓库名为" + repo) + comment_pr_url = "https://gitee.com/api/v5/repos/{}/{}/pulls/{}/comments".format(repo_owner, repo, 1) + res = requests.post(comment_pr_url, data, timeout=50, verify=False) + print("评论/source_scan") + comment_pr_url = "https://gitee.com/api/v5/repos/{}/{}/pulls/{}/comments?per_page=20&direction=desc". \ + format(repo_owner, repo, 1) + res = requests.get(comment_pr_url, data, timeout=50, verify=False) + if res.status_code == 200: + while res.json()[0]["user"]["name"] == 'anyuting': + time.sleep(30) + res = requests.get(comment_pr_url, data, timeout=50, verify=False) + print("已得到" + repo + "的报告") diff --git a/tools/porting_advisor/scan_report.py b/tools/porting_advisor/scan_report.py new file mode 100644 index 0000000000000000000000000000000000000000..c8c86d5cf0c3b9f8e5f0ce5ae0b6b325042801ec --- /dev/null +++ b/tools/porting_advisor/scan_report.py @@ -0,0 +1,46 @@ +import csv +import os + +path = 'C:\\Users\Desktop\\report-master' # 要扫描的文件夹,注意不要包含中文 +files = os.listdir(path) # 获取的文件夹列表 +title = ["项目", "是否需要迁移", "Number of Scanned Files", "C/C++/Fortran/Makefile/CMakeLists.txt/Automake", + "pure assembly files", "Go files", "python files", "java files", "scala files", + "Estimated transplant workload"] + +with open(r'C:\\Users\Desktop\\report.csv', 'a', newline="", encoding="UTF-8-SIG") as f: #写入title + writer = csv.writer(f) + writer.writerow(title) + + +def splitCsvFiles(): + for file in files: + dirpath = 'C:\\Users\Desktop\\report-master\\{}\\porting-advisor.csv'.format(file) + print(dirpath) + f = open(dirpath) + csv_reader = csv.reader(f) + fields = [file] + begin = 0 + for line in csv_reader: #判断是否需要迁移, + if begin == 1: + fields.append(line) + if 'Estimated transplant' in line: + begin = 0 + break + if 'Source Need Migrated: NO' in line: + fields.append('Source Need Migrated: NO') + break + if 'Source Need Migrated: YES' in line: + begin = 1 + fields.append('Source Need Migrated: YES') + if 'Architecture-related Dependencies:' in line or 'Source files scan details are as follows:' in line: + fields.pop(len(fields) - 1) + fields.pop(len(fields) - 1) + begin = 0 + break + with open(r'C:\\Users\Desktop\\report.csv', 'a', newline="") as f: + writer = csv.writer(f) + writer.writerow(fields) + + +if __name__ == '__main__': + splitCsvFiles()