Python获取rpm包基本信息[import rpm]

在进行测试之前,必须先检查开发的rpm包数据

包括安装目录,权限,文件结构,是否包含某些文件等信息

写了个脚本自动化


python的rpm包,在网上资料实在不多,时间仓促,也就简单看了下


首先,import

import rpm
获取hdr

def get_hdr(rpmPath): ts = rpm.ts() try: fdno = os.open(rpmPath,os.O_RDONLY) hdr = ts.hdrFromFdno(fdno) os.close(fdno) except: print("ERROR: Init rpm error!") sys.exit(1) return hdr


接着,可以从hdr获取到包中的各类信息

可以使用help(rpm)查看已经定义好的变量,变量基本读下就大概知道什么意思

主要是RPMTAG_*
以下简单获取自己想要的几项

def get_rpm_info(file_path): rpm_info = {} hdr = get_hdr(file_path) tag_files = [s for s in hdr[rpm.RPMTAG_FILENAMES] if ".svn" not in s] rpm_info.update({"tag_name":str(hdr[rpm.RPMTAG_NAME])}) rpm_info.update({"tag_version":str(hdr[rpm.RPMTAG_VERSION])}) rpm_info.update({"tag_release":str(hdr[rpm.RPMTAG_R])}) rpm_info.update({"tag_vendor":str(hdr[rpm.RPMTAG_VENDOR])}) rpm_info.update({"tag_desc":str(hdr[rpm.RPMTAG_SUMMARY])}) rpm_info.update({"tag_packager":str(hdr[rpm.RPMTAG_PACKAGER])}) rpm_info.update({"tag_files":sorted(tag_files)}) rpm_info.update({"tag_xml_files":[s for s in hdr[rpm.RPMTAG_FILENAMES] if ".xml" in s]}) rpm_info.update({"tag_install_path":os.path.commonprefix(tag_files)}) return rpm_info
从上到下依次

包名,版本,release,开发者,描述,包所有者,包内文件列表,安装路径



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值