From b8021a880a8506089e9b043a53ae40a666e3b097 Mon Sep 17 00:00:00 2001 From: gordonwwang Date: Tue, 17 Oct 2023 19:50:16 +0800 Subject: [PATCH] add dev-tools: auto_yaml and check_yaml --- auto_yaml/auto_mv.sh | 23 +++++++++ auto_yaml/auto_yaml.py | 108 +++++++++++++++++++++++++++++++++++++++++ auto_yaml/pkg_list | 2 + 3 files changed, 133 insertions(+) create mode 100755 auto_yaml/auto_mv.sh create mode 100755 auto_yaml/auto_yaml.py create mode 100644 auto_yaml/pkg_list diff --git a/auto_yaml/auto_mv.sh b/auto_yaml/auto_mv.sh new file mode 100755 index 0000000..0bc34e7 --- /dev/null +++ b/auto_yaml/auto_mv.sh @@ -0,0 +1,23 @@ +# /bin/bash + +file_des="./" +file_src_dir0="success_yaml" +file_src_dir1="fail_yaml" + +for file in $(ls $file_des | grep "\.yaml" ); do + if [ ! -f "$file" ]; then + echo "'$file' not exists!" + continue + fi + + # rpm-upgrade check + repo_name=$(echo $file | cut -d '.' -f 1) + rpm-upgrade $repo_name --path $file_des | grep -E "Latest *version *is:" + if [ $? -eq 0 ]; then + mv $file $file_src_dir0 + else + echo "###'$repo_name' query failed!" + mv $file $file_src_dir1 + fi + +done diff --git a/auto_yaml/auto_yaml.py b/auto_yaml/auto_yaml.py new file mode 100755 index 0000000..8c34eca --- /dev/null +++ b/auto_yaml/auto_yaml.py @@ -0,0 +1,108 @@ +import os +import subprocess +import re +import requests + +# 输入gitee 私人tocken +acess_tocken = "xxxx" + +def extract_src_repo(repo_name, url): + repo_type = None + repo_url = None + + # 扫描python包 + if repo_name.startswith("python") or "files.pythonhosted.org" in url: + mypatt = r'^python-(.+)' + mymatch = re.search(mypatt,repo_name) + if mymatch: + repo_type = "pypi" + repo_url = mymatch.group(1) + + # 扫描perl包 + if repo_name.startswith("perl"): + mypatt = r'^perl-(.+)' + mymatch = re.search(mypatt,repo_name) + if mymatch: + repo_type = "metacpan" + repo_url = mymatch.group(1) + + # 扫描apache包 + if "apache.org" in url: + if url.endswith('/'): + url = url[:-1] + repo_name=url.split("/")[-1] + # 如果是"commons"系列包,并且repo_name中尚未包含"commons-",添加之 + if "commons." in url and not "commons-" in repo_name: + repo_name = "commons-" + repo_name + repo_type = "github" + repo_url = "apache/" + repo_name + + # 扫描github、gitlab.gnome、git(gitlab) + pattern = r'(github\.com/|gitlab\.gnome\.org/)([\w\-]+/[\w\-]+)' + match = re.search(pattern, url) + if match: + repo_type = "github" if "github.com/" in match.group(1) else "gitlab.gnome" + repo_url = match.group(2) + # 检查是否为普通git仓库 + # elif url.startswith("http") and "://" in url and (url.endswith(".git") or ".git/" in url): + elif "://" in url and (url.endswith(".git") or ".git/" in url): + repo_type = "git" + repo_url = url + + return repo_type, repo_url + +def create_yaml(repo_name, repo_type, src_repo, git_link): + with open(f"{repo_name}.yaml", "w") as yaml_file: + yaml_file.write(f"""--- +repo_type: {repo_type} +src_repo: {src_repo} +tag_prefix: "v" +tag_separator: "." +url: {git_link} +""") + +def main(): + cur_path = os.getcwd() + with open("pkg_list", "r") as pkg_list_file: + for repo_name in pkg_list_file: + repo_name = repo_name.strip() + + # Check if the repository exists on Gitee + iter = 1 + while iter <= 5: + headers = {"Authorization": f"token {acess_tocken}"} + response = requests.get(f"https://gitee.com/api/v5/repos/opencloudos-stream/{repo_name}", headers=headers) + if response.status_code == 200: + break + iter += 1 + if iter > 5: + print(f"############# Warning:'{repo_name}' does not exist!!! ##############") + continue + + # repo exists, clone it! + subprocess.run(["git", "clone", "-q", f"https://gitee.com/opencloudos-stream/{repo_name}"]) + os.chdir(repo_name) + + url = subprocess.run("rpmspec -P *.spec | grep 'URL:' | awk '{print $2}'", capture_output=True, text=True, shell=True).stdout.strip() + source0 = subprocess.run("rpmspec -P *.spec | grep 'Source0:' | awk '{print $2}'", capture_output=True, text=True, shell=True).stdout.strip() + + src_repo = None + git_link = None + if url: + repo_type, src_repo = extract_src_repo(repo_name, url) + git_link = url + if not src_repo and source0: + repo_type, src_repo = extract_src_repo(repo_name, source0) + git_link = source0 + + # print (url,source0) + print (f"test:{repo_name},{src_repo}") + if src_repo: + os.chdir(cur_path) + create_yaml(repo_name, repo_type, src_repo, git_link) + + os.chdir(cur_path) + subprocess.run(["rm", "-rf", repo_name]) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/auto_yaml/pkg_list b/auto_yaml/pkg_list new file mode 100644 index 0000000..b2b8c92 --- /dev/null +++ b/auto_yaml/pkg_list @@ -0,0 +1,2 @@ +acpica-tools +asciidoc -- Gitee