From 9bf48bec70ec18f91dd5e9af870eb27d2ddfd100 Mon Sep 17 00:00:00 2001 From: wangchong1995924 <15229716099@163.com> Date: Thu, 14 Dec 2023 11:04:10 +0800 Subject: [PATCH] fix issue I8MTVQ --- script/tools/update_cve_and_repodata.py | 91 ++++++++++++++++++------- 1 file changed, 66 insertions(+), 25 deletions(-) diff --git a/script/tools/update_cve_and_repodata.py b/script/tools/update_cve_and_repodata.py index 2bb8d8f..6d408ca 100644 --- a/script/tools/update_cve_and_repodata.py +++ b/script/tools/update_cve_and_repodata.py @@ -85,10 +85,17 @@ def download_xmlfile(args, cvrf_path, obsClient): downloads cve xml file """ update_path = os.path.join(cvrf_path, "update_fixed.txt") + + bugfix_cvrf = os.path.join(os.getcwd(), os.path.join("bugFix", "cvrf")) + if os.path.exists(bugfix_cvrf): + shutil.rmtree(bugfix_cvrf) + os.makedirs(bugfix_cvrf) + hotpatch_cvrf = os.path.join(os.getcwd(), "hotpatch_cvrf") if os.path.exists(hotpatch_cvrf): shutil.rmtree(hotpatch_cvrf) os.makedirs(hotpatch_cvrf) + if os.path.exists(update_path): if os.path.getsize(update_path): with open(update_path, "r") as f: @@ -97,12 +104,19 @@ def download_xmlfile(args, cvrf_path, obsClient): if line: line = line.replace('\n', '') year = line.split('/')[0] - if "HotPatch" in line: + if "openEuler-HotPatchSA" in line: year_path = os.path.join(hotpatch_cvrf, year) localfile = os.path.join(hotpatch_cvrf, line) - else: + elif "openEuler-SA" in line: year_path = os.path.join(cvrf_path, year) localfile = os.path.join(cvrf_path, line) + elif "openEuler-BA" in line: + year_path = os.path.join(bugfix_cvrf, year) + localfile = os.path.join(bugfix_cvrf, line) + else: + print("There are some problems in the update_fixed.txt file.") + sys.exit(1) + if not os.path.exists(year_path): os.makedirs(year_path) name = os.path.join("cvrf", line) @@ -113,15 +127,32 @@ def download_xmlfile(args, cvrf_path, obsClient): else: return -1 -def upload_file(args, uploadfile): +def upload_xml_file(args, uploadfile, cvrf_name): """ - upload files to publish server + upload xml files to publish server """ - print("Uploading file to publish server.") - if args.flag == "cve": - cmd = "scp -i %s -o StrictHostKeyChecking=no -r %s root@%s:/repo/openeuler/security/data/" % (args.sshkey, uploadfile, args.ipadd) - elif args.flag == "updateinfo" or args.flag == "updateinfo-hotpatch": - cmd = "scp -i %s -o StrictHostKeyChecking=no %s root@%s:/repo/" % (args.sshkey, uploadfile, args.ipadd) + print("Uploading xml file to publish server.") + if cvrf_name == "SA" or cvrf_name == "HotPatchSA": + dest_dir = "/repo/openeuler/security/data/" + elif cvrf_name == "BA": + dest_dir = "/repo/openeuler/bugFix/data/" + cmd = "ssh -i %s -o StrictHostKeyChecking=no root@%s 'if [ ! -d %s ];then mkdir -p %s;fi'" % (args.sshkey, args.ipadd, dest_dir, dest_dir) + if os.system(cmd) != 0: + print("Fail to create directory:%s" % dest_dir) + + cmd = "scp -i %s -o StrictHostKeyChecking=no -r %s root@%s:%s" % (args.sshkey, uploadfile, args.ipadd, dest_dir) + if os.system(cmd) == 0: + print("Succeed to upload file!") + else: + print("Failed to upload file!") + sys.exit(1) + +def upload_updateinfo_file(args, uploadfile): + """ + upload updateinfo files to publish server + """ + print("Uploading updateinfo file to publish server.") + cmd = "scp -i %s -o StrictHostKeyChecking=no %s root@%s:/repo/" % (args.sshkey, uploadfile, args.ipadd) if os.system(cmd) == 0: print("Succeed to upload file!") else: @@ -157,38 +188,48 @@ def update_cve(args): if os.path.exists(cvrf_path): shutil.rmtree(cvrf_path) os.makedirs(cvrf_path) + for name in args.filename.split(','): localfile = os.path.join(cvrf_path, name) createFile(localfile) obsClient = construct_obsClient(args) name = os.path.join("cvrf", name) download_withfile(args, obsClient, name, localfile) + ret = download_xmlfile(args, cvrf_path, obsClient) update_path = os.path.join(cvrf_path, "update_fixed.txt") if os.path.exists(update_path): os.remove(update_path) + if ret == -1: print("Nothing to update !") else: - hotpatch_path = os.path.join(os.getcwd(), "hotpatch_cvrf") - hotpatch_index_txt = os.path.join(hotpatch_path, "index.txt") all_index_txt = os.path.join(os.getcwd(), "index.txt") cvrf_index_txt = os.path.join(cvrf_path, "index.txt") shutil.copy(cvrf_index_txt, all_index_txt) - f1 = open(all_index_txt, "r") - f2 = open(cvrf_index_txt, "w") - f3 = open(hotpatch_index_txt, "w") - for line in f1: + hotpatch_path = os.path.join(os.getcwd(), "hotpatch_cvrf") + hotpatch_index_txt = os.path.join(hotpatch_path, "index.txt") + bugfix_path = os.path.join(os.getcwd(), os.path.join("bugFix", "cvrf")) + bugfix_index_txt = os.path.join(bugfix_path, "index.txt") + f_all = open(all_index_txt, "r") + f_sa = open(cvrf_index_txt, "w") + f_hotpatch = open(hotpatch_index_txt, "w") + f_bugfix = open(bugfix_index_txt, "w") + for line in f_all: if line: - if "HotPatch" in line: - f3.write(line) - else: - f2.write(line) - f1.close() - f2.close() - f3.close() - upload_file(args, cvrf_path) - upload_file(args, hotpatch_path) + if "openEuler-HotPatchSA" in line: + f_hotpatch.write(line) + elif "openEuler-SA" in line: + f_sa.write(line) + elif "openEuler-BA" in line: + f_bugfix.write(line) + f_all.close() + f_sa.close() + f_hotpatch.close() + f_bugfix.close() + upload_xml_file(args, cvrf_path, "SA") + upload_xml_file(args, hotpatch_path, "HotPatchSA") + upload_xml_file(args, bugfix_path, "BA") def update_repo(args): """ @@ -218,7 +259,7 @@ def update_repo(args): os.makedirs(branch_path) createFile(localfile) download_withfile(args, obsClient, name, localfile) - upload_file(args, localfile) + upload_updateinfo_file(args, localfile) ret = modify_repo(args, branch, xmlfile) if ret: error_msg.extend(ret) -- Gitee