From 590e9a55501c84ae9a25743b87a1a4e7208c4ed4 Mon Sep 17 00:00:00 2001 From: miao_kaibo Date: Thu, 5 Aug 2021 15:28:56 +0800 Subject: [PATCH] add unable install rpms --- script/config/unable_install_list | 36 +++++++++ script/tools/check_dep.py | 125 ++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 script/tools/check_dep.py diff --git a/script/config/unable_install_list b/script/config/unable_install_list index e69de29..6c2c518 100644 --- a/script/config/unable_install_list +++ b/script/config/unable_install_list @@ -0,0 +1,36 @@ +python3-importlib-resources +mailman +oscilloscope +pacemaker-nagios-plugins-metadata +protobuf2-emacs-el +python3-pylint +pylint +python3-pylama +rubygem-mail-doc +rubygem-sass-rails +rubygem-sass-rails-doc +texlive-babel-vietnamese +texlive-lexikon +texlive-collection-humanities +texlive-collection-langother +vte-devel +wireless-tools +wireless-tools-devel +gimp +python3-nni +texlive-biblatex-apa +texlive-collection-bibtexextra +texlive-collection-binextra +texlive-oldstandard +texlive-collection-fontsextra +texlive-collection-fontutils +texlive-exceltex +texlive-collection-latexextra +texlive-collection-mathscience +texlive-includernw +texlive-ctanupload +texlive-latexindent +texlive-scheme-full +texlive-scheme-gust +texlive-scheme-medium +texlive-scheme-tetex diff --git a/script/tools/check_dep.py b/script/tools/check_dep.py new file mode 100644 index 0000000..db7d236 --- /dev/null +++ b/script/tools/check_dep.py @@ -0,0 +1,125 @@ +import os +import sys +import time +import threading +import platform +import subprocess +import argparse + + +def kill_yumdownloader(rpm_path, thr): + cmd = "ls %s | grep '\.rpm'" % rpm_path + res = os.popen(cmd).read() + while not res: + if not thr.is_alive(): + break + time.sleep(5) + res = os.popen(cmd).read() + cmd = "ps -ef | grep yumdownloader | awk '{print $2}' | xargs kill -9" + os.system(cmd) + + +def set_rpm_list(rpm_list_file, arch, rpm_path, config=None, repo=None): + if config and repo: + para = "-c %s --repo %s" % (config, repo) + elif config: + para = "-c %s" % config + else: + para = "" + cmd = "yum list --installroot=%s --available %s | grep -E '\.%s|\.noarch' | grep -v 'debugsource' | grep -v 'debuginfo'| awk '{print $1 \" \" $2 \" \" $1 \"-\" $2}' > %s" % (rpm_path, para, arch, rpm_list_file) + print(cmd) + if os.system(cmd) == 0: + cmd = "sed -i 's/\.{0}-/-/g' {1} && sed -i 's/\.noarch-/-/g' {2}".format(arch, rpm_list_file, rpm_list_file) + if os.system(cmd) == 0: + pass + else: + return 1 + else: + return 1 + return 0 + + +def set_exclude(f, arch, err, rpm_list_file, delete_rpm_list_file): + rpm_list = [] + print("--------------------------------------------------------------") + for line in err.splitlines(): + if "requires" in line: + print(line) + f.write("%s\n" % line) + if "package" in line: + pkg = line.split("package")[1].split("requires")[0].strip() + if pkg not in rpm_list: + rpm_list.append(pkg) + if "needed by" in line: + print(line) + f.write("%s\n" % line) + pkg = line.split("needed by")[1].strip() + if pkg not in rpm_list: + rpm_list.append(pkg) + if "obsoletes" in line: + print(line) + f.write("%s\n" % line) + pkg = line.split("provided by")[1].strip() + if pkg not in rpm_list: + rpm_list.append(pkg) + for p in rpm_list: + if "noarch" in p: + pkg = p.replace(".noarch", "") + if arch in p: + pkg = p.replace(".%s" % arch, "") + cmd = "cat %s | grep %s | awk '{print $1}' >> %s && sed -i '/%s/d' %s" % (rpm_list_file, pkg, delete_rpm_list_file, \ + pkg, rpm_list_file) + if os.system(cmd) == 0: + pass + else: + print("======== unable install %s" % p) + + +def check_dep(rpm_list_file, check_log_file, delete_rpm_list_file, rpm_path, config=None, repo=None): + if config and repo: + para = "-c %s --repo %s" % (config, repo) + elif config: + para = "-c %s" % config + else: + para = "" + cmd = "rm -rf %s && rm -rf %s && rm -rf %s && rm -rf %s/*.rpm" % (rpm_list_file, check_log_file, delete_rpm_list_file, rpm_path) + if os.system(cmd) == 0: + pass + arch = platform.machine() + if set_rpm_list(rpm_list_file, arch, rpm_path, config=config, repo=repo): + sys.exit(1) + delete_list = [] + cmd="yumdownloader --resolve --installroot=%s --destdir=%s $(cat %s | awk '{print $1}' | tr '\n' ' ') %s" % (rpm_path, rpm_path, rpm_list_file, para) + print(cmd) + p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8") + out, err = p.communicate() + with open(check_log_file, 'w') as f: + while err: + if "Problem" not in err and "No package" not in err: + break + set_exclude(f, arch, err, rpm_list_file, delete_rpm_list_file) + cmd="yumdownloader --resolve --installroot=%s --destdir=%s $(cat %s | awk '{print $1}' | tr '\n' ' ') %s" % (rpm_path, rpm_path, rpm_list_file, para) + print(cmd) + p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8") + out, err = p.communicate() + cmd = "sed -i 's/\.noarch//g' %s && sed -i 's/\.%s//g' %s" % (delete_rpm_list_file, arch, delete_rpm_list_file) + if os.system(cmd) == 0: + pass + print("=================== exclude rpm list start ======================") + print(os.popen("cat %s && rm -rf %s/*.rpm" % (delete_rpm_list_file, rpm_path)).read()) + print("=================== exclude rpm list end ======================") + + +par = argparse.ArgumentParser() +par.add_argument("-d", "--dest_rpm_path", help="path for rpm", required=True) +par.add_argument("-l", "--rpm_list_file", help="file for rpm list", required=True) +par.add_argument("-f", "--check_log_file", help="file for checking log", required=True) +par.add_argument("-e", "--exclude_rpm_list_file", help="file for rpms which are exclude", required=True) +par.add_argument("-c", "--config", help="config file repofile", default=None, required=False) +par.add_argument("-r", "--repo", help="name of repo", default=None, required=False) +args = par.parse_args() + +t1 = threading.Thread(target=check_dep, args=(args.rpm_list_file, args.check_log_file, args.exclude_rpm_list_file, args.dest_rpm_path, args.config, args.repo)) +t1.start() +t2 = threading.Thread(target=kill_yumdownloader, args=(args.dest_rpm_path, t1)) +t2.start() -- Gitee