7 Star 1 Fork 7

BigSkySea / mkbshare

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
check_rpm_dep.py 2.50 KB
一键复制 编辑 原始数据 按行查看 历史
BigSkySea 提交于 2021-08-19 14:08 . update
import os
import re
import sys
import subprocess
import argparse
import platform
ARCH = platform.machine()
cmd = "yum list --installroot=/tmp --available | grep -E '\.%s|\.noarch' | grep -v 'debugsource' | grep -v 'debuginfo'| awk '{print $1}' > allist" % ARCH
print(cmd)
if os.system(cmd) == 0:
pass
else:
sys.exit(1)
rpmlist=[]
excludelist = ""
deletelist = []
cmd="yumdownloader --resolve --installroot=/tmp --destdir=/tmp $(cat allist | tr '\n' ' ')"
p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
out, err = p.communicate()
with open("checklog.txt", 'w') as f:
while err:
print("============== %s ============" % err)
if "Problem" not in err and "No package" not in err:
break
for line in err.splitlines():
if "requires" in line:
f.write("%s\n" % line)
if "package" in line:
pkg = line.split("package")[1].split("requires")[0].strip()
if pkg not in rpmlist:
rpmlist.append(pkg)
if "needed by" in line:
f.write("%s\n" % line)
pkg = line.split("needed by")[1].strip()
if pkg not in rpmlist:
rpmlist.append(pkg)
for p in rpmlist:
excludelist = excludelist + " -x %s" % p
cmd="yumdownloader --resolve --installroot=/tmp --destdir=/tmp $(cat allist | tr '\n' ' ') %s" % excludelist
p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
out, err = p.communicate()
if err:
for line in err.splitlines():
if "No package" in line:
pkg = line.split("No package")[1].split("available")[0].strip()
cmd = "sed -i '/%s/d' allist" % pkg
if os.system(cmd) == 0:
pass
if pkg not in deletelist:
deletelist.append(pkg)
cmd="yumdownloader --resolve --installroot=/tmp --destdir=/tmp $(cat allist | tr '\n' ' ') %s" % excludelist
p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
out, err = p.communicate()
print("++++++++++ %s ++++++++++++" % out)
for p in deletelist:
cmd = "echo %s >> deletelist" % p
if os.system(cmd) == 0:
pass
cmd = "sed -i 's/\.%s//g' deletelist && sed -i 's/\.noarch//g' deletelist" % ARCH
os.system(cmd)
1
https://gitee.com/BigSkySea/mkbshare.git
git@gitee.com:BigSkySea/mkbshare.git
BigSkySea
mkbshare
mkbshare
master

搜索帮助