diff --git a/tools/check_package_binary_archive.py b/tools/check_package_binary_archive.py index 7d6f2f4777c9a8b3bbaf40efa327f731572fdac0..429b9e2f0526bddadbba7b5a9e01554072848450 100644 --- a/tools/check_package_binary_archive.py +++ b/tools/check_package_binary_archive.py @@ -27,37 +27,32 @@ import smtplib from email.mime.text import MIMEText from email.header import Header -par = argparse.ArgumentParser() -par.add_argument("-p", "--project", default=None, help="obs project name", required=True) -par.add_argument("-dp", "--dep_project", default=None, - help="obs binary dependent project, example:openEuler:selfbuild:BaseOS", required=True) -par.add_argument("-dr", "--dep_repo", default=None, - help="dependent repo name, example:mainline_standard_aarch64", required=True) -par.add_argument("-a", "--arch", default=None, - help="architecture name, example:aarch64", required=True) -par.add_argument("-ip", "--obs_ip", default=None, help="obs server ipaddress", required=True) -par.add_argument("-ou", "--obs_user", default=None, help="obs server user", required=True) -par.add_argument("-opwd", "--obs_password", default=None, help="obs server password", required=True) -par.add_argument("-eu", "--email_user", help="email user name", required=True) -par.add_argument("-epwd", "--email_passwd", help="email user password", required=True) -par.add_argument("-tu", "--to_addr", help="recive email user", required=True) -args = par.parse_args() - -branch = args.project.replace(":", "-") -gitee_repo_path = os.path.join(os.getcwd(), "obs_pkg_rpms") -yaml_file = os.path.join(gitee_repo_path, "repo_files", "%s_%s.yaml" % (branch, args.arch)) -full_path = os.path.join("/srv/obs/build", args.dep_project, args.dep_repo, args.arch, ":full") - +def parse_arguments(): + """ + 解析命令行参数 + """ + par = argparse.ArgumentParser() + par.add_argument("-p", "--project", help="obs project name", required=True) + par.add_argument("-dp", "--dep_project", help="obs binary dependent project, example:openEuler:selfbuild:BaseOS", required=True) + par.add_argument("-dr", "--dep_repo", help="dependent repo name, example:mainline_standard_aarch64", required=True) + par.add_argument("-a", "--arch", help="architecture name, example:aarch64", required=True) + par.add_argument("-ip", "--obs_ip", help="obs server ipaddress", required=True) + par.add_argument("-ou", "--obs_user", help="obs server user", required=True) + par.add_argument("-opwd", "--obs_password", help="obs server password", required=True) + par.add_argument("-eu", "--email_user", help="email user name", required=True) + par.add_argument("-epwd", "--email_passwd", help="email user password", required=True) + par.add_argument("-tu", "--to_addr", help="receive email user", required=True) + return par.parse_args() -def git_clone(): +def git_clone(gitee_repo_path): """ - git clone gitee repo + 克隆 Gitee 仓库 """ if os.path.exists(gitee_repo_path): shutil.rmtree(gitee_repo_path) git_url = "https://gitee.com/openeuler_latest_rpms/obs_pkg_rpms.git" cmd = "git clone --depth 1 %s" % git_url - for i in range(5): + for _ in range(5): if os.system(cmd) != 0: print("[ERROR]: Git clone failed, try again...") else: @@ -66,9 +61,9 @@ def git_clone(): if not os.path.exists(gitee_repo_path): sys.exit(1) -def read_yaml(): +def read_yaml(yaml_file): """ - read yaml file + 读取 YAML 文件 """ rpmlist = [] if os.path.exists(yaml_file): @@ -76,17 +71,16 @@ def read_yaml(): file_msg = yaml.load(f, Loader=yaml.SafeLoader) for rpm in file_msg.values(): rpmlist.extend(rpm) - shutil.rmtree(gitee_repo_path) return rpmlist -def get_server_rpmlist(): +def get_server_rpmlist(obs_ip, obs_user, obs_password, full_path): """ - get obs server dependent repos binary list + 获取 OBS 服务器上依赖仓库的二进制列表 """ pmk = paramiko.SSHClient() key = paramiko.AutoAddPolicy() pmk.set_missing_host_key_policy(key) - pmk.connect(args.obs_ip, "22", args.obs_user, args.obs_password, timeout=5) + pmk.connect(obs_ip, "22", obs_user, obs_password, timeout=5) cmd = "cd %s && ls *.rpm | grep -v 'src.rpm'" % full_path stdin, stdout, stderr = pmk.exec_command(cmd) error_msg = stderr.readlines() @@ -95,58 +89,61 @@ def get_server_rpmlist(): sys.exit(1) server_rpmlist = [] for line in stdout.readlines(): - server_rpmlist.append(line.replace("\n", "")) + server_rpmlist.append(line.strip()) return server_rpmlist -def rpm_exist(rpmlist, server_rpmlist): +def check_binary_archive(project, dep_project, dep_repo, arch, obs_ip, obs_user, obs_password, email_user, email_passwd, to_addr): """ - check rpms archive + 检查二进制包归档完整性并发送邮件通知 """ - notfind = [] - for rpm in rpmlist: - if rpm and rpm.endswith(".rpm") and rpm not in server_rpmlist: - notfind.append(rpm) + branch = project.replace(":", "-") + gitee_repo_path = os.path.join(os.getcwd(), "obs_pkg_rpms") + yaml_file = os.path.join(gitee_repo_path, "repo_files", "%s_%s.yaml" % (branch, arch)) + full_path = os.path.join("/srv/obs/build", dep_project, dep_repo, arch, ":full") + + if arch not in dep_repo: + print("[ERROR]: %s and %s are not match." % (dep_repo, arch)) + sys.exit(1) + + git_clone(gitee_repo_path) + rpmlist = read_yaml(yaml_file) + server_rpmlist = get_server_rpmlist(obs_ip, obs_user, obs_password, full_path) + + notfind = [rpm for rpm in rpmlist if rpm.endswith(".rpm") and rpm not in server_rpmlist] if notfind: - msg = "
%s %s some binary not archived into %s as follows:
" %( - args.project, args.arch, full_path) + msg = "%s %s some binaries are missing in %s:
" % (project, arch, full_path) print(msg) for line in notfind: - msg = msg + "