diff --git a/modify_branch.py b/modify_branch.py new file mode 100644 index 0000000000000000000000000000000000000000..c70618fa1ef9d9e1a4a626b0552161593587fa3a --- /dev/null +++ b/modify_branch.py @@ -0,0 +1,23 @@ +import base64 +import sys +import os +#import yaml +import json +import re +import requests +import time +from collections import defaultdict,OrderedDict + +data = {"access_token":"f044826681b5bb001b7cf5ac148b1fae","name":"phrel","has_issues":"true","has_wiki":"true","can_comment":"true","default_branch":"openEuler-22.03-LTS"} +headers = {"Content-Type": "application/json;charset=UTF-8"} +with open("default_branch.txt", "r") as f: + yaml_list = f.read() +print("---------------") +print(len([ i.split("'")[1] for i in yaml_list.split(", ")])) +for i in yaml_list.split(", "): + yaml_file = i.split("'")[1] + response_url = requests.patch("https://gitee.com/api/v5/repos/src-oepkgs/{}".format(yaml_file),data=data) + if response_url.status_code != 200: + print("*******************") + print(yaml_file) + sys.exit() \ No newline at end of file diff --git a/tools/auto_creat_lib/.keep b/tools/auto_creat_lib/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tools/auto_creat_lib/add/.keep b/tools/auto_creat_lib/add/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tools/auto_creat_lib/add/lib_data.py b/tools/auto_creat_lib/add/lib_data.py new file mode 100644 index 0000000000000000000000000000000000000000..f863cc7a07994fec2b7062e2c2ac49cb60c07ca0 --- /dev/null +++ b/tools/auto_creat_lib/add/lib_data.py @@ -0,0 +1,95 @@ +# !/usr/bin/python3 +# -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import re +import requests +import time +import copy +from collections import defaultdict, OrderedDict +# import requests.adapters + +from xml.etree.ElementTree import parse + +srcOepkgsNum = 0 +allFileNum = 0 +allFileList = [] # 存放 当前路径 以及当前路径的子路径 下的所有文件 +sigInfolist = [] +allYamlList = [] +filter_char = [] +allYamldata = [] +src_code_up = [] +src_code_is = [] +yaml_error = [] +rpm_info = {} +d = defaultdict(list) +d_oepkg = defaultdict(list) +dict_list = defaultdict(list) + + +def getAllFilesInPath(path): + global allFileNum + curPathDirList = [] # 当前路径下的所有文件夹 + files = os.listdir(path) # 返回当前路径下的所有文件和文件夹 + for f in files: + if os.path.isdir(path + "/" + f): + if f[0] == ".": + pass # 排除隐藏文件夹 + else: + curPathDirList.append(f) # 添加非隐藏文件夹 + if os.path.isfile(path + "/" + f): + if f[-8:] == ".src.rpm": + allFileList.append(os.path.abspath(path + "/" + f)) # 添加文件 + allFileNum = allFileNum + 1 + # 总文件数+1 + if f[-5:] == ".yaml" and f != "sig-info.yaml": + yaml_name = f[:-5] + allYamlList.append(yaml_name) + # allYamldata.append(os.path.abspath(path + "/" + f)) + + for dl in curPathDirList: + getAllFilesInPath(path + "/" + dl) # 递归获取当前目录下的文件夹内的文件 + + +# 获取rpm信息,拿到name和description +def shell_cmd(rpm_key, path): + rpm_info = os.popen("rpm -qi {}".format(path)) + for line in rpm_info.read().splitlines(): + rpm_value = line.split(":") + if rpm_value[0].strip() == rpm_key: + return rpm_value[1].strip() + + +if __name__ == '__main__': + # 读取rpm包名存入列表内 + # rpm_pkg_path = input("请输入要获取的rpm包目录:") + # api_token = input("请输入api的token:") + if len(sys.argv) != 2: + sys.exit() + + # requests.adapters.DEFUALT_RETRYS = 10 + headers = {"Content-Type":"application/json;charset=UTF-8","Connection":"close"} + rpm_pkg_path = "/srv/rpm/testing/openeuler-20.03-LTS-SP3" + rq_header = "curl -X POST --header 'Content-Type: application/json;charset=UTF-8'" + real_path = os.path.dirname(os.path.realpath(__file__)) + "/" + api_token = "68a19dd4a3bd83ce89b3ce0e3ca979d1" + robot_token = "c951fee688f4b037d27602d7461b81fc" + # 取rpm包总数和rpm文件绝对路径 + getAllFilesInPath(rpm_pkg_path) + print("当前路径下的总文件数 =", allFileNum) + for rpm_path in allFileList: + rpm_file = shell_cmd("Name", rpm_path) # 获取rpm信息 + d[rpm_file].append(rpm_path) + # 获取src-oepkgs上已经存在的库,通过yaml文件获取 + #getAllFilesInPath("./oepkgs-management/sig") + print("------- yaml file ---------") + print(len(allYamlList)) + # print(allYamlList) + print("------- rpm dict -------") + # json.dumps(d) + with open("sp3_yaml.json", "w") as f: + f.write(json.dumps(d)) diff --git a/tools/auto_creat_lib/add/pr_bat.py b/tools/auto_creat_lib/add/pr_bat.py new file mode 100644 index 0000000000000000000000000000000000000000..639b182950e9b6fdeb454e7b23853e25de6284a1 --- /dev/null +++ b/tools/auto_creat_lib/add/pr_bat.py @@ -0,0 +1,230 @@ +# !/usr/bin/python3 +# -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import copy +import re +import requests +import time +from collections import defaultdict +from xml.etree.ElementTree import parse +from txdpy import get_Bletter,get_Sletter + +srcOepkgsNum = 0 +allFileNum = 0 +allFileList = [] # 存放 当前路径 以及当前路径的子路径 下的所有文件 +sigInfolist = [] +allYamlList = [] +filter_char = [] +allYamldata = [] +rpm_info = {} +d = defaultdict(list) +d_oepkg = defaultdict(list) +dict_list = defaultdict(list) +Inyaml = [] + +def getAllFilesInPath(path): + #print(path) + global allFileNum + curPathDirList = [] # 当前路径下的所有文件夹 + files = os.listdir(path) # 返回当前路径下的所有文件和文件夹 + for f in files: + if os.path.isdir(path + "/" + f): + if f[0] == ".": + pass # 排除隐藏文件夹 + else: + curPathDirList.append(f) # 添加非隐藏文件夹 + if os.path.isfile(path + "/" + f): + if f[-8:] == ".src.rpm": + allFileList.append(os.path.abspath(path + "/" + f)) # 添加文件 + allFileNum = allFileNum + 1 + # 总文件数+1 + if f[-5:] == ".yaml" and f != "sig-info.yaml": + # yaml_name = f[:-5] + # allYamlList.append(yaml_name) + if path.split("/")[1] == "oepkgs-management_10": + allYamldata.append(os.path.abspath(path + "/" + f)) + elif path.split("/")[1] == "oepkgs-management": + Inyaml.append(f) + for dl in curPathDirList: + getAllFilesInPath(path + "/" + dl) # 递归获取当前目录下的文件夹内的文件 + + +def creat_pr(): + print("------ pr -------") + data = {"access_token": api_token, "title": "自动化创建库", "head": "zhang-yn:master", "base": "master"} + response = requests.post("https://gitee.com/api/v5/repos/oepkgs/oepkgs-management/pulls", params=data,headers=headers) + #print(response) + pr_num = json.loads(response.text)["number"] + print("-------- waiting 10 minutes ---------") + #sys.exit() + time.sleep(150) + response = requests.get("https://gitee.com/api/v5/repos/oepkgs/oepkgs-management/pulls/{}/merge?access_token={}".format(pr_num,api_token),headers=headers) + response_dict = json.loads(response.text) + if "message" in response_dict.keys(): + if response_dict['message'] == 'Pull Request已经合并': + print("merge push") + else: + commit_id = os.popen( + "{0} 'https://gitee.com/api/v5/repos/oepkgs/oepkgs-management/pulls/{1}' -d '{{\"access_token\":\"{2}\",\"state\":\"closed\"}}'".format( + closed_header, pr_num, api_token)).read() + response_json = json.loads(commit_id) + if response_json["state"] == "closed": + # print("******* 当前提交未合并 ********") + creat_pr() + else: + print("---------- pr 未关闭 ------------") + sys.exit() + print("--- 已合入 ---") + #time.sleep(300) + #print(pr_num) + #sys.exit() + #os.system( + # "{} 'https://gitee.com/api/v5/repos/oepkgs/oepkgs-management/pulls/{}/comments' -d '{{\"access_token\":\"{}\",\"body\":\"{}\"}}'".format( + # rq_header, pr_num, robot_token, "/lgtm")) + #os.system( + # "{} 'https://gitee.com/api/v5/repos/oepkgs/oepkgs-management/pulls/{}/comments' -d '{{\"access_token\":\"{}\",\"body\":\"{}\"}}'".format( + # rq_header, pr_num, robot_token, "/approve")) + + + +# 监听pr +def listen_event(pr_num): + response = requests.get( + "https://gitee.com/api/v5/repos/oepkgs/oepkgs-management/pulls/{}/merge?access_token={}".format(pr_num,api_token),headers=headers) + response_dict = json.loads(response.text) + if not response_dict['message'] == 'Pull Request已经合并': + time.sleep(300) + listen_event(pr_num) + + + + +if __name__ == '__main__': + # 读取rpm包名存入列表内 + # rpm_pkg_path = input("请输入要获取的rpm包目录:") + # api_token = input("请输入api的token:") + headers = {"Content-Type": "application/json;charset=UTF-8"} + rpm_pkg_path = "/srv/rpm/pub/" + rq_header = "curl -X POST --header 'Content-Type: application/json;charset=UTF-8'" + real_path = os.path.dirname(os.path.realpath(__file__)) + "/" + closed_header = "curl -X PATCH --header 'Content-Type: application/json;charset=UTF-8'" + api_token = "c4a7f2254bd58885a9c6fa80cbd0b7dc" + robot_token = "c951fee688f4b037d27602d7461b81fc" + # 取rpm包总数和rpm文件绝对路径 + # getAllFilesInPath(rpm_pkg_path) + + a = 0 + # 创建pr + os.system("git clone 'https://gitee.com/zhang-yn/oepkgs-management.git';") + print("--------") + getAllFilesInPath("./oepkgs-management_10/sig") + getAllFilesInPath("./oepkgs-management/sig") + print("********") + #print(Inyaml) + print("===========") + print(len(allYamldata)) + print(len(set(allYamldata))) + print("---------------") + #b = [j.split("/")[-1] for j in allYamldata] + #a = copy.deepcopy(b) + #for i in a: + # if i in Inyaml: + # b.remove(i) + #print(len(set(b))) + #print(b) + #sys.exit() + #print(len(set([j.split("/")[-1][:-5] for j in allYamldata]))) + #c = [j.split("/")[-1][:-5] for j in allYamldata] + #list_num = [] + #for i in c: + # if c.count(i) > 1: + # list_num.append(i) + #print(list_num) + #sys.exit() + # if len(get_Bletter(i)) != 0: + #for i, item in enumerate(allYamldata): + # if len(get_Bletter(item.split("/")[-1][:-5])) != 0: + # if item.split("/")[-1][:-5].lower() + ".yaml" not in Inyaml: + # if item.split("/")[-1][:-5].lower() in [j.split("/")[-1][:-5] for j in allYamldata]: + # print(item.split("/")[-1][:-5],item.split("/")[-1][:-5].lower(),item) + #sys.exit() + for i, item in enumerate(allYamldata): + if len(get_Bletter(item.split("/")[-1][:-5])) != 0: + if item.split("/")[-1][:-5].lower() + ".yaml" in Inyaml: + # os.system("rm -rf {}".format(item)) + continue + dest_path = real_path + "oepkgs-management" + "/" + "/".join(item.split("/")[-5:-1]) + "/" + #print(item) + if item.split("/")[-1] not in Inyaml and len(item.split("/")[-1][:-5]) > 1 and len(item.split("/")[-1].split(".")) == 2: + a = a + 1 + if not os.path.exists(dest_path): + os.system("mkdir -p {0};cp -rf {1} {0}".format(dest_path,item)) + else: + os.system("cp -rf {1} {0}".format(dest_path, item)) + if a >= 100: + os.system("cd {0};git add .;git commit -m '自动化仓库创建';git push".format("oepkgs-management")) + creat_pr() + time.sleep(500) + # print(a) + a = 0 + print("--------") + # print(a) + # data = {"access_token": api_token, "title": "自动化创建库", "head": "zhang-yn:master", "base": "master"} + # response = requests.post("https://gitee.com/api/v5/repos/oepkgs/oepkgs-management/pulls", params=data, + # headers = headers) + # pr_num = json.loads(response.text)["number"] + # print(pr_num) + # # listen_event(pr_num) + + + + + + print("------- creat end -------") + sys.exit() + for lib_name in d: + # fork仓库 + os.system("{} 'https://gitee.com/api/v5/repos/src-oepkgs/{}/forks' -d '{{\"access_token\":\"{}\"}}'".format(rq_header, + lib_name, + api_token)) + module_name = d[lib_name] + for rpm_path in module_name: + rpm_version = rpm_path.split("/")[-1][:-8][len(lib_name) + 1:] + # 解压rpm,git commit + if not os.path.exists(real_path+lib_name): + os.system( + "git clone 'https://gitee.com/zhang-yn/{0}.git';cd {0};pwd;rm -rf *;rpm2cpio {1} | cpio -div;git add .;git commit -m '{2}';git push".format( + lib_name, rpm_path, rpm_version)) + print( + "git clone 'https://gitee.com/zhang-yn/{0}.git';cd {0};rm -rf README.*;rpm2cpio {1} | cpio -div;git add .;git commit -m '{2}';git push".format( + lib_name, rpm_path, rpm_version)) + else: + os.system( + "cd {0};rm -rf *;rpm2cpio {1} | cpio -div;git add .;git commit -m '{2}';git push".format(lib_name, + rpm_path, + rpm_version)) + + # 创建pr + data = {"access_token": api_token, "title": "自动化创建库", "head": "zhang-yn:master", + "base": "openEuler-22.03-LTS"} + response = requests.post("https://gitee.com/api/v5/repos/wwccyang/{}/pulls".format(lib_name), params=data, + headers = rq_header) + + # 取commit信息,打tag + response_url = requests.get( + "https://gitee.com/api/v5/repos/src-oepkgs/{}/commits?access_token={}=master&page=1&per_page=20".format( + lib_name, api_token), headers = rq_header) + pr_num = json.loads(response_url.text) + for i in range(1, len(d[lib_name]) + 1): + print("********************") + print(pr_num[i]["sha"]) + commit_id = pr_num[i]["sha"] + tag_str = pr_num[i]["commit"]["message"] + os.system( + "{} 'https://gitee.com/api/v5/repos/zhang-yn/{}/tags' -d '{{\"access_token\":\"{}\",\"refs\":\"{}\",\"tag_name\":\"{}\"}}'".format( + rq_header, lib_name, api_token, commit_id, "22.0-" + tag_str)) diff --git a/tools/auto_creat_lib/add/upload_rpmcode.py b/tools/auto_creat_lib/add/upload_rpmcode.py new file mode 100644 index 0000000000000000000000000000000000000000..353e1a499941df7d727dec4ab17a500ba8c2711a --- /dev/null +++ b/tools/auto_creat_lib/add/upload_rpmcode.py @@ -0,0 +1,305 @@ +# !/usr/bin/python3 +# -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import re +import requests +import time +import copy +from collections import defaultdict, OrderedDict +# import requests.adapters + +from xml.etree.ElementTree import parse + +srcOepkgsNum = 0 +allFileNum = 0 +allFileList = [] # 存放 当前路径 以及当前路径的子路径 下的所有文件 +sigInfolist = [] +allYamlList = [] +filter_char = [] +allYamldata = [] +src_code_up = [] +src_code_is = [] +yaml_error = [] +rpm_info = {} +d = defaultdict(list) +d_oepkg = defaultdict(list) +dict_list = defaultdict(list) +ones = {1: "one", 2: "two", 3: "three", 4: "four", + 5: "five", 6: "six", 7: "seven", 8: "eight", + 9: "nine", 0: "zero"} + + +def getAllFilesInPath(path): + global allFileNum + curPathDirList = [] # 当前路径下的所有文件夹 + files = os.listdir(path) # 返回当前路径下的所有文件和文件夹 + for f in files: + if os.path.isdir(path + "/" + f): + if f[0] == ".": + pass # 排除隐藏文件夹 + else: + curPathDirList.append(f) # 添加非隐藏文件夹 + if os.path.isfile(path + "/" + f): + if f[-8:] == ".src.rpm": + allFileList.append(os.path.abspath(path + "/" + f)) # 添加文件 + allFileNum = allFileNum + 1 + # 总文件数+1 + if f[-5:] == ".yaml" and f != "sig-info.yaml": + yaml_name = f[:-5] + allYamlList.append(yaml_name) + # allYamldata.append(os.path.abspath(path + "/" + f)) + + for dl in curPathDirList: + getAllFilesInPath(path + "/" + dl) # 递归获取当前目录下的文件夹内的文件 + + +# 获取rpm信息,拿到name和description +def shell_cmd(rpm_key, path): + rpm_info = os.popen("rpm -qi {}".format(path)) + for line in rpm_info.read().splitlines(): + rpm_value = line.split(":") + if rpm_value[0].strip() == rpm_key: + return rpm_value[1].strip() + + +if __name__ == '__main__': + # 读取rpm包名存入列表内 + # rpm_pkg_path = input("请输入要获取的rpm包目录:") + # api_token = input("请输入api的token:") + if len(sys.argv) != 2: + sys.exit() + + # requests.adapters.DEFUALT_RETRYS = 10 + headers = {"Content-Type":"application/json;charset=UTF-8","Connection":"close"} + rpm_pkg_path = "/srv/rpm/pub/openeuler-20.03-LTS-SP1" + rq_header = "curl -X POST --header 'Content-Type: application/json;charset=UTF-8'" + real_path = os.path.dirname(os.path.realpath(__file__)) + "/" + api_token = "c4a7f2254bd58885a9c6fa80cbd0b7dc" + robot_token = "c951fee688f4b037d27602d7461b81fc" + print("yaml文件的名字") + #getAllFilesInPath("./oepkgs-management/sig") + #print(allYamlList) + with open("yaml_sp3.json", "r") as f: + d = json.load(f) + # print(d) + #d_list = copy.deepcopy(d) + #for i in d_list: + # if i != "openblas": + # del d[i] + # else: + # break + print("---------------") + print(len(d)) + print(d) + #sys.exit() + tag_num = 0 + for yaml_file in d: + # # if yaml_modify not in allYamlList: + # yaml_file = "" + # if yaml_modify[0].isdigit(): + # for i, item in enumerate(yaml_modify): + # if not item.isdigit() and item == "-": + # yaml_file = yaml_file + yaml_modify[i + 1:] + # # yaml_file = yaml_modify[i + 1:] + "-" + yaml_modify[:i] + # break + # elif not item.isdigit() and item != "-": + # yaml_file = yaml_file + yaml_modify[i:] + # # yaml_file = yaml_modify[i + 1:] + yaml_modify[:i] + # break + # else: + # yaml_file = yaml_file + ones[int(item)] + "-" + # elif "+" in yaml_modify: + # yaml_file = yaml_modify.replace("+", "plus") + # else: + # yaml_file = yaml_modify + # print("*****{}****".format(yaml_modify)) + # + # if yaml_file not in allYamlList: + # src_code_is.append(yaml_file) + # print("-------- out of yaml file --------") + # print(src_code_is) + # continue + module_name = d[yaml_file] + print("----module_name----") + print(module_name) + rpm_dict = {} + version_set = set() + for rpm_path in module_name: + rpm_version = shell_cmd("Version", rpm_path) + print(rpm_version) + version_set.add(rpm_version) + rpm_dict[rpm_version] = rpm_path + version_list = list(version_set) + version_list.sort() + print("------++++++") + print(version_list) + print(rpm_dict) + # sys.exit() + print("+-+-+-+-+-+-+-+") + # s = requests.session() + # s.keep_alive = False + # branch_data = os.popen("curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/src-oepkgs/{}/branches?access_token={}'".format(yaml_file, api_token)).read() + # print("------ branch_data -----") + # print(branch_data) + # response_txt = json.loads(branch_data) + # print("------ branch list -----") + # print(response_txt) + # branch_data.close() + # branch_list = [i["name"] for i in response_txt] + # print(branch_list) + # print([i["name"] for i in response_txt]) + # if type(response_txt) == list: + # if sys.argv[1] not in [i["name"] for i in response_txt]: + # continue + # else: + # tag_num = tag_num + 1 + # print("------ tag_num ------") + # print(tag_num) + # print("https://gitee.com/api/v5/repos/src-oepkgs/{0}/branches/{1}/setting?access_token={2}".format( + # yaml_file, sys.argv[1], api_token)) + # s = requests.session() + # s.keep_alive = False + os.system("curl -X DELETE --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/src-oepkgs/{}/branches/{}/setting?access_token={}'".format(yaml_file, sys.argv[1], api_token)) + for rpm_version in version_list: + rpm_path = rpm_dict[rpm_version] + # if not os.path.exists(real_path + yaml_file): + # time.sleep(1) + # s = requests.session() + # s.keep_alive = False + # tags_data = requests.get( + # "https://gitee.com/api/v5/repos/src-oepkgs/{}/tags?access_token={}".format(yaml_file, + # api_token), + # headers=headers) + # response_txt = json.loads(tags_data.text) + # tags_data.close() + print("***************") + # print(response_txt) + # tag_list = [i["name"] for i in response_txt] + # print(tag_list) + # sys.exit() + # if sys.argv[1] == "master": + # if "20.03-LTS-SP1" + "-v" + rpm_version in [i["name"] for i in response_txt]: + # os.chdir(os.path.pardir) + # os.system("rm -rf {0}".format(yaml_file)) + # print(os.getcwd()) + # src_code_is.append(yaml_file) + # print(src_code_is) + # # continue + # break + # else: + # if sys.argv[1][10:] + "-v" + rpm_version in [i["name"] for i in response_txt]: + # os.chdir(os.path.pardir) + # os.system("rm -rf {0}".format(yaml_file)) + # print(os.getcwd()) + # src_code_is.append(yaml_file) + # print(src_code_is) + # # continue + # break + if sys.argv[1] == "master": + # if "20.03-LTS-SP1" + "-v" + rpm_version in [i["name"] for i in response_txt]: + # os.chdir(os.path.pardir) + # os.system("rm -rf {0}".format(yaml_file)) + # print(os.getcwd()) + # src_code_is.append(yaml_file) + # print(src_code_is) + # continue + # break + os.system("git clone 'https://gitee.com/src-oepkgs/{0}.git';".format(yaml_file)) + print("-----git clone-----") + else: + # if sys.argv[1][10:] + "-v" + rpm_version in [i["name"] for i in response_txt]: + # os.chdir(os.path.pardir) + # os.system("rm -rf {0}".format(yaml_file)) + # print(os.getcwd()) + # src_code_is.append(yaml_file) + # print(src_code_is) + # continue + # break + os.system("git clone -b {1} 'https://gitee.com/src-oepkgs/{0}.git';".format(yaml_file, + sys.argv[1])) + print("-----git clone-----") + if not os.path.exists(real_path + yaml_file): + print("-------path is not exist-------") + print("route is {}".format(os.path.exists(real_path + yaml_file))) + break + os.chdir(os.getcwd() + "/" + yaml_file) + print(os.listdir("./")) + + + print("-----****-----") + print(os.getcwd()) + # print("-----****-----") + os.system( + "rm -rf *;rpm2cpio {0} | cpio -div;git add .;git commit -m '{1}';git push".format(rpm_path, + rpm_version)) + print(os.getcwd()) + #os.chdir(os.path.pardir) + #os.system("rm -rf {0}".format(yaml_file)) + print("-------- pwd --------") + print(os.getcwd()) + # else: + # #print(os.getcwd()) + # print("-------- pwd2 --------") + # print(os.getcwd()) + # #os.chdir(os.getcwd() + "/" + yaml_file) + # os.system("rm -rf *;rpm2cpio {1} | cpio -div;git add .;git commit -m '{2}';git push".format(yaml_file,rpm_path,rpm_version)) + # time.sleep(3) + # st = requests.session() + # st.keep_alive = False + # time.sleep(3) + # response_url = os.popen("curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/src-oepkgs/{}/branches/{}?access_token={}'".format(yaml_file, sys.argv[1], api_token)).read() + commit_id = os.popen("git rev-parse HEAD").read().strip() + print(commit_id) + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + print("-------- pwd --------") + print(os.getcwd()) + # response_json = json.loads(response_url) + # response_url.close() + # if response_json == {'message': 'Branch does not exist'}: + # print("-------") + # print("{} is 500".format(yaml_file)) + # yaml_error.append(yaml_file) + # break + print("------- sha value ------") + # print(response_json) + # commit_id = response_json["commit"]["sha"] + print(commit_id) + if sys.argv[1] == "master": + os.system( + "{} 'https://gitee.com/api/v5/repos/src-oepkgs/{}/tags' -d '{{\"access_token\":\"{}\",\"refs\":\"{}\",\"tag_name\":\"{}\"}}'".format( + rq_header, yaml_file, api_token, commit_id, "20.03-LTS-SP1" + "-v" + rpm_version.replace("^",".").replace("~","."))) + else: + os.system( + "{} 'https://gitee.com/api/v5/repos/src-oepkgs/{}/tags' -d '{{\"access_token\":\"{}\",\"refs\":\"{}\",\"tag_name\":\"{}\"}}'".format( + rq_header, yaml_file, api_token, commit_id, sys.argv[1][10:] + "-v" + rpm_version.replace("^",".").replace("~","."))) + print("------- 库名 ------") + print(yaml_file) + tag_num = tag_num + 1 + # time.sleep(1) + # s = requests.session() + # s.keep_alive = False + # data = {"access_token": api_token} + os.system("curl -X PUT --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/src-oepkgs/{}/branches/{}/protection' -d '{{\"access_token\":\"{}\"}}'".format(yaml_file, sys.argv[1], api_token)) + # r_pt.close() + #sys.exit() + src_code_up.append(yaml_file) + # os.system("rm -rf {}".format(yaml_file)) + print(tag_num) + print(src_code_up) + #time.sleep(1) +# else: +# src_code_is.append(yaml_file) +# print(src_code_is) +# time.sleep(2) + #if tag_num >= 3: + # print("----- time sleep -----") + # #print(time.sleep(1800)) + # print("----- time end -----") + # print("----tag_num------") + # sys.exit() diff --git a/tools/auto_creat_lib/add/yaml_part.py b/tools/auto_creat_lib/add/yaml_part.py new file mode 100644 index 0000000000000000000000000000000000000000..92ab74eeaaac13c2ca983efe2ea039949a7a835d --- /dev/null +++ b/tools/auto_creat_lib/add/yaml_part.py @@ -0,0 +1,187 @@ +# !/usr/bin/python3 +# -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import re +import requests +import time +import copy +from collections import defaultdict, OrderedDict +# import requests.adapters + +from xml.etree.ElementTree import parse + +srcOepkgsNum = 0 +allFileNum = 0 +allFileList = [] # 存放 当前路径 以及当前路径的子路径 下的所有文件 +sigInfolist = [] +allYamlList = [] +filter_char = [] +allYamldata = [] +allYamldata_branch = [] +allYamldata_tag = [] +src_code_up = [] +src_code_is = [] +yaml_error = [] +rpm_info = {} +d = defaultdict(list) +d_oepkg = defaultdict(list) +dict_list = defaultdict(list) +ones = {1: "one", 2: "two", 3: "three", 4: "four", + 5: "five", 6: "six", 7: "seven", 8: "eight", + 9: "nine", 0: "zero"} + + +def getAllFilesInPath(path): + global allFileNum + curPathDirList = [] # 当前路径下的所有文件夹 + files = os.listdir(path) # 返回当前路径下的所有文件和文件夹 + for f in files: + if os.path.isdir(path + "/" + f): + if f[0] == ".": + pass # 排除隐藏文件夹 + else: + curPathDirList.append(f) # 添加非隐藏文件夹 + if os.path.isfile(path + "/" + f): + if f[-8:] == ".src.rpm": + allFileList.append(os.path.abspath(path + "/" + f)) # 添加文件 + allFileNum = allFileNum + 1 + # 总文件数+1 + if f[-5:] == ".yaml" and f != "sig-info.yaml": + yaml_name = f[:-5] + allYamlList.append(yaml_name) + # allYamldata.append(os.path.abspath(path + "/" + f)) + + for dl in curPathDirList: + getAllFilesInPath(path + "/" + dl) # 递归获取当前目录下的文件夹内的文件 + + +# 获取rpm信息,拿到name和description +def shell_cmd(rpm_key, path): + rpm_info = os.popen("rpm -qi {}".format(path)) + for line in rpm_info.read().splitlines(): + rpm_value = line.split(":") + if rpm_value[0].strip() == rpm_key: + return rpm_value[1].strip() + + +if __name__ == '__main__': + # 读取rpm包名存入列表内 + # rpm_pkg_path = input("请输入要获取的rpm包目录:") + # api_token = input("请输入api的token:") + if len(sys.argv) != 2: + sys.exit() + + # requests.adapters.DEFUALT_RETRYS = 10 + headers = {"Content-Type":"application/json;charset=UTF-8","connection":"close"} + #rpm_pkg_path = "/srv/rpm/pub/openeuler-20.03-LTS-SP1" + rq_header = "curl -X POST --header 'Content-Type: application/json;charset=UTF-8'" + real_path = os.path.dirname(os.path.realpath(__file__)) + "/" + api_token = "613df0cd941abfdfc90f36445e98736d" + robot_token = "c951fee688f4b037d27602d7461b81fc" + print("yaml文件的名字") + getAllFilesInPath("./oepkgs-management/sig") + print(allYamlList) + with open("sp3_yaml.json", "r") as f: + d = json.load(f) + print("---------------") + print(len(d)) + tag_num = 0 + add_yaml = 0 + for yaml_modify in d: + tag_num = tag_num + 1 + print("------ branch {} 已添加 -----".format(tag_num)) + # if yaml_modify not in allYamlList: + yaml_file = "" + if yaml_modify[0].isdigit(): + for i, item in enumerate(yaml_modify): + if not item.isdigit() and item == "-": + yaml_file = yaml_file + yaml_modify[i + 1:] + # yaml_file = yaml_modify[i + 1:] + "-" + yaml_modify[:i] + break + elif not item.isdigit() and item != "-": + yaml_file = yaml_file + yaml_modify[i:] + # yaml_file = yaml_modify[i + 1:] + yaml_modify[:i] + break + else: + yaml_file = yaml_file + ones[int(item)] + "-" + elif "+" in yaml_modify: + yaml_file = yaml_modify.replace("+", "plus") + else: + yaml_file = yaml_modify + print("----- yaml_modify ----") + print("*****{}****".format(yaml_modify)) + + if yaml_file not in allYamlList: + src_code_is.append(yaml_file) + print("-------- out of yaml file --------") + print(src_code_is) + continue + # elif yaml_file in allFileList and yaml_file.lower() not in allFileList: + # elif yaml_file in allFileList and yaml_file.lower() in allFileList: + # yaml_file = yaml_file.lower() + os.system("git clone 'https://gitee.com/src-oepkgs/{0}.git';".format(yaml_file)) + if not os.path.exists(real_path + yaml_file): + yaml_file = yaml_file.lower() + os.system("git clone 'https://gitee.com/src-oepkgs/{0}.git';".format(yaml_file)) + if not os.path.exists(real_path + yaml_file): + allYamldata.append(yaml_file) + #print("------ allYamldata {} 已添加 -----".format(yaml_file)) + continue + # time.sleep() + os.chdir(os.getcwd() + "/" + yaml_file) + commit_id = os.popen("git tag").read().strip() + + repo_branch = os.popen("git branch").read().strip() + if repo_branch == "": + #print("----- {} branch 不存在 -----".format(yaml_file)) + allYamldata_branch.append(yaml_file) + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + continue + if commit_id == "": + d_oepkg[yaml_file]=d[yaml_modify] + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + add_yaml = add_yaml + 1 + print("----- tag 不存在 -----") + print("------ {0} branch {1} 已添加 -----".format(yaml_file,add_yaml)) + else: + tag_list = commit_id.split("\n") + if "20.03-LTS-SP3" in [ i[:13] for i in tag_list]: + print("----- {} tag 已存在 -----".format(yaml_file)) + allYamldata_tag.append(yaml_file) + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + continue + else: + d_oepkg[yaml_file]=d[yaml_modify] + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + add_yaml = add_yaml + 1 + print("----- 20.03-LTS-SP3 存在 -----") + print("------ {0} branch {1} 已添加 -----".format(yaml_file,add_yaml)) + + with open("yaml_sp3.json", "w") as f: + f.write(json.dumps(d_oepkg)) + print("--------- yaml list -----------") + print(len(src_code_is)) + print(src_code_is) + print("--------- git list -----------") + print(len(allYamldata)) + print(allYamldata) + print("--------- branch list -----------") + print(len(allYamldata_branch)) + print(allYamldata_branch) + print("--------- tag list -----------") + print(len(allYamldata_tag)) + print(allYamldata_tag) + print("--------- d_oepkg list -----------") + print(len(d_oepkg)) + #print(allYamldata_tag) + print("---- end ----") + sys.exit() diff --git "a/tools/auto_creat_lib/add/\345\214\205\345\220\215\346\230\240\345\260\204\345\267\245\345\205\267.docx" "b/tools/auto_creat_lib/add/\345\214\205\345\220\215\346\230\240\345\260\204\345\267\245\345\205\267.docx" new file mode 100644 index 0000000000000000000000000000000000000000..76d986b895f9cec345b62ecd346a664bd32c8b4d Binary files /dev/null and "b/tools/auto_creat_lib/add/\345\214\205\345\220\215\346\230\240\345\260\204\345\267\245\345\205\267.docx" differ diff --git "a/tools/auto_creat_lib/add/\346\240\207\346\263\250\347\263\273\347\273\237\350\277\220\350\241\214\350\257\264\346\230\216.docx" "b/tools/auto_creat_lib/add/\346\240\207\346\263\250\347\263\273\347\273\237\350\277\220\350\241\214\350\257\264\346\230\216.docx" new file mode 100644 index 0000000000000000000000000000000000000000..2b2fb115524087fc987574190a2345fdc8637778 Binary files /dev/null and "b/tools/auto_creat_lib/add/\346\240\207\346\263\250\347\263\273\347\273\237\350\277\220\350\241\214\350\257\264\346\230\216.docx" differ diff --git a/tools/auto_creat_lib/auto_creat_lib.py b/tools/auto_creat_lib/auto_creat_lib.py new file mode 100644 index 0000000000000000000000000000000000000000..3ff723f2f89c2c166b3ab52b7a5c152f4353b2cd --- /dev/null +++ b/tools/auto_creat_lib/auto_creat_lib.py @@ -0,0 +1,400 @@ +# !/usr/bin/python3 +# -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import re +import requests +import time +from collections import defaultdict +from xml.etree.ElementTree import parse + +srcOepkgsNum = 0 +allFileNum = 0 +allFileList = [] # 存放 当前路径 以及当前路径的子路径 下的所有文件 +sigInfolist = [] +allYamlList = [] +rpm_info = {} +d = defaultdict(list) +d_oepkg = defaultdict(list) +dict_list = defaultdict(list) +rq_header = "curl -X POST --header 'Content-Type: application/json;charset=UTF-8'" +real_path = os.path.dirname(os.path.realpath(__file__)) + "/" + +group_dict = {"Amusements/Games": "multimedia/game", "Amusements/Graphics": "multimedia/graphics", + "Apache Software": "other/other", "Application": "other/other", + "Application/Development": "development environment/development environment", + "Application/Internet": "network/communications", "Application/System": "basic system/system tools", + "Applications": "other/other", "Applications/Archiving": "other/other", + "Applications/Communications": "network/", "Applications/Databases": "databases/databases", + "Applications/Development": "development environment/development tools", + "Applications/Editors": "development environment/auxiliary applications", + "Applications/Emulators": "hardware/emulation", "Applications/Engineering": "basic system/accelerator", + "Applications/File": "development environment/other", "Applications/Internet": "network/communications", + "Applications/Multimedia": "multimedia/audio", + "Applications/Productivity": "development environment/productization", + "Applications/Publishing": "development environment/publish", "Applications/Server": "middleware/server", + "Applications/System": "basic system/syetem tools", "Applications/Text": "development environment/other", + "Arch/Tech": "other/other", "Backup Server": "middleware/server", + "Development": "development environment/development environment", + "Development Documentation": "development environment/document", + "Development/Bioinformatics": "development environment/biological development", + "Development/C": "development environment/C", "Development/C++": "development environment/C++", + "Development/Data": "development environment/data", + "Development/Debug": "development environment/debugger", + "Development/Debuggers": "development environment/debugger", + "Development/Documentation": "development environment/document", + "Development/Java": "development environment/java", + "Development/Languages": "development environment/other", + "Development/Languages/Other": "development environment/other", + "Development/Languages/Python": "development environment/python", + "Development/Languages/C and C++": "evelopment environment/C++", + "Development/Libraries": "development environment/basic library", + "Development/Libraries/C and C++": "development environment/basic library", + "Development/Libraries/Python": "development environment/basic library", + "Development/Libraries/Java": "development environment/basic library", + "Google": "other/other", + "Development/Python": "development environment/python", + "Development/Ruby": "development environment/ruby", + "Development/System": "development environment/system", + "Development/Testing": "development environment/testing", + "Development/Tools": "development environment/tools", + "Development/Tools/Building": "development environment/build tools", + "Development/Tools/Debuggers": "development environment/debugger", + "Development/Tools/Other": "development environment/debugger/other", + "Development/Tools/Version Control": "development environment/version management", + "Distro/utilities": "development environment/publish", + "Distro/virtual": "development environment/publish", "Documentation": "development environment/document", + "Documentation/Man": "development environment/document", "Graphical desktop/Other": "desktop/graphics", + "Installation Script": "development environment/deployment", "LXQt": "desktop/graphics", + "Libraries": "basic system/basic library", "NONE": "other/other", + "Networking/Admin": "network/network management", "Networking/Daemons": "network/basic service", + "Networking/Diagnostic": "network/network diagnosis", + "OS Security": "development environment/security development", + "Productivity/Databases/Servers": "database/service", + "Productivity/Networking/Diagnostic": "network/network diagnosis", + "Productivity/Networking/Other": "network/other", "System Environment": "basic system/other", + "System Environment/Base": "basic system/basic library", + "System Environment/Daemons": "basic system/basic service", + "System Environment/Development": "development environment/development environment", + "System Environment/Development Tools": "development environment/tools", + "System Environment/Kernel": "other/other", "System Environment/Libraries": "basic system/basic library", + "System Environment/Shells": "basic system/basic tools", "System/Boot": "basic system/Initiate", + "System/Config": "basic system/config", "System/Daemons": "basic system/basic service", + "System/GUI/Other": "desktop/graphics", "System/I18n/Chinese": "basic system/standardization", + "System/Kernel": "other/other", "System/Libraries": "basic system/basic library", + "System/Management": "basic system/management", "System/Monitoring": "basic system/monitoring tools", + "Test": "development environment/testing", "Testing": "development environment/testing", + "development environment/testing": "development environment/developing plug-ins", + "Text Processing/Markup/HTML": "development environment/developing plug-ins", + "Text Processing/Markup/XML": "development environment/developing plug-ins", + "Tools/Docker": "virtualization/container", "Unspecified": "other/other", + "User Interface/Desktops": "desktop/graphical applications", + "User Interface/X": "desktop/graphics library", + "User Interface/X Hardware Support": "desktop/graphical basics", "Utilities": "basic system/other", + "Utilities/System": "other", "Utility/Libraries": "basic system/basic library", + "Virtualization/Management": "virtualization/virtualization management", + "__GROUP_SYS_BASE__": "other/other", "a": "other/other", "applications/database": "database/other", + "default": "other/other", "devel": "development environment/development", "hw.com": "other/other", + "testing": "development environment/testing", "xx.com": "other/other", "xxx.com": "other/other", + "????": "development environment/development framework"} + + +def getAllFilesInPath(path): + global allFileNum + curPathDirList = [] # 当前路径下的所有文件夹 + files = os.listdir(path) # 返回当前路径下的所有文件和文件夹 + for f in files: + if os.path.isdir(path + "/" + f): + if f[0] == ".": + pass # 排除隐藏文件夹 + else: + curPathDirList.append(f) # 添加非隐藏文件夹 + if os.path.isfile(path + "/" + f): + if f[-8:] == ".src.rpm": + allFileList.append(os.path.abspath(path + "/" + f)) # 添加文件 + allFileNum = allFileNum + 1 + # 总文件数+1 + if f[-5:] == ".yaml" and f != "sig-info.yaml": + yaml_name = f[:-5] + allYamlList.append(yaml_name) + + for dl in curPathDirList: + getAllFilesInPath(path + "/" + dl) # 递归获取当前目录下的文件夹内的文件 + + +# base64编码,文件创建api接口需要 +def base64_encode(path, group_dir, yaml_str): + with open(r"{}".format(path), 'r', encoding='utf-8') as f: + config = yaml.load(f.read().format(yaml_str.split("-+-")[0], yaml_str.split("-+-")[1], yaml_str.split("-+-")[2],yaml_str.split("-+-")[3]), Loader=yaml.FullLoader) + print(config) + encode_str = base64.b64encode(yaml.dump(config, allow_unicode=True, default_flow_style=False, sort_keys=False).encode('utf-8')).decode('utf-8') + print("{} 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_5/contents/sig%2F{}%2Fsrc-oepkgs%2F{}%2F{}.yaml' -d '{{\"access_token\":\"{}\",\"content\":\"{}\",\"message\":\"test\"}}'".format(rq_header, group_dir, str.lower(rpm_name[0]), rpm_name, api_token, encode_str)) + os.system("{} 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_5/contents/sig%2F{}%2Fsrc-oepkgs%2F{}%2F{}.yaml' -d '{{\"access_token\":\"{}\",\"content\":\"{}\",\"message\":\"test\"}}'".format(rq_header, group_dir, str.lower(rpm_name[0]), rpm_name, api_token, encode_str)) + print("--------- yaml_end ------------") + # return encode_str + + +# 获取rpm信息,拿到name和description +def shell_cmd(rpm_key, path): + rpm_info = os.popen("rpm -qi {}".format(path)) + for line in rpm_info.read().splitlines(): + rpm_value = line.split(":") + if rpm_value[0].strip() == rpm_key: + return rpm_value[1].strip() + + +# sig_info.yaml创建 +def sig_info(yaml_module, sig_name, yaml_name, group_secdir): + with open(r"{}".format(yaml_module), 'r', encoding='utf-8') as f: + config = yaml.load(f.read().format(sig_name), Loader=yaml.FullLoader) + print("------------------") + print(yaml_module) + print(config) + if yaml_module == "sig-info.yaml": + config['repositories'] = [{'repo': ['src-oepkgs/' + yaml_name], 'type': group_secdir}] + else: + print("111111111111111") + #print(sig_code_str) + type_str = [j for j,i in enumerate(config['repositories']) if i.get("type") == group_secdir] + print(type_str) + if len(type_str)==0: + config['repositories'].append({'repo': ['src-oepkgs/' + yaml_name], 'type': group_secdir}) + else: + config['repositories'][type_str[0]]['repo'].append("src-oepkgs/" + yaml_name) + return config + # encode_str = base64.b64encode(yaml.dump(config, allow_unicode=True, default_flow_style=False, sort_keys=False).encode('utf-8')).decode('utf-8') + # os.system("{} 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_5/contents/sig%2F{}%2Fsig-info.yaml' -d '{{\"access_token\":\"{}\",\"content\":\"{}\",\"message\":\"test\"}}'".format(rq_header, sig_name, api_token, encode_str)) + +def sig_info_add(sig_name,str_content): + print("--------- info ----------") + print("----------------") + print("https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_5/contents/sig%2F{}%2Fsig-info.yaml?access_token={}".format(sig_name, api_token)) + print("****************") + response_url = requests.get("https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_5/contents/sig%2F{}%2Fsig-info.yaml?access_token={}".format(sig_name, api_token), headers=headers) + pr_num = json.loads(response_url.text) + # data = {"access_token": api_token, "content": str_content, "sha": pr_num["sha"], "message": "test"} + # print("data:{}".format(data)) + # requests.put("https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_5/contents/sig%2F{}%2Fsig-info.yaml".format(sig_name), params=data, headers=headers) + # print("------- sig-info.yaml end --------") + print("curl -X PUT --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_5/contents/sig%2F{}%2Fsig-info.yaml' -d '{{\"access_token\":\"{}\", \"sha\":\"{}\", \"message\":\"test\"}}'".format(sig_name,api_token,pr_num["sha"])) + os.system("curl -X PUT --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_5/contents/sig%2F{}%2Fsig-info.yaml' -d '{{\"access_token\":\"{}\",\"content\":\"{}\", \"sha\":\"{}\", \"message\":\"test\"}}'".format(sig_name,api_token,str_content,pr_num["sha"])) +# def read_yaml(yaml_module, sig_name) +# with open(r"{}".format(yaml_module), 'r', encoding='utf-8') as f: +# config = yaml.load(f.read().format(sig_name), Loader=yaml.FullLoader) +# return config + +# 监听pr +def listen_event(pr_num): + response = requests.get( + "https://gitee.com/api/v5/repos/oepkgs/oepkgs-management_5/pulls/{0}/merge?access_token={1}".format(pr_num, + api_token), + headers=headers) + response_dict = json.loads(response.text) + if "Pull Request已经合并" in response_dict: + print("------------pr已合入-------------") + else: + time.sleep(600) + listen_event(pr_num) + + +def source_ocde(xmlfile): + Parse = parse(xmlfile) + root = Parse.getroot() + # print(root) + # sys.exit() + # print(root.findall("metadata")) + for child in root: + # print("*********") + # print(child.tag) + a = "" + b = "" + c = "" + for i in child: + if i.tag[39:] == "summary": + d = i.text + if i.tag[39:] == "name": + a = i.text + # print(a) + # sys.exit() + if i.tag[39:] == "format": + for j in i: + if j.tag[36:]=="license": + b = j.text + # print(b) + if j.tag[36:]=="group": + # print(c) + c = j.text + dict_list[a].append(b+"-*-"+c+"-*-"+d) + +a = {"Amusement/other":"multimedia/game","Amusements/Games/3D/Other":"multimedia/game","Amusements/Games/3D/Race":"multimedia/game","Amusements/Games/3D/Shoot":"multimedia","Amusements/Games/3D/Simulation":"multimedia","Amusements/Games/Action/Arcade":"multimedia","Amusements/Games/Action/Breakout":"multimedia","Amusements/Games/Action/Other":"multimedia","Amusements/Games/Action/Race":"multimedia","Amusements/Games/Action/Shoot":"multimedia","Amusements/Games/Board/Card":"multimedia","Amusements/Games/Board/Chess":"multimedia","Amusements/Games/Board/Other":"multimedia","Amusements/Games/Board/Pool":"multimedia","Amusements/Games/Board/Puzzle":"multimedia","Amusements/Games/Logic":"multimedia","Amusements/Games/Other":"multimedia","Amusements/Games/RPG":"multimedia","Amusements/Games/Strategy/Other":"multimedia","Amusements/Games/Strategy/Real Time":"multimedia","Amusements/Games/Strategy/Turn Based":"multimedia","Amusements/Teaching/Language":"multimedia","Amusements/Teaching/Mathematics":"multimedia","Amusements/Teaching/Other":"multimedia","Amusements/Toys/Background":"multimedia","Amusements/Toys/Clocks":"multimedia","Amusements/Toys/Graphics":"multimedia","Amusements/Toys/Other":"multimedia","Amusements/Toys/Screensavers":"multimedia","Development/Languages/C and C++":"developmentenvironment","Development/Languages/Fortran":"developmentenvironment","Development/Languages/Go":"developmentenvironment","Development/Languages/Haskell":"developmentenvironment","Development/Languages/Java":"developmentenvironment","Development/Languages/Lua":"developmentenvironment","Development/Languages/NodeJS":"developmentenvironment","Development/Languages/OCaml":"developmentenvironment","Development/Languages/Other":"developmentenvironment","Development/Languages/Perl":"developmentenvironment","Development/Languages/PHP":"developmentenvironment","Development/Languages/Python":"developmentenvironment","Development/Languages/Ruby":"developmentenvironment","Development/Languages/Rust":"developmentenvironment","Development/Languages/Scheme":"developmentenvironment","Development/Languages/Tcl":"developmentenvironment","Development/Languages/Perl *.spec -> 29":"developmentenvironment","Development/Libraries/Perl *.spec -> 1127":"developmentenvironment","Development/Languages/Python *.spec -> 1190":"developmentenvironment","Development/Libraries/Python *.spec -> 404":"developmentenvironment","Development/Libraries/C and C++":"developmentenvironment","Development/Libraries/Cross":"developmentenvironment","Development/Libraries/GNOME":"basicsystem","Development/Libraries/Haskell":"developmentenvironment","Development/Libraries/Java":"developmentenvironment","Development/Libraries/KDE":"basicsystem","Development/Libraries/Other":"basicsystem","Development/Libraries/Parallel":"basicsystem","Development/Libraries/Perl":"developmentenvironment","Development/Libraries/PHP":"developmentenvironment","Development/Libraries/Python":"developmentenvironment","Development/Libraries/Rust":"developmentenvironment","Development/Libraries/Tcl":"developmentenvironment","Development/Libraries/X11":"basicsystem","Development/Libraries/YaST":"basicsystem","Development/Tools/Building":"developmentenvironment","Development/Tools/Debuggers":"developmentenvironment","Development/Tools/Doc Generators":"developmentenvironment","Development/Tools/GUI Builders":"developmentenvironment","Development/Tools/IDE":"developmentenvironment","Development/Tools/Navigators":"developmentenvironment","Development/Tools/Other":"developmentenvironment","Development/Tools/Version Control":"developmentenvironment","Hardware/Camera":"hardware","Hardware/Fax":"hardware","Hardware/ISDN":"hardware","Hardware/Joystick":"hardware","Hardware/Mobile":"hardware","Hardware/Modem":"hardware","Hardware/Other":"hardware","Hardware/Palm":"hardware","Hardware/Printing":"hardware","Hardware/Psion":"hardware","Hardware/Radio":"hardware","Hardware/Scanner":"hardware","Hardware/TV":"hardware","Hardware/UPS":"hardware","Hardware/Wifi":"hardware","Meta packages":"hardware","Multimedia":"multimedia","Productivity/Archiving/Backup":"middleware","Productivity/Archiving/Compression":"middleware","Productivity/Clustering/Computing":"middleware","Productivity/Clustering/HA":"middleware","Productivity/Databases/Clients":"database","Productivity/Databases/Servers":"middleware","Productivity/Databases/Tools":"middleware","File utilities":"middleware","Productivity/File utilities":"middleware","Graphics":"multimedia","Productivity/Graphics/3D Editors":"multimedia","Productivity/Graphics/Bitmap Editors":"multimedia","Productivity/Graphics/CAD":"multimedia","Productivity/Graphics/Convertors (Converters?)":"multimedia","Productivity/Graphics/Other":"multimedia","Productivity/Graphics/Vector Editors":"multimedia","Productivity/Graphics/Viewers":"multimedia","Productivity/Graphics/Visualization/Graph":"multimedia","Productivity/Graphics/Visualization/Other":"multimedia","Productivity/Graphics/Visualization/Raytracers":"multimedia","Hamradio":"middleware","Productivity/Hamradio/Fax":"middleware","Productivity/Hamradio/Logging":"middleware","Productivity/Hamradio/Morse":"middleware","Productivity/Hamradio/Other":"middleware","Productivity/Hamradio/Packet":"middleware","Productivity/Hamradio/Psk31":"middleware","Productivity/Hamradio/Satellite":"middleware","Productivity/Multimedia/CD/Grabbers":"multimedia","Productivity/Multimedia/CD/Players":"multimedia","Productivity/Multimedia/CD/Record":"multimedia","Productivity/Multimedia/Other":"multimedia","Productivity/Multimedia/Sound/Editors and Convertors":"multimedia","Productivity/Multimedia/Sound/Midi":"multimedia","Productivity/Multimedia/Sound/Mixers":"multimedia","Productivity/Multimedia/Sound/Players":"multimedia","Productivity/Multimedia/Sound/Utilities":"multimedia","Productivity/Multimedia/Sound/Visualization":"multimedia","Productivity/Multimedia/Video/Editors and Convertors":"multimedia","Productivity/Multimedia/Video/Players":"multimedia","Networking":"multimedia","Productivity/Networking/AOLInstantMessenger":"network","Productivity/Networking/Archie":"network","Productivity/Networking/Boot/Clients":"network","Productivity/Networking/Boot/Servers":"network","Productivity/Networking/Boot/Utilities":"network","Productivity/Networking/Diagnostic":"network","Productivity/Networking/DNS/Servers":"network","Productivity/Networking/DNS/Utilities":"network","Productivity/Networking/Email/Clients":"network","Productivity/Networking/Email/Mailinglists":"network","Productivity/Networking/Email/Servers":"network","Productivity/Networking/Email/Utilities":"network","Productivity/Networking/File-Sharing":"network","Productivity/Networking/Ftp/Clients":"network","Productivity/Networking/Ftp/Servers":"network","Productivity/Networking/ICQ":"network","Productivity/Networking/Instant Messenger":"network","Productivity/Networking/IRC":"network","Productivity/Networking/LDAP/Clients":"network","Productivity/Networking/LDAP/Servers":"network","Productivity/Networking/LDAP/Utilities":"network","Productivity/Networking/Napster":"network","Productivity/Networking/News/Clients":"network","Productivity/Networking/News/Servers":"network","Productivity/Networking/News/Utilities":"network","Productivity/Networking/NFS":"network","Productivity/Networking/NIS":"network","Productivity/Networking/Novell":"network","Productivity/Networking/Other":"network","Productivity/Networking/PPP":"network","Productivity/Networking/Radius/Clients":"network","Productivity/Networking/Radius/Servers":"network","Productivity/Networking/Routing":"network","Productivity/Networking/Samba":"network","Productivity/Networking/Security":"network","Productivity/Networking/SSH":"network","Productivity/Networking/System":"network","Productivity/Networking/Talk/Clients":"network","Productivity/Networking/Talk/Servers":"network","Productivity/Networking/Web/Browsers":"network","Productivity/Networking/Web/Frontends":"network","Productivity/Networking/Web/Proxy":"network","Productivity/Networking/Web/Servers":"network","Productivity/Networking/Web/Utilities":"network","Productivity/Office/Dictionary":"desktop","Productivity/Office/Finance":"desktop","Productivity/Office/Management":"desktop","Productivity/Office/Organizers":"desktop","Productivity/Office/Other":"desktop","Productivity/Office/Spreadsheets":"desktop","Productivity/Office/Suite":"desktop","Productivity/Office/Word Processor":"desktop","Productivity/Other":"desktop","Productivity/Publishing/DocBook":"basicsystem","Productivity/Publishing/HTML/Editors":"basicsystem","Productivity/Publishing/HTML/Tools":"basicsystem","Productivity/Publishing/Other":"basicsystem","Productivity/Publishing/PDF":"basicsystem","Productivity/Publishing/Presentation":"basicsystem","Productivity/Publishing/PS":"basicsystem","Productivity/Publishing/SGML":"basicsystem","Productivity/Publishing/TeX/Base":"basicsystem","Productivity/Publishing/TeX/Fonts":"basicsystem","Productivity/Publishing/TeX/Frontends":"basicsystem","Productivity/Publishing/TeX/Utilities":"basicsystem","Productivity/Publishing/Texinfo":"basicsystem","Productivity/Publishing/Troff":"basicsystem","Productivity/Publishing/Word":"basicsystem","Productivity/Publishing/XML":"basicsystem","Productivity/Scientific/Astronomy":"middleware","Productivity/Scientific/Chemistry":"middleware","Productivity/Scientific/Electronics":"middleware","Productivity/Scientific/Math":"middleware","Productivity/Scientific/Other":"middleware","Productivity/Scientific/Physics":"middleware","Productivity/Security":"middleware","Productivity/Telephony/Clients":"middleware","Productivity/Telephony/H323/Clients":"middleware","Productivity/Telephony/H323/Servers":"middleware","Productivity/Telephony/H323/Utilities":"middleware","Productivity/Telephony/Servers":"middleware","Productivity/Telephony/SIP/Clients":"middleware","Productivity/Telephony/SIP/Servers":"middleware","Productivity/Telephony/SIP/Utilities":"middleware","Productivity/Telephony/Utilities":"middleware","Productivity/Text/Convertors":"middleware","Productivity/Text/Editors":"middleware","Productivity/Text/Spell":"middleware","Productivity/Text/Utilities":"middleware","System/Emulators/Other":"hardware","System/Emulators/PC":"hardware","GUI":"desktop","System/GUI/GNOME":"desktop","System/GUI/KDE":"desktop","System/GUI/LXDE":"desktop","System/GUI/Other":"desktop","System/GUI/XFCE":"desktop","System/I18n/Chinese":"basicsystem","System/I18n/Japanese":"basicsystem","System/I18n/Korean":"basicsystem","X11":"desktop","System/X11/Displaymanagers":"desktop","System/X11/Fonts":"desktop","System/X11/Icons":"desktop","System/X11/Servers/XF86_3":"desktop","System/X11/Servers/XF86_4":"desktop","System/X11/Terminals":"desktop","System/X11/Utilities":"desktop","YaST":"systemtools","System/YaST":"systemtools","Internationalization (I18N)":""} + + + +if __name__ == '__main__': + # 读取rpm包名存入列表内 + # rpm_pkg_path = input("请输入要获取的rpm包目录:") + # api_token = input("请输入api的token:") + headers = {"Content-Type": "application/json;charset=UTF-8"} + rpm_pkg_path = "/srv/rpm/pub/openeuler-22.03-LTS/" + #rpm_pkg_path = "contrib" + api_token = "a52c89251c94583ab0288d86c9711bb8" + # 取rpm包总数和rpm文件绝对路径 + getAllFilesInPath(rpm_pkg_path) + print("当前路径下的总文件数 =", allFileNum) + for rpm_path in allFileList: + rpm_file = shell_cmd("Name", rpm_path) # 获取rpm信息 + d[rpm_file].append(rpm_path) + os.system("git clone 'https://gitee.com/zhang-yn/oepkgs-management_5.git';") + # 获取src-oepkgs上已经存在的库,通过yaml文件获取 + getAllFilesInPath("./oepkgs-management_5/sig") + # 判断取到的rpm文件是否在舱内已经存在,进行过滤 + for i in allYamlList: + if i in d.keys(): + d.pop(i) + print("-----*****-----") + print(len(d.keys())) + #sys.exit() + # 遍历字典进行yaml创建 + for yaml_modify in d: + yaml_file = "" + if yaml_modify[0].isdigit(): + for i, item in enumerate(yaml_modify): + if not item.isdigit() and item == "-": + yaml_file = yaml_modify[i + 1:] + "-" + yaml_modify[:i] + break + elif not item.isdigit() and item != "-": + yaml_file = yaml_modify[i + 1:] + yaml_modify[:i] + break + else: + yaml_file = yaml_modify + if yaml_modify in dict_list.keys(): + group_str = dict_list[yaml_modify][0].split("-*-")[0] + des_str = dict_list[yaml_modify][0].split("-*-")[2] + license_str = dict_list[yaml_modify][0].split("-*-")[1] + if group_str in a.keys(): + d_oepkg[a[group_str]].append(yaml_file+"-+-"+des_str+"-+-"+license_str+"-+-"+group_str) + # if yaml_modify[0].isdigit(): + # pass + else: + group_str = shell_cmd("Group", d[yaml_modify][0]) + license_str = shell_cmd("License", d[yaml_modify][0]) + des_str = "" + rpm_str = shell_cmd("Summary", d[yaml_modify][0]) + for str_dig in rpm_str.split(" "): + str_dig = "".join(filter(str.isalpha, str_dig)) + des_str = des_str + str_dig + " " + if group_str in group_dict.keys(): + d_oepkg[group_dict[group_str]].append(yaml_file+"-+-"+des_str+"-+-"+license_str+"-+-"+group_str) + print(d_oepkg) + for d_oepkg_key in d_oepkg.keys(): + group_dir = d_oepkg_key.split("/", 1)[0].replace(" ","") + group_secdir = d_oepkg_key.split("/", 1)[1] + sig_code_str = {} + if not os.path.exists(real_path +"/oepkgs-management_5/sig/{}/sig_info.yaml".format(group_dir)): + for i, item in enumerate(d_oepkg[d_oepkg_key]): + print("44-------------------") + print(real_path +"oepkgs-management_5/sig/{}/sig_info.yaml".format(group_dir)) + #print(d_oepkg[d_oepkg_key]) + print("222--------------") + if i == 0: + print("bbbbbbb-----------ddddddddddd") + sig_code_str = sig_info("sig-info.yaml", group_dir, item.split("-+-")[0], group_secdir) + print(sig_code_str) + print("dddddd-------------------bbbbb") + base64_encode("./test.yaml", group_dir, item) + else: + print("333------------------") + # type_str = [sig_code_str['repositories'].index(i) for i in sig_code_str['repositories'] if i.get("type") == group_secdir] + # if not type_str: + # sig_code_str['repositories'].append({'repo': ['src-oepkgs/' + str.lower(item.split("-+-")[0])], 'type': group_secdir}) + # else: + + sig_code_str['repositories'][0]['repo'].append("src-oepkgs/" + item.split("-+-")[0]) + base64_encode("./test.yaml", group_dir, item) + #print(sig_code_str) + print("---------sig_code_str----------") + print(sig_code_str) + code_str = base64.b64encode(yaml.dump(sig_code_str, allow_unicode=True, default_flow_style=False, sort_keys=False).encode('utf-8')).decode('utf-8') + os.system("{} 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_5/contents/sig%2F{}%2Fsig-info.yaml' -d '{{\"access_token\":\"{}\",\"content\":\"{}\",\"message\":\"test\"}}'".format(rq_header, group_dir, api_token, code_str)) + print("---------sig_code_str end----------") + else: + for j, items in enumerate(d_oepkg[d_oepkg_key]): + print("dddddd-------------------") + if j == 0: + sig_code_str = sig_info("./oepkgs-management_5/sig/{}/sig-info.yaml".format(group_dir), group_dir, items.split("/", 1)[0], group_secdir) + print("-------000000-------") + print(sig_code_str) + base64_encode("./test.yaml", group_dir, items) + else: + print(sig_code_str) + print("------22222222-------") + base64_encode("./test.yaml", group_dir, items) + type_str = [j for j,i in enumerate(sig_code_str['repositories']) if i.get("type") == group_secdir] + if len(type_str)==0: + sig_code_str['repositories'].append({'repo': ['src-oepkgs/' + items.split("/", 1)[0]], 'type': group_secdir}) + else: + sig_code_str['repositories'][type_str[0]]['repo'].append( "src-oepkgs/" + items.split("/", 1)[0]) + print("dddddd-------------------") + code_str = base64.b64encode(yaml.dump(sig_code_str, allow_unicode=True, default_flow_style=False, sort_keys=False).encode('utf-8')).decode('utf-8') + sig_info_add(group_dir, code_str) + + print("---------------") + print("配置文件创建完成") + sys.exit() + + # 创建pr + data = {"access_token": api_token, "title": "自动化创建库", "head": "zhang-yn:master", "base": "master"} + response = requests.post("https://gitee.com/api/v5/repos/oepkgs/oepkgs-management_5/pulls", params=data, + headers = headers) + pr_num = json.loads(response.text)["number"] + print(pr_num) + listen_event(pr_num) + + rq_header = "curl -X POST --header 'Content-Type: application/json;charset=UTF-8'" + api_token = "84ecf3c63f2b49cf2b809cba3e2ba091" + for lib_name in d: + # fork仓库 + os.system("{} 'https://gitee.com/api/v5/repos/src-oepkgs/{}/forks' -d '{{\"access_token\":\"{}\"}}'".format(rq_header, + lib_name, + api_token)) + module_name = d[lib_name] + for rpm_path in module_name: + rpm_version = rpm_path.split("/")[-1][:-8][len(lib_name) + 1:] + # 解压rpm,git commit + if not os.path.exists(lib_name): + os.system( + "git clone 'https://gitee.com/zhang-yn/{0}.git';cd {0};pwd;rm -rf *;rpm2cpio {1} | cpio -div;git add .;git commit -m '{2}';git push".format( + lib_name, rpm_path, rpm_version)) + print( + "git clone 'https://gitee.com/zhang-yn/{0}.git';cd {0};rm -rf README.*;rpm2cpio {1} | cpio -div;git add .;git commit -m '{2}';git push".format( + lib_name, rpm_path, rpm_version)) + else: + os.system( + "cd {0};rm -rf *;rpm2cpio {1} | cpio -div;git add .;git commit -m '{2}';git push".format(lib_name, + rpm_path, + rpm_version)) + +# 创建pr +data = {"access_token": api_token, "title": "自动化创建库", "head": "zhang-yn:master", +"base": "openEuler-22.03-LTS"} +response = requests.post("https://gitee.com/api/v5/repos/wwccyang/{}/pulls".format(lib_name), params=data, +headers = rq_header) + +# 取commit信息,打tag +response_url = requests.get( +"https://gitee.com/api/v5/repos/src-oepkgs/{}/commits?access_token={}=master&page=1&per_page=20".format( + lib_name, api_token), headers = rq_header) +pr_num = json.loads(response_url.text) +for i in range(1, len(d[lib_name]) + 1): + print("********************") +print(pr_num[i]["sha"]) +commit_id = pr_num[i]["sha"] +tag_str = pr_num[i]["commit"]["message"] +os.system( +"{} 'https://gitee.com/api/v5/repos/zhang-yn/{}/tags' -d '{{\"access_token\":\"{}\",\"refs\":\"{}\",\"tag_name\":\"{}\"}}'".format( + rq_header, lib_name, api_token, commit_id, "22.0-" + tag_str)) + \ No newline at end of file diff --git a/tools/auto_creat_lib/creat_file.py b/tools/auto_creat_lib/creat_file.py new file mode 100644 index 0000000000000000000000000000000000000000..52b17d04326a58b762b519352187bcb26c848bda --- /dev/null +++ b/tools/auto_creat_lib/creat_file.py @@ -0,0 +1,592 @@ +# !/usr/bin/python3 +# -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import re +import requests +import time +from collections import defaultdict +from xml.etree.ElementTree import parse +import copy + +srcOepkgsNum = 0 +allFileNum = 0 +allFileList = [] # 存放 当前路径 以及当前路径的子路径 下的所有文件 +sigInfolist = [] +allYamlList = [] +yaml_liu = [] +rpm_info = {} +d = defaultdict(list) +d_oepkg = defaultdict(list) +dict_list = defaultdict(list) +rq_header = "curl -X POST --header 'Content-Type: application/json;charset=UTF-8'" +real_path = os.path.dirname(os.path.realpath(__file__)) + "/" +ones = {1: "one", 2: "two", 3: "three", 4: "four", + 5: "five", 6: "six", 7: "seven", 8: "eight", + 9: "nine", 0: "zero"} + +group_dict = {"Amusements/Games": "multimedia/game", "Amusements/Graphics": "multimedia/graphics", + "Apache Software": "other/other", "Application": "other/other", + "Application/Development": "development environment/development environment", + "Application/Internet": "network/communications", "Application/System": "basic system/system tools", + "Applications": "other/other", "Applications/Archiving": "other/other", + "Applications/Communications": "network/", "Applications/Databases": "databases/databases", + "Applications/Development": "development environment/development tools", + "Applications/Editors": "development environment/auxiliary applications", + "Applications/Emulators": "hardware/emulation", "Applications/Engineering": "basic system/accelerator", + "Applications/File": "development environment/other", "Applications/Internet": "network/communications", + "Applications/Multimedia": "multimedia/audio", + "Applications/Productivity": "development environment/productization", + "Applications/Publishing": "development environment/publish", "Applications/Server": "middleware/server", + "Applications/System": "basic system/syetem tools", "Applications/Text": "development environment/other", + "Arch/Tech": "other/other", "Backup Server": "middleware/server", + "Development": "development environment/development environment", + "Development Documentation": "development environment/document", + "Development/Bioinformatics": "development environment/biological development", + "Development/C": "development environment/C", "Development/C++": "development environment/C++", + "Development/Data": "development environment/data", + "Development/Debug": "development environment/debugger", + "Development/Debuggers": "development environment/debugger", + "Development/Documentation": "development environment/document", + "Development/Java": "development environment/java", + "Development/Languages": "development environment/other", + "Development/Languages/Other": "development environment/other", + "Development/Languages/Python": "development environment/python", + "Development/Languages/C and C++": "development environment/C++", + "Development/Libraries": "development environment/basic library", + "Development/Libraries/C and C++": "development environment/basic library", + "Development/Libraries/Python": "development environment/basic library", + "Development/Libraries/Java": "development environment/basic library", + "Google": "other/other", + "Development/Python": "development environment/python", + "Development/Ruby": "development environment/ruby", + "Development/System": "development environment/system", + "Development/Testing": "development environment/testing", + "Development/Tools": "development environment/tools", + "Development/Tools/Building": "development environment/build tools", + "Development/Tools/Debuggers": "development environment/debugger", + "Development/Tools/Other": "development environment/debugger/other", + "Development/Tools/Version Control": "development environment/version management", + "Distro/utilities": "development environment/publish", + "Distro/virtual": "development environment/publish", "Documentation": "development environment/document", + "Documentation/Man": "development environment/document", "Graphical desktop/Other": "desktop/graphics", + "Installation Script": "development environment/deployment", "LXQt": "desktop/graphics", + "Libraries": "basic system/basic library", "NONE": "other/other", + "Networking/Admin": "network/network management", "Networking/Daemons": "network/basic service", + "Networking/Diagnostic": "network/network diagnosis", + "OS Security": "development environment/security development", + "Productivity/Databases/Servers": "database/service", + "Productivity/Networking/Diagnostic": "network/network diagnosis", + "Productivity/Networking/Other": "network/other", "System Environment": "basic system/other", + "System Environment/Base": "basic system/basic library", + "System Environment/Daemons": "basic system/basic service", + "System Environment/Development": "development environment/development environment", + "System Environment/Development Tools": "development environment/tools", + "System Environment/Kernel": "other/other", "System Environment/Libraries": "basic system/basic library", + "System Environment/Shells": "basic system/basic tools", "System/Boot": "basic system/Initiate", + "System/Config": "basic system/config", "System/Daemons": "basic system/basic service", + "System/GUI/Other": "desktop/graphics", "System/I18n/Chinese": "basic system/standardization", + "System/Kernel": "other/other", "System/Libraries": "basic system/basic library", + "System/Management": "basic system/management", "System/Monitoring": "basic system/monitoring tools", + "Test": "development environment/testing", "Testing": "development environment/testing", + "development environment/testing": "development environment/developing plug-ins", + "Text Processing/Markup/HTML": "development environment/developing plug-ins", + "Text Processing/Markup/XML": "development environment/developing plug-ins", + "Tools/Docker": "virtualization/container", "Unspecified": "other/other", + "User Interface/Desktops": "desktop/graphical applications", + "User Interface/X": "desktop/graphics library", + "User Interface/X Hardware Support": "desktop/graphical basics", "Utilities": "basic system/other", + "Utilities/System": "other/other", "Utility/Libraries": "basic system/basic library", + "Virtualization/Management": "virtualization/virtualization management", + "__GROUP_SYS_BASE__": "other/other", "a": "other/other", "applications/database": "database/other", + "default": "other/other", "devel": "development environment/development", "hw.com": "other/other", + "testing": "development environment/testing", "xx.com": "other/other", "xxx.com": "other/other", + "????": "development environment/development framework"} + + +def getAllFilesInPath(path): + global allFileNum + curPathDirList = [] # 当前路径下的所有文件夹 + files = os.listdir(path) # 返回当前路径下的所有文件和文件夹 + for f in files: + if os.path.isdir(path + "/" + f): + if f[0] == ".": + pass # 排除隐藏文件夹 + else: + curPathDirList.append(f) # 添加非隐藏文件夹 + if os.path.isfile(path + "/" + f): + if f[-8:] == ".src.rpm": + allFileList.append(os.path.abspath(path + "/" + f)) # 添加文件 + allFileNum = allFileNum + 1 + # 总文件数+1 + if f[-5:] == ".yaml" and f != "sig-info.yaml": + yaml_name = f[:-5] + allYamlList.append(yaml_name) + + for dl in curPathDirList: + getAllFilesInPath(path + "/" + dl) # 递归获取当前目录下的文件夹内的文件 + + +# base64编码,文件创建api接口需要 +def base64_encode(path, group_dir, yaml_str): + with open(r"{}".format(path), 'r', encoding='utf-8') as f: + config = yaml.load(f.read().format(yaml_str.split("-+-")[0], yaml_str.split("-+-")[1], yaml_str.split("-+-")[2], + yaml_str.split("-+-")[3]), Loader=yaml.FullLoader) + print(config) + encode_str = base64.b64encode( + yaml.dump(config, allow_unicode=True, default_flow_style=False, sort_keys=False).encode('utf-8')).decode( + 'utf-8') + print( + "{} 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_1/contents/sig%2F{}%2Fsrc-oepkgs%2F{}%2F{}.yaml' -d '{{\"access_token\":\"{}\",\"content\":\"{}\",\"message\":\"test\"}}'".format( + rq_header, group_dir, yaml_str.split("-+-")[0][0], yaml_str.split("-+-")[0], api_token, encode_str)) + os.system( + "{} 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_1/contents/sig%2F{}%2Fsrc-oepkgs%2F{}%2F{}.yaml' -d '{{\"access_token\":\"{}\",\"content\":\"{}\",\"message\":\"test\"}}'".format( + rq_header, group_dir, yaml_str.split("-+-")[0][0], yaml_str.split("-+-")[0], api_token, encode_str)) + print("--------- yaml_end ------------") + # return encode_str + + +# 获取rpm信息,拿到name和description +def shell_cmd(rpm_key, path): + rpm_info = os.popen("rpm -qi {}".format(path)) + for line in rpm_info.read().splitlines(): + rpm_value = line.split(":") + if rpm_value[0].strip() == rpm_key: + return rpm_value[1].strip() + + +# sig_info.yaml创建 +def sig_info(yaml_module, sig_name, yaml_name, group_secdir): + with open(r"{}".format(yaml_module), 'r', encoding='utf-8') as f: + config = yaml.load(f.read().format(sig_name), Loader=yaml.FullLoader) + print("------------------") + print(yaml_module) + print(config) + if yaml_module == "sig-info.yaml": + config['repositories'] = [{'repo': ['src-oepkgs/' + yaml_name], 'type': group_secdir}] + else: + print("111111111111111") + # print(sig_code_str) + type_str = [j for j, i in enumerate(config['repositories']) if i.get("type") == group_secdir] + print(type_str) + if len(type_str) == 0: + config['repositories'].append({'repo': ['src-oepkgs/' + yaml_name], 'type': group_secdir}) + else: + config['repositories'][type_str[0]]['repo'].append("src-oepkgs/" + yaml_name) + return config + # encode_str = base64.b64encode(yaml.dump(config, allow_unicode=True, default_flow_style=False, sort_keys=False).encode('utf-8')).decode('utf-8') + # os.system("{} 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_1/contents/sig%2F{}%2Fsig-info.yaml' -d '{{\"access_token\":\"{}\",\"content\":\"{}\",\"message\":\"test\"}}'".format(rq_header, sig_name, api_token, encode_str)) + + +def sig_info_add(sig_name, str_content): + print("--------- info ----------") + print("----------------") + print( + "https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_1/contents/sig%2F{}%2Fsig-info.yaml?access_token={}".format( + sig_name, api_token)) + print("****************") + response_url = requests.get( + "https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_1/contents/sig%2F{}%2Fsig-info.yaml?access_token={}".format( + sig_name, api_token), headers=headers) + pr_num = json.loads(response_url.text) + # data = {"access_token": api_token, "content": str_content, "sha": pr_num["sha"], "message": "test"} + # print("data:{}".format(data)) + # requests.put("https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_1/contents/sig%2F{}%2Fsig-info.yaml".format(sig_name), params=data, headers=headers) + # print("------- sig-info.yaml end --------") + print( + "curl -X PUT --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_1/contents/sig%2F{}%2Fsig-info.yaml' -d '{{\"access_token\":\"{}\", \"sha\":\"{}\", \"message\":\"test\"}}'".format( + sig_name, api_token, pr_num["sha"])) + os.system( + "curl -X PUT --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_1/contents/sig%2F{}%2Fsig-info.yaml' -d '{{\"access_token\":\"{}\",\"content\":\"{}\", \"sha\":\"{}\", \"message\":\"test\"}}'".format( + sig_name, api_token, str_content, pr_num["sha"])) + + +# def read_yaml(yaml_module, sig_name) +# with open(r"{}".format(yaml_module), 'r', encoding='utf-8') as f: +# config = yaml.load(f.read().format(sig_name), Loader=yaml.FullLoader) +# return config + +# 监听pr +def listen_event(pr_num): + response = requests.get( + "https://gitee.com/api/v5/repos/oepkgs/oepkgs-management_1/pulls/{0}/merge?access_token={1}".format(pr_num, + api_token), + headers=headers) + response_dict = json.loads(response.text) + if "Pull Request已经合并" in response_dict: + print("------------pr已合入-------------") + else: + time.sleep(600) + listen_event(pr_num) + + +def source_ocde(xmlfile): + Parse = parse(xmlfile) + root = Parse.getroot() + for child in root: + a = "" + b = "" + c = "" + for i in child: + if i.tag[39:] == "summary": + d = i.text + if i.tag[39:] == "name": + a = i.text + if i.tag[39:] == "format": + for j in i: + if j.tag[36:] == "license": + b = j.text + # print(b) + if j.tag[36:] == "group": + # print(c) + c = j.text + dict_list[a].append(b + "-*-" + c + "-*-" + d) + # print(dict_list) + + +a = {"Amusement/other": "multimedia/game", "Amusements/Games/3D/Other": "multimedia/game", + "Amusements/Games/3D/Race": "multimedia/game", "Amusements/Games/3D/Shoot": "multimedia/game", + "Amusements/Games/3D/Simulation": "multimedia/game", "Amusements/Games/Action/Arcade": "multimedia/game", + "Amusements/Games/Action/Breakout": "multimedia/game", "Amusements/Games/Action/Other": "multimedia/game", + "Amusements/Games/Action/Race": "multimedia/game", "Amusements/Games/Action/Shoot": "multimedia/game", + "Amusements/Games/Board/Card": "multimedia/game", "Amusements/Games/Board/Chess": "multimedia/game", + "Amusements/Games/Board/Other": "multimedia/game", "Amusements/Games/Board/Pool": "multimedia/game", + "Amusements/Games/Board/Puzzle": "multimedia/game", "Amusements/Games/Logic": "multimedia/game", + "Amusements/Games/Other/game": "multimedia/game", "Amusements/Games/RPG": "multimedia/game", + "Amusements/Games/Strategy/Other": "multimedia/game", "Amusements/Games/Strategy/Real Time": "multimedia/game", + "Amusements/Games/Strategy/Turn Based": "multimedia/game", "Amusements/Teaching/Language": "multimedia/teaching", + "Amusements/Teaching/Mathematics": "multimedia/teaching", "Amusements/Teaching/Other": "multimedia/teaching", + "Amusements/Toys/Background": "multimedia/tools", "Amusements/Toys/Clocks": "multimedia/tools", + "Amusements/Toys/Graphics": "multimedia/tools", "Amusements/Toys/Other": "multimedia/tools", + "Amusements/Toys/Screensavers": "multimedia/tools", + "Development/Languages/C and C++": "development environment/C++", + "Development/Languages/Fortran": "development environment/Forgtran Development", + "Development/Languages/Go": "development environment/go development", + "Development/Languages/Haskell": "development environment/Haskell development", + "Development/Languages/Java": "development environment/java development", + "Development/Languages/Lua": "development environment/lua development", + "Development/Languages/NodeJS": "development environment/nodejs development", + "Development/Languages/OCaml": "development environment/0caml development", + "Development/Languages/Other": "development environment/other development", + "Development/Languages/perl": "development environment/perl development", + "Development/Languages/PHP": "development environment/php development", + "Development/Languages/Python": "development environment/python development", + "Development/Languages/Ruby": "development environment/ruby development", + "Development/Languages/Rust": "development environment/rust development", + "Development/Languages/Scheme": "development environment/scheme development", + "Development/Languages/Tcl": "developm entenvironment/tc1 development", + "Development/Languages/perl *.spec -> 29": "development environment/perl development", + "Development/Libraries/perl *.spec -> 1127": "development environment/Development Library", + "Development/Languages/Python *.spec -> 1190": "development environment/python development", + "Development/Libraries/Python *.spec -> 404": "development environment/Development Library", + "Development/Libraries/C and C++": "development environment/c development", + "Development/Libraries/Cross": "development environment/Development Library", + "Development/Libraries/GNOME": "basic system/Basic library", + "Development/Libraries/Haskell": "development environment/Haskell development", + "Development/Libraries/Java": "development environment/java development", + "Development/Libraries/KDE": "basic system/Basic library", + "Development/Libraries/Other": "basic system/Basic library", + "Development/Libraries/Parallel": "basic system/Basic library", + "Development/Libraries/perl": "development environment/perl development", + "Development/Libraries/PHP": "development environment/php development", + "Development/Libraries/Python": "development environment/python development", + "Development/Libraries/Rust": "development environment/ruby development", + "Development/Libraries/Tcl": "development environment/tcl development", + "Development/Libraries/X11": "basic system/Basic library", + "Development/Libraries/YaST": "basic system/Basic library", + "Development/Tools/Building": "development environment/tools", + "Development/Tools/Debuggers": "development environment/tools", + "Development/Tools/Doc Generators": "development environment/tools", + "Development/Tools/GUI Builders": "development environment/tools", + "Development/Tools/IDE": "development environment/tools", + "Development/Tools/Navigators": "development environment/tools", + "Development/Tools/Other": "development environment/tools", + "Development/Tools/Version Control": "development environment/tools", "Hardware/Camera": "hardware/hardware", + "Hardware/Fax": "hardware/hardware", "Hardware/ISDN": "hardware/hardware", + "Hardware/Joystick": "hardware/hardware", "Hardware/Mobile": "hardware/hardware", + "Hardware/Modem": "hardware/hardware", "Hardware/Other": "hardware/hardware", "Hardware/Palm": "hardware/hardware", + "Hardware/Printing": "hardware/hardware", "Hardware/Psion": "hardware/hardware", + "Hardware/Radio": "hardware/hardware", "Hardware/Scanner": "hardware/hardware", "Hardware/TV": "hardware/hardware", + "Hardware/UPS": "hardware/hardware", "Hardware/Wifi": "hardware/hardware", "Meta packages": "hardware/hardware", + "Multimedia": "multimedia/hardware", "Productivity/Archiving/Backup": "middleware/Backup and restoration", + "Productivity/Archiving/Compression": "middleware/Decompress", + "Productivity/Clustering/Computing": "middleware/clustering", + "Productivity/Clustering/HA": "middleware/clustering", "Productivity/Databases/Clients": "database/database", + "Productivity/Databases/Servers": "middleware/database", "Productivity/Databases/Tools": "middleware/database", + "File utilities": "middleware/tools", "Productivity/File utilities": "middleware/tools", + "Graphics": "multimedia/Graphics", "Productivity/Graphics/3D Editors": "multimedia/Graphics", + "Productivity/Graphics/Bitmap Editors": "multimedia/Graphics", "Productivity/Graphics/CAD": "multimedia/Graphics", + "Productivity/Graphics/Convertors (Converters?)": "multimedia/Graphics", + "Productivity/Graphics/Other": "multimedia/Graphics", + "Productivity/Graphics/Vector Editors": "multimedia/Graphics", + "Productivity/Graphics/Viewers": "multimedia/Graphics", + "Productivity/Graphics/Visualization/Graph": "multimedia/Graphics", + "Productivity/Graphics/Visualization/Other": "multimedia/Graphics", + "Productivity/Graphics/Visualization/Raytracers": "multimedia/Graphics", "Hamradio": "middleware/Office", + "Productivity/Hamradio/Fax": "middleware/Office", "Productivity/Hamradio/Logging": "middleware/Office", + "Productivity/Hamradio/Morse": "middleware/Office", "Productivity/Hamradio/Other": "middleware/Office", + "Productivity/Hamradio/Packet": "middleware/Office", "Productivity/Hamradio/Psk31": "middleware/Office", + "Productivity/Hamradio/Satellite": "middleware/Office", "multimedia": "multimedia/Audio", + "Productivity/Multimedia/CD/Grabbers": "multimedia/Audio", + "Productivity/Multimedia/CD/Players": "multimedia/Audio", "Productivity/Multimedia/CD/Record": "multimedia/Audio", + "Productivity/Multimedia/Other": "multimedia/Audio", + "Productivity/Multimedia/Sound/Editors and Convertors": "multimedia/Audio", + "Productivity/Multimedia/Sound/Midi": "multimedia/Audio", + "Productivity/Multimedia/Sound/Mixers": "multimedia/Audio", + "Productivity/Multimedia/Sound/Players": "multimedia/Audio", + "Productivity/Multimedia/Sound/Utilities": "multimedia/Audio", + "Productivity/Multimedia/Sound/Visualization": "multimedia/Audio", + "Productivity/Multimedia/Video/Editors and Convertors": "multimedia/Audio", + "Productivity/Multimedia/Video/Players": "multimedia/Audio", "Networking": "multimedia/Audio", + "Productivity/Networking/AOLInstantMessenger": "network/Network Management", + "Productivity/Networking/Archie": "network/Network Management", + "Productivity/Networking/Boot/Clients": "network/Basic Services", + "Productivity/Networking/Boot/Servers": "network/Basic Services", + "Productivity/Networking/Boot/Utilities": "network/Network Management", + "Productivity/Networking/Diagnostic": "network/Network diagnosis", + "Productivity/Networking/DNS/Servers": "network/Basic Services", + "Productivity/Networking/DNS/Utilities": "network/Network Management", + "Productivity/Networking/Email/Clients": "network/communications", + "Productivity/Networking/Email/Mailinglists": "network/Network Management", + "Productivity/Networking/Email/Servers": "network/Basic Services", + "Productivity/Networking/Email/Utilities": "network/Network Management", + "Productivity/Networking/File-Sharing": "network/Basic Services", + "Productivity/Networking/Ftp/Clients": "network/Basic Services", + "Productivity/Networking/Ftp/Servers": "network/Basic Services", + "Productivity/Networking/ICQ": "network/communications", + "Productivity/Networking/Instant Messenger": "network/Network Management", + "Productivity/Networking/IRC": "network/communications", + "Productivity/Networking/LDAP/Clients": "network/Basic Services", + "Productivity/Networking/LDAP/Servers": "network/Basic Services", + "Productivity/Networking/LDAP/Utilities": "network/Network Management", + "Productivity/Networking/Napster": "network/Network Management", + "Productivity/Networking/News/Clients": "network/Basic Services", + "Productivity/Networking/News/Servers": "network/Basic Services", + "Productivity/Networking/News/Utilities": "network/Network Management", + "Productivity/Networking/NFS": "network/Basic Services", "Productivity/Networking/NIS": "network/Basic Services", + "Productivity/Networking/Novell": "network/Network Management", "Productivity/Networking/Other": "network/other", + "Productivity/Networking/PPP": "network/communications", + "Productivity/Networking/Radius/Clients": "network/Basic Services", + "Productivity/Networking/Radius/Servers": "network/Basic Services", + "Productivity/Networking/Routing": "network/Network Management", + "Productivity/Networking/Samba": "network/Basic Services", + "Productivity/Networking/Security": "network/Network Management", + "Productivity/Networking/SSH": "network/Basic Services", + "Productivity/Networking/System": "network/Network Management", + "Productivity/Networking/Talk/Clients": "network/Basic Services", + "Productivity/Networking/Talk/Servers": "network/Basic Services", + "Productivity/Networking/Web/Browsers": "network/Communicating", + "Productivity/Networking/Web/Frontends": "network/Communicating", + "Productivity/Networking/Web/Proxy": "network/Network Management", + "Productivity/Networking/Web/Servers": "network/Basic Services", + "Productivity/Networking/Web/Utilities": "network/Network Management", + "Productivity/Office/Dictionary": "desktop/office", "Productivity/Office/Finance": "desktop/office", + "Productivity/Office/Management": "desktop/office", "Productivity/Office/Organizers": "desktop/office", + "Productivity/Office/Other": "desktop/office", "Productivity/Office/Spreadsheets": "desktop/office", + "Productivity/Office/Suite": "desktop/office", "Productivity/Office/Word Processor": "desktop/office", + "Productivity/Other": "desktop/office", "Productivity/Publishing/DocBook": "basic system/Release Tools", + "Productivity/Publishing/HTML/Editors": "basic system/Release Tools", + "Productivity/Publishing/HTML/Tools": "basic system/Release Tools", + "Productivity/Publishing/Other": "basic system/Release Tools", + "Productivity/Publishing/PDF": "basic system/Release Tools", + "Productivity/Publishing/Presentation": "basic system/Release Tools", + "Productivity/Publishing/PS": "basic system/Release Tools", + "Productivity/Publishing/SGML": "basic system/Release Tools", + "Productivity/Publishing/TeX/Base": "basic system/Release Tools", + "Productivity/Publishing/TeX/Fonts": "basic system/Release Tools", + "Productivity/Publishing/TeX/Frontends": "basic system/Release Tools", + "Productivity/Publishing/TeX/Utilities": "basic system/Release Tools", + "Productivity/Publishing/Texinfo": "basic system/Release Tools", + "Productivity/Publishing/Troff": "basic system/Release Tools", + "Productivity/Publishing/Word": "basic system/Release Tools", + "Productivity/Publishing/XML": "basic system/Release Tools", + "Productivity/Scientific/Astronomy": "middleware/scientific computing", + "Productivity/Scientific/Chemistry": "middleware/scientific computing", + "Productivity/Scientific/Electronics": "middleware/scientific computing", + "Productivity/Scientific/Math": "middleware/scientific computing", + "Productivity/Scientific/Other": "middleware/scientific computing", + "Productivity/Scientific/Physics": "middleware/scientific computing", + "Productivity/Security": "middleware/Security Tools", + "Productivity/Telephony/Clients": "middleware/Security Tools", + "Productivity/Telephony/H323/Clients": "middleware/Security Tools", + "Productivity/Telephony/H323/Servers": "middleware/Security Tools", + "Productivity/Telephony/H323/Utilities": "middleware/Security Tools", + "Productivity/Telephony/Servers": "middleware/Security Tools", + "Productivity/Telephony/SIP/Clients": "middleware/Security Tools", + "Productivity/Telephony/SIP/Servers": "middleware/Security Tools", + "Productivity/Telephony/SIP/Utilities": "middleware/Security Tools", + "Productivity/Telephony/Utilities": "middleware/Security Tools", + "Productivity/Text/Convertors": "middleware/Security Tools", + "Productivity/Text/Editors": "middleware/Security Tools", "Productivity/Text/Spell": "middleware/Security Tools", + "Productivity/Text/Utilities": "middleware/Security Tools", "System/Emulators/Other": "hardware/emulation", + "System/Emulators/PC": "hardware/emulation", "GUI": "desktop/Desktop Library", + "System/GUI/GNOME": "desktop/graphics system", "System/GUI/KDE": "desktop/graphics system", + "System/GUI/LXDE": "desktop/graphics system", "System/GUI/Other": "desktop/graphics system", + "System/GUI/XFCE": "desktop/graphics system", "System/I18n/Chinese": "basic system/Standardization", + "System/I18n/Japanese": "basic system/Standardization", "System/I18n/Korean": "basic system/Standardization", + "X11": "desktop/Graphical Basics", "System/X11/Displaymanagers": "desktop/Graphical Basics", + "System/X11/Fonts": "desktop/Graphical Basics", "System/X11/Icons": "desktop/Graphical Basics", + "System/X11/Servers/XF86_3": "desktop/Graphical Basics", "System/X11/Servers/XF86_4": "desktop/Graphical Basics", + "System/X11/Terminals": "desktop/Graphical Basics", "System/X11/Utilities": "desktop/Graphical Basics", + "YaST": "systemtools/tools", "System/YaST": "systemtools/tools"} + +if __name__ == '__main__': + # 读取rpm包名存入列表内 + # rpm_pkg_path = input("请输入要获取的rpm包目录:") + # api_token = input("请输入api的token:") + headers = {"Content-Type": "application/json;charset=UTF-8"} + rpm_pkg_path = "/srv/rpm/pub/" + # rpm_pkg_path = "contrib" + api_token = "c4a7f2254bd58885a9c6fa80cbd0b7dc" + # 取rpm包总数和rpm文件绝对路径 + getAllFilesInPath(rpm_pkg_path) + print("当前路径下的总文件数 =", allFileNum) + for rpm_path in allFileList: + rpm_file = shell_cmd("Name", rpm_path) # 获取rpm信息 + d[rpm_file].append(rpm_path) + os.system("git clone 'https://gitee.com/zhang-yn/oepkgs-management_1.git';") + # 获取src-oepkgs上已经存在的库,通过yaml文件获取 + getAllFilesInPath("./oepkgs-management_1/sig") + # 判断取到的rpm文件是否在舱内已经存在,进行过滤 + print("***************") + # print(d) + print("---------------") + # print(allYamlList) + d_list = copy.deepcopy(d) + for i in d_list: + if i in allYamlList or str.lower(i) in allYamlList: + d.pop(i) + print(d) + print("-----*****-----") + print(len(d.keys())) + # print(d.keys()) + # sys.exit() + # sys.exit() + # 遍历字典进行yaml创建 + source_ocde("module2.xml") + for yaml_modify in d: + yaml_file = "" + if yaml_modify[0].isdigit(): + for i, item in enumerate(yaml_modify): + if not item.isdigit() and item == "-": + yaml_file = yaml_file + yaml_modify[i + 1:] + # yaml_file = yaml_modify[i + 1:] + "-" + yaml_modify[:i] + break + elif not item.isdigit() and item != "-": + yaml_file = yaml_file + yaml_modify[i:] + # yaml_file = yaml_modify[i + 1:] + yaml_modify[:i] + break + else: + yaml_file = yaml_file + ones[int(item)] + "-" + elif "+" in yaml_modify: + yaml_file = yaml_modify.replace("+", "plus") + else: + yaml_file = yaml_modify + # print("*****{}****".format(yaml_modify)) + if yaml_modify in dict_list.keys() and dict_list[yaml_modify][0].split("-*-")[1] in a.keys(): + group_str = dict_list[yaml_modify][0].split("-*-")[1] + print("-----{0}-----*******{1}******".format(yaml_modify, group_str)) + des_str = "" + rpm_str = dict_list[yaml_modify][0].split("-*-")[2] + for str_dig in rpm_str.split(" "): + str_dig = "".join(filter(str.isalpha, str_dig.strip())) + des_str = des_str + str_dig + " " + license_str = dict_list[yaml_modify][0].split("-*-")[0] + if group_str in a.keys(): + d_oepkg[a[group_str].split("/", 1)[0].replace(" ", "")].append( + yaml_file + "-+-" + des_str + "-+-" + license_str + "-+-" + group_str + "-+-" + + a[group_str].split("/", 1)[1]) + # if yaml_modify[0].isdigit(): + # pass + else: + group_str = shell_cmd("Group", d[yaml_modify][0]) + # print("{0}-*-*-*-*{1}".format(yaml_modify,group_str)) + license_str = shell_cmd("License", d[yaml_modify][0]) + des_str = "" + rpm_str = shell_cmd("Summary", d[yaml_modify][0]) + for str_dig in rpm_str.split(" "): + str_dig = "".join(filter(str.isalpha, str_dig.strip())) + des_str = des_str + str_dig + " " + if group_str in group_dict.keys(): + d_oepkg[group_dict[group_str].split("/", 1)[0].replace(" ", "")].append( + yaml_file + "-+-" + des_str + "-+-" + license_str + "-+-" + group_str + "-+-" + + group_dict[group_str].split("/", 1)[1]) + else: + yaml_liu.append(yaml_modify) + print("------- 需要添加 -------") + print(d_oepkg) + print("------- 剩余 ------") + print(yaml_liu) + + for d_oepkg_key in d_oepkg.keys(): + group_dir = d_oepkg_key + sig_code_str = {} + if not os.path.exists(real_path + "/oepkgs-management_1/sig/{}/sig-info.yaml".format(group_dir)): + for i, item in enumerate(d_oepkg[d_oepkg_key]): + print("44-------------------") + print(real_path + "oepkgs-management_1/sig/{}/sig-info.yaml".format(group_dir)) + # print(d_oepkg[d_oepkg_key]) + print("222--------------") + if i == 0: + print("bbbbbbb-----------ddddddddddd") + sig_code_str = sig_info("sig-info.yaml", group_dir, item.split("-+-")[0], item.split("-+-")[4]) + print(sig_code_str) + print("dddddd-------------------bbbbb") + base64_encode("./test.yaml", group_dir, item) + else: + print("333------------------") + # type_str = [sig_code_str['repositories'].index(i) for i in sig_code_str['repositories'] if i.get("type") == group_secdir] + # if not type_str: + # sig_code_str['repositories'].append({'repo': ['src-oepkgs/' + str.lower(item.split("-+-")[0])], 'type': group_secdir}) + # else: + + type_str = [j for j, i in enumerate(sig_code_str['repositories']) if + i.get("type") == item.split("-+-")[4]] + if len(type_str) == 0: + sig_code_str['repositories'].append( + {'repo': ['src-oepkgs/' + item.split("-+-")[0]], 'type': item.split("-+-")[4]}) + else: + sig_code_str['repositories'][type_str[0]]['repo'].append("src-oepkgs/" + item.split("-+-")[0]) + base64_encode("./test.yaml", group_dir, item) + # print(sig_code_str) + print("---------sig_code_str----------") + print(sig_code_str) + code_str = base64.b64encode( + yaml.dump(sig_code_str, allow_unicode=True, default_flow_style=False, sort_keys=False).encode( + 'utf-8')).decode('utf-8') + os.system( + "{} 'https://gitee.com/api/v5/repos/zhang-yn/oepkgs-management_1/contents/sig%2F{}%2Fsig-info.yaml' -d '{{\"access_token\":\"{}\",\"content\":\"{}\",\"message\":\"test\"}}'".format( + rq_header, group_dir, api_token, code_str)) + print("---------sig_code_str end----------") + else: + for j, items in enumerate(d_oepkg[d_oepkg_key]): + print("dddddd-------------------") + if j == 0: + sig_code_str = sig_info("./oepkgs-management_1/sig/{}/sig-info.yaml".format(group_dir), group_dir, + items.split("-+-")[0], items.split("-+-")[4]) + print("-------000000-------") + print(sig_code_str) + base64_encode("./test.yaml", group_dir, items) + else: + print(sig_code_str) + print("------22222222-------") + base64_encode("./test.yaml", group_dir, items) + type_str = [j for j, i in enumerate(sig_code_str['repositories']) if + i.get("type") == items.split("-+-")[4]] + if len(type_str) == 0: + sig_code_str['repositories'].append( + {'repo': ['src-oepkgs/' + items.split("-+-")[0]], 'type': items.split("-+-")[4]}) + else: + sig_code_str['repositories'][type_str[0]]['repo'].append("src-oepkgs/" + items.split("-+-")[0]) + print("dddddd-------------------") + code_str = base64.b64encode( + yaml.dump(sig_code_str, allow_unicode=True, default_flow_style=False, sort_keys=False).encode( + 'utf-8')).decode('utf-8') + sig_info_add(group_dir, code_str) + + print("---------------") + print("配置文件创建完成") \ No newline at end of file diff --git a/tools/auto_creat_lib/push/.keep b/tools/auto_creat_lib/push/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tools/auto_creat_lib/push/pr.py b/tools/auto_creat_lib/push/pr.py new file mode 100644 index 0000000000000000000000000000000000000000..0d95d7e695cbcace1f71a991d96fb9d404ba0487 --- /dev/null +++ b/tools/auto_creat_lib/push/pr.py @@ -0,0 +1,135 @@ +# !/usr/bin/python3 +# -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import re +import requests +import time +from collections import defaultdict +from xml.etree.ElementTree import parse +from txdpy import get_Bletter,get_Sletter + +srcOepkgsNum = 0 +allFileNum = 0 +allFileList = [] # 存放 当前路径 以及当前路径的子路径 下的所有文件 +sigInfolist = [] +allYamlList = [] +filter_char = [] +allYamldata = [] +rpm_info = {} +d = defaultdict(list) +d_oepkg = defaultdict(list) +dict_list = defaultdict(list) +Inyaml = [] + +def getAllFilesInPath(path): + #print(path) + global allFileNum + curPathDirList = [] # 当前路径下的所有文件夹 + files = os.listdir(path) # 返回当前路径下的所有文件和文件夹 + for f in files: + if os.path.isdir(path + "/" + f): + if f[0] == ".": + pass # 排除隐藏文件夹 + else: + curPathDirList.append(f) # 添加非隐藏文件夹 + if os.path.isfile(path + "/" + f): + if f[-8:] == ".src.rpm": + allFileList.append(os.path.abspath(path + "/" + f)) # 添加文件 + allFileNum = allFileNum + 1 + # 总文件数+1 + if f[-5:] == ".yaml" and f != "sig-info.yaml": + # yaml_name = f[:-5] + # allYamlList.append(yaml_name) + if path.split("/")[1] == "oepkgs-management_10": + allYamldata.append(os.path.abspath(path + "/" + f)) + elif path.split("/")[1] == "oepkgs-management": + Inyaml.append(f) + for dl in curPathDirList: + getAllFilesInPath(path + "/" + dl) # 递归获取当前目录下的文件夹内的文件 + + +def creat_pr(): + print("------ pr -------") + data = {"access_token": api_token, "title": "自动化创建库", "head": "zhang-yn:master", "base": "master"} + response = requests.post("https://gitee.com/api/v5/repos/oepkgs/oepkgs-management/pulls", params=data,headers=headers) + #print(response) + pr_num = json.loads(response.text)["number"] + print("-------- waiting 10 minutes ---------") + #sys.exit() + time.sleep(300) + response = requests.get("https://gitee.com/api/v5/repos/oepkgs/oepkgs-management/pulls/{}/merge?access_token={}".format(pr_num,api_token),headers=headers) + response_dict = json.loads(response.text) + if response_dict['message'] != 'Pull Request已经合并': + commit_id = os.popen("{0} 'https://gitee.com/api/v5/repos/new-op/community/pulls/{1}' -d '{{\"access_token\":\"{2}\",\"state\":\"closed\"}}'".format(closed_header, pr_num, api_token)).read() + response_json = json.loads(commit_id) + if response_json["state"] == "closed": + # print("******* 当前提交未合并 ********") + creat_pr() + else: + print("---------- pr 未关闭 ------------") + sys.exit() + time.sleep(500) + print("--- 已合入 ---") + + +# 监听pr +def listen_event(pr_num): + response = requests.get( + "https://gitee.com/api/v5/repos/oepkgs/oepkgs-management/pulls/{}/merge?access_token={}".format(pr_num,api_token),headers=headers) + response_dict = json.loads(response.text) + if not response_dict['message'] == 'Pull Request已经合并': + time.sleep(300) + listen_event(pr_num) + + + + +if __name__ == '__main__': + # 读取rpm包名存入列表内 + # rpm_pkg_path = input("请输入要获取的rpm包目录:") + # api_token = input("请输入api的token:") + headers = {"Content-Type": "application/json;charset=UTF-8"} + rpm_pkg_path = "/srv/rpm/pub/" + rq_header = "curl -X POST --header 'Content-Type: application/json;charset=UTF-8'" + real_path = os.path.dirname(os.path.realpath(__file__)) + "/" + api_token = "077fd301428ee142b5bc5d5eaae0a0fc" + robot_token = "c951fee688f4b037d27602d7461b81fc" + # 取rpm包总数和rpm文件绝对路径 + # getAllFilesInPath(rpm_pkg_path) + + a = 0 + # 创建pr + os.system("git clone 'https://gitee.com/zhang-yn/oepkgs-management.git';") + print("--------") + getAllFilesInPath("./oepkgs-management_10/sig") + getAllFilesInPath("./oepkgs-management/sig") + print("********") + print(Inyaml) + print("===========") + print(len(allYamldata)) + print("---------------") + for i, item in enumerate(allYamldata): + if len(get_Bletter(item.split("/")[-1][:-5])) != 0: + if item.split("/")[-1][:-5].lower() + ".yaml" in Inyaml: + # os.system("rm -rf {}".format(item)) + continue + dest_path = real_path + "oepkgs-management" + "/" + "/".join(item.split("/")[-5:-1]) + "/" + #print(item) + if item.split("/")[-1] not in Inyaml and len(item.split("/")[-1][:-5]) > 1 and len(item.split("/")[-1].split(".")) == 2: + a = a + 1 + if not os.path.exists(dest_path): + os.system("mkdir -p {0};cp -rf {1} {0}".format(dest_path,item)) + else: + os.system("cp -rf {1} {0}".format(dest_path, item)) + if a >= 100: + os.system("cd {0};git add .;git commit -m '自动化仓库创建';git push".format("oepkgs-management")) + creat_pr() + # print(a) + a = 0 + print("--------") + sys.exit() \ No newline at end of file diff --git a/tools/auto_creat_lib/push/pre_push.py b/tools/auto_creat_lib/push/pre_push.py new file mode 100644 index 0000000000000000000000000000000000000000..ea1270407c97a11c3c84ba74377d6a1ecb8ae35c --- /dev/null +++ b/tools/auto_creat_lib/push/pre_push.py @@ -0,0 +1,198 @@ +# !/usr/bin/python3 +# -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import re +import requests +import time +import copy +from collections import defaultdict, OrderedDict +# import requests.adapters + +from xml.etree.ElementTree import parse + +srcOepkgsNum = 0 +allFileNum = 0 +allFileList = [] # 存放 当前路径 以及当前路径的子路径 下的所有文件 +sigInfolist = [] +allYamlList = [] +filter_char = [] +allYamldata = [] +allYamldata_branch = [] +allYamldata_tag = [] +src_code_up = [] +src_code_is = [] +yaml_error = [] +branch_list = [] +rpm_info = {} +d = defaultdict(list) +d_oepkg = defaultdict(list) +dict_list = defaultdict(list) +ones = {1: "one", 2: "two", 3: "three", 4: "four", + 5: "five", 6: "six", 7: "seven", 8: "eight", + 9: "nine", 0: "zero"} + + +def getAllFilesInPath(path): + global allFileNum + curPathDirList = [] # 当前路径下的所有文件夹 + files = os.listdir(path) # 返回当前路径下的所有文件和文件夹 + for f in files: + if os.path.isdir(path + "/" + f): + if f[0] == ".": + pass # 排除隐藏文件夹 + else: + curPathDirList.append(f) # 添加非隐藏文件夹 + if os.path.isfile(path + "/" + f): + if f[-8:] == ".src.rpm": + allFileList.append(os.path.abspath(path + "/" + f)) # 添加文件 + allFileNum = allFileNum + 1 + # 总文件数+1 + if f[-5:] == ".yaml" and f != "sig-info.yaml": + yaml_name = f[:-5] + allYamlList.append(yaml_name) + # allYamldata.append(os.path.abspath(path + "/" + f)) + + for dl in curPathDirList: + getAllFilesInPath(path + "/" + dl) # 递归获取当前目录下的文件夹内的文件 + + +# 获取rpm信息,拿到name和description +def shell_cmd(rpm_key, path): + rpm_info = os.popen("rpm -qi {}".format(path)) + for line in rpm_info.read().splitlines(): + rpm_value = line.split(":") + if rpm_value[0].strip() == rpm_key: + return rpm_value[1].strip() + + +if __name__ == '__main__': + # 读取rpm包名存入列表内 + # rpm_pkg_path = input("请输入要获取的rpm包目录:") + # api_token = input("请输入api的token:") + if len(sys.argv) != 2: + sys.exit() + + # requests.adapters.DEFUALT_RETRYS = 10 + headers = {"Content-Type":"application/json;charset=UTF-8","connection":"close"} + rpm_pkg_path = "/srv/rpm/pub/openeuler-22.03-LTS" + rq_header = "curl -X POST --header 'Content-Type: application/json;charset=UTF-8'" + real_path = os.path.dirname(os.path.realpath(__file__)) + "/" + api_token = "613df0cd941abfdfc90f36445e98736d" + robot_token = "c951fee688f4b037d27602d7461b81fc" + print("yaml文件的名字") + getAllFilesInPath("./oepkgs-management/sig") + print(allYamlList) + with open("sp3_yaml.json", "r") as f: + d = json.load(f) + print("---------------") + print(len(d)) + tag_num = 0 + add_yaml = 0 + for yaml_modify in d: + tag_num = tag_num + 1 + print("------ branch {} 已添加 -----".format(tag_num)) + # if yaml_modify not in allYamlList: + yaml_file = "" + if yaml_modify[0].isdigit(): + for i, item in enumerate(yaml_modify): + if not item.isdigit() and item == "-": + yaml_file = yaml_file + yaml_modify[i + 1:] + # yaml_file = yaml_modify[i + 1:] + "-" + yaml_modify[:i] + break + elif not item.isdigit() and item != "-": + yaml_file = yaml_file + yaml_modify[i:] + # yaml_file = yaml_modify[i + 1:] + yaml_modify[:i] + break + else: + yaml_file = yaml_file + ones[int(item)] + "-" + elif "+" in yaml_modify: + yaml_file = yaml_modify.replace("+", "plus") + else: + yaml_file = yaml_modify + print("----- yaml_modify ----") + print("*****{}****".format(yaml_modify)) + + if yaml_file not in allYamlList: + src_code_is.append(yaml_file) + print("-------- out of yaml file --------") + print(src_code_is) + continue + # elif yaml_file in allFileList and yaml_file.lower() not in allFileList: + # elif yaml_file in allFileList and yaml_file.lower() in allFileList: + # yaml_file = yaml_file.lower() + os.system("git clone 'https://gitee.com/src-oepkgs/{0}.git';".format(yaml_file)) + if not os.path.exists(real_path + yaml_file): + yaml_file = yaml_file.lower() + os.system("git clone 'https://gitee.com/src-oepkgs/{0}.git';".format(yaml_file)) + if not os.path.exists(real_path + yaml_file): + allYamldata.append(yaml_file) + #print("------ allYamldata {} 已添加 -----".format(yaml_file)) + continue + # time.sleep() + os.chdir(os.getcwd() + "/" + yaml_file) + commit_id = os.popen("git tag").read().strip() + + repo_branch = os.popen("git branch -r").read().strip() + branch_a = repo_branch.split("\n") + if repo_branch == "": + #print("----- {} branch 不存在 -----".format(yaml_file)) + allYamldata_branch.append(yaml_file) + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + continue + if "origin/openEuler-22.03-LTS" not in [i.strip() for i in branch_a]: + print("----- openEuler-22.03-LTS 不存在 ----") + branch_list.append(yaml_file) + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + continue + + if commit_id == "": + d_oepkg[yaml_file]=d[yaml_modify] + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + add_yaml = add_yaml + 1 + print("----- tag 不存在 -----") + print("------ {0} branch {1} 已添加 -----".format(yaml_file,add_yaml)) + else: + tag_list = commit_id.split("\n") + if "22.03-LTS" in [ i[:9] for i in tag_list]: + print("----- {} tag 已存在 -----".format(yaml_file)) + allYamldata_tag.append(yaml_file) + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + continue + else: + d_oepkg[yaml_file]=d[yaml_modify] + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + add_yaml = add_yaml + 1 + print("----- 22.03-LTS 存在 -----") + print("------ {0} branch {1} 已添加 -----".format(yaml_file,add_yaml)) + + with open("yaml_sp3.json", "w") as f: + f.write(json.dumps(d_oepkg)) + print("--------- yaml list -----------") + print(len(src_code_is)) + print(src_code_is) + print("--------- git list -----------") + print(len(allYamldata)) + print(allYamldata) + print("--------- branch list -----------") + print(len(allYamldata_branch)) + print(allYamldata_branch) + print("--------- 22 list -----------") + print(len(branch_list)) + print(branch_list) + print("--------- tag list -----------") + print(len(allYamldata_tag)) + print(allYamldata_tag) + print("--------- d_oepkg list -----------") + print(len(d_oepkg)) + #print(allYamldata_tag) + print("---- end ----") diff --git a/tools/auto_creat_lib/push/rw_xls.py b/tools/auto_creat_lib/push/rw_xls.py new file mode 100644 index 0000000000000000000000000000000000000000..471b6c4816d0c881d03ce8c917ebf824fed940f5 --- /dev/null +++ b/tools/auto_creat_lib/push/rw_xls.py @@ -0,0 +1,45 @@ +# # !/usr/bin/python3 +# # -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import re +import requests +import time +from collections import defaultdict +from xml.etree.ElementTree import parse +import xlwt +xl = xlwt.Workbook(encoding='UTF-8') +sheet = xl.add_sheet('docker', cell_overwrite_ok=True) +row = 0 +cloum = 0 + +# a = os.system("find ./ -name Dockerfile > log.txt") +with open("log1.txt","r") as f: + for k,i in enumerate(f.readlines()): + #print(i) + a = os.popen("grep FROM {}".format(i)).read() + #print(a) + #with open("./test.txt","a+") as f1: + #f1.write(a.strip() + "-------------" + i) + data = i.split("/") + for j in data: + sheet.write(row, cloum, j) + cloum = cloum + 1 + #data = i.split("/blob/master/")[1] + #sys.exit() + # print(data) + #data = "https://gitee.com/{}/{}/blob/master/{}".format(upper,i[2:].split("/", 1)[0],i[2:].split("/", 1)[1]) + # with open("./docker_1.txt","a+") as f1: + # f1.write(data + "\n") + sheet.write(row, 12, a) + cloum = cloum + 1 + with open("docker_link.txt","r") as f1: + sheet.write(row, 15, f1.readlines()[k]) + row = row + 1 + cloum = 0 + +xl.save("docker.xls") \ No newline at end of file diff --git a/tools/auto_creat_lib/push/sig-info.yaml b/tools/auto_creat_lib/push/sig-info.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ae86cc2df4f90653ac373cd0e66bbea4eb666e8d --- /dev/null +++ b/tools/auto_creat_lib/push/sig-info.yaml @@ -0,0 +1,12 @@ +name: {0} +description: To support the field of {0} +mailing_list: NA +meeting_url: NA +mature_level: startup +maintainers: +- gitee_id: lipingEmmaSiguyi + name: Ping Li + orgnization: Huawei + email: liping136@huawei.com +repositories: +- repo: \ No newline at end of file diff --git a/tools/auto_creat_lib/push/test.py b/tools/auto_creat_lib/push/test.py new file mode 100644 index 0000000000000000000000000000000000000000..df45cc460314cfe6e86e1c841865a8b4498d87dc --- /dev/null +++ b/tools/auto_creat_lib/push/test.py @@ -0,0 +1,27 @@ +# !/usr/bin/python3 +# -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import re +import requests +import time +from collections import defaultdict +from xml.etree.ElementTree import parse + +with open("./yaml_list.txt","r") as f: + #for i in f.readlines(): + yaml_list = f.read() + for i in yaml_list.split(", "): + i = i.split("'")[1] + os.system("git clone 'https://gitee.com/src-oepkgs/{0}.git';cp README.md {0}/;".format(i)) + os.chdir(os.getcwd() + "/" + i) + os.system("git add .;git commit -m 'create';git push;") + os.chdir(os.path.pardir) + os.system("rm -rf {}".format(i)) +print("-------- end -------") + + # print(type(", ".split(i))) diff --git a/tools/auto_creat_lib/push/test.yaml b/tools/auto_creat_lib/push/test.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f131fb142212ae23503f28fcc9e00d26c248d3fd --- /dev/null +++ b/tools/auto_creat_lib/push/test.yaml @@ -0,0 +1,21 @@ +name: {0} +description: {1} +group: {3} +license: {2} +upstream: https://gitee.com/src-oepkgs/{0} +branches: +- name: master + type: protected +- name: openEuler-20.03-LTS-SP1 + type: protected + create_from: master +- name: openEuler-20.03-LTS-SP2 + type: protected + create_from: master +- name: openEuler-20.03-LTS-SP3 + type: protected + create_from: master +- name: openEuler-22.03-LTS + type: protected + create_from: master +type: public \ No newline at end of file diff --git a/tools/auto_creat_lib/push/upload.py b/tools/auto_creat_lib/push/upload.py new file mode 100644 index 0000000000000000000000000000000000000000..0d3e72da670390ae6462dcda0299abe3811b3fd1 --- /dev/null +++ b/tools/auto_creat_lib/push/upload.py @@ -0,0 +1,170 @@ +# !/usr/bin/python3 +# -*- coding:UTF-8 -*- + +import base64 +import sys +import os +import yaml +import json +import re +import requests +import time +import copy +from collections import defaultdict, OrderedDict +# import requests.adapters + +from xml.etree.ElementTree import parse + +srcOepkgsNum = 0 +allFileNum = 0 +allFileList = [] # 存放 当前路径 以及当前路径的子路径 下的所有文件 +sigInfolist = [] +allYamlList = [] +filter_char = [] +allYamldata = [] +src_code_up = [] +src_code_is = [] +yaml_error = [] +rpm_info = {} +d = defaultdict(list) +d_oepkg = defaultdict(list) +dict_list = defaultdict(list) + + +def getAllFilesInPath(path): + global allFileNum + curPathDirList = [] # 当前路径下的所有文件夹 + files = os.listdir(path) # 返回当前路径下的所有文件和文件夹 + for f in files: + if os.path.isdir(path + "/" + f): + if f[0] == ".": + pass # 排除隐藏文件夹 + else: + curPathDirList.append(f) # 添加非隐藏文件夹 + if os.path.isfile(path + "/" + f): + if f[-8:] == ".src.rpm": + allFileList.append(os.path.abspath(path + "/" + f)) # 添加文件 + allFileNum = allFileNum + 1 + # 总文件数+1 + if f[-5:] == ".yaml" and f != "sig-info.yaml": + yaml_name = f[:-5] + allYamlList.append(yaml_name) + # allYamldata.append(os.path.abspath(path + "/" + f)) + + for dl in curPathDirList: + getAllFilesInPath(path + "/" + dl) # 递归获取当前目录下的文件夹内的文件 + + +# 获取rpm信息,拿到name和description +def shell_cmd(rpm_key, path): + rpm_info = os.popen("rpm -qi {}".format(path)) + for line in rpm_info.read().splitlines(): + rpm_value = line.split(":") + if rpm_value[0].strip() == rpm_key: + return rpm_value[1].strip() + + +if __name__ == '__main__': + # 读取rpm包名存入列表内 + # rpm_pkg_path = input("请输入要获取的rpm包目录:") + # api_token = input("请输入api的token:") + if len(sys.argv) != 2: + sys.exit() + + # requests.adapters.DEFUALT_RETRYS = 10 + headers = {"Content-Type":"application/json;charset=UTF-8","Connection":"close"} + rpm_pkg_path = "/srv/rpm/pub/openeuler-20.03-LTS-SP1" + rq_header = "curl -X POST --header 'Content-Type: application/json;charset=UTF-8'" + real_path = os.path.dirname(os.path.realpath(__file__)) + "/" + api_token = "c0733ca83ae57261ae3513fa8d78ef47" + robot_token = "c951fee688f4b037d27602d7461b81fc" + print("yaml文件的名字") + with open("yaml_file_d.json", "r") as f: + d = json.load(f) + # print(d) + # d_list = copy.deepcopy(d) + # for i in d_list: + # if i != "rt61pci-firmware": + # del d[i] + # else: + # break + print("---------------") + print(len(d)) + print(d) + #sys.exit() + tag_num = 0 + for yaml_file in d: + module_name = d[yaml_file] + print("----module_name----") + print(module_name) + rpm_dict = {} + version_set = set() + for rpm_path in module_name: + rpm_version = shell_cmd("Version", rpm_path) + print(rpm_version) + version_set.add(rpm_version) + rpm_dict[rpm_version] = rpm_path + version_list = list(version_set) + version_list.sort() + print("------++++++") + print(version_list) + print(rpm_dict) + # sys.exit() + print("+-+-+-+-+-+-+-+") + os.system("curl -X DELETE --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/src-oepkgs/{}/branches/{}/setting?access_token={}'".format(yaml_file, sys.argv[1], api_token)) + for rpm_version in version_list: + rpm_path = rpm_dict[rpm_version] + print("***************") + if sys.argv[1] == "master": + os.system("git clone 'https://gitee.com/src-oepkgs/{0}.git';".format(yaml_file)) + print("-----git clone-----") + else: + os.system("git clone -b {1} 'https://gitee.com/src-oepkgs/{0}.git';".format(yaml_file, + sys.argv[1])) + print("-----git clone-----") + if not os.path.exists(real_path + yaml_file): + print("-------path is not exist-------") + print("route is {}".format(os.path.exists(real_path + yaml_file))) + break + os.chdir(os.getcwd() + "/" + yaml_file) + print(os.listdir("./")) + + + print("-----****-----") + print(os.getcwd()) + # print("-----****-----") + os.system( + "rm -rf *;rpm2cpio {0} | cpio -div;git add .;git commit -m '{1}';git push".format(rpm_path, + rpm_version)) + print(os.getcwd()) + #os.chdir(os.path.pardir) + #os.system("rm -rf {0}".format(yaml_file)) + print("-------- pwd --------") + print(os.getcwd()) + # response_url = os.popen("curl -X GET --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/src-oepkgs/{}/branches/{}?access_token={}'".format(yaml_file, sys.argv[1], api_token)).read() + commit_id = os.popen("git rev-parse HEAD").read().strip() + print(commit_id) + os.chdir(os.path.pardir) + os.system("rm -rf {0}".format(yaml_file)) + print("-------- pwd --------") + print(os.getcwd()) + print("------- sha value ------") + # print(response_json) + # commit_id = response_json["commit"]["sha"] + print(commit_id) + if sys.argv[1] == "master": + os.system( + "{} 'https://gitee.com/api/v5/repos/src-oepkgs/{}/tags' -d '{{\"access_token\":\"{}\",\"refs\":\"{}\",\"tag_name\":\"{}\"}}'".format( + rq_header, yaml_file, api_token, commit_id, "20.03-LTS-SP1" + "-v" + rpm_version.replace("^",".").replace("~","."))) + else: + os.system( + "{} 'https://gitee.com/api/v5/repos/src-oepkgs/{}/tags' -d '{{\"access_token\":\"{}\",\"refs\":\"{}\",\"tag_name\":\"{}\"}}'".format( + rq_header, yaml_file, api_token, commit_id, sys.argv[1][10:] + "-v" + rpm_version.replace("^",".").replace("~","."))) + print("------- 库名 ------") + print(yaml_file) + tag_num = tag_num + 1 + os.system("curl -X PUT --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/src-oepkgs/{}/branches/{}/protection' -d '{{\"access_token\":\"{}\"}}'".format(yaml_file, sys.argv[1], api_token)) + # r_pt.close() + src_code_up.append(yaml_file) + # os.system("rm -rf {}".format(yaml_file)) + print(src_code_up) \ No newline at end of file diff --git a/tools/auto_creat_lib/software-compile/.keep b/tools/auto_creat_lib/software-compile/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tools/default_branch.py b/tools/default_branch.py new file mode 100644 index 0000000000000000000000000000000000000000..75407d932624273e34a287a294ef143d6f27dab8 --- /dev/null +++ b/tools/default_branch.py @@ -0,0 +1,37 @@ +import base64 +import sys +import os +#import yaml +import json +import re +import requests +import time +from collections import defaultdict,OrderedDict + +data = {"access_token":"c4a7f2254bd58885a9c6fa80cbd0b7dc","name":"phrel","has_issues":"true","has_wiki":"true","can_comment":"true","default_branch":"openEuler-22.03-LTS"} +headers = {"Content-Type": "application/json;charset=UTF-8"} +with open("default_branch.txt", "r") as f: + yaml_list = f.read() +print("---------------") +d = [ i.split("'")[1] for i in yaml_list.split(", ")] +print(len([ i.split("'")[1] for i in yaml_list.split(", ")])) +# d_list = copy.deepcopy(d) +# for i,j in enmerate(d_list): +# if i != "": +# del d[i] +# else: +# break +a = 0 +for yaml_file in d: + response_url = requests.patch("https://gitee.com/api/v5/repos/src-oepkgs/{}".format(yaml_file),data=data) + print("------ 已修改 ------") + a = a + 1 + print(a) + print(yaml_file) + if response_url.status_code != 200: + print("*******************") + print(yaml_file) + sys.exit() + if a == 1: + sys.exit() + time.slepp(2) \ No newline at end of file