在进行测试之前,必须先检查开发的rpm包数据<%2Fp>
包括安装目录,权限,文件结构,是否包含某些文件等信息<%2Fstrong><%2Fp>
写了个脚本自动化<%2Fp>
<%2Fp>
python的rpm包,在网上资料实在不多,时间仓促,也就简单看了下<%2Fp>
<%2Fp>
首先,import<%2Fp>
<%2Fp>
import+rpm<%2Fpre> 获取<%2Fstrong>hdr<%2Fp>
<%2Fp>
def+get_hdr(rpmPath)%3A ++++ts+%3D+rpm.ts() ++++try%3A ++++++fdno+%3D+os.open(rpmPath%2Cos.O_RDONLY) ++++++hdr+%3D+ts.hdrFromFdno(fdno) ++++++os.close(fdno) ++++except%3A ++++++print(%26quot%3BERROR%3A+Init+rpm+error!%26quot%3B) ++++++sys.exit(1) ++++return+hdr+<%2Fpre><%2Fp>
<%2Fp> 接着,可以从hdr获取<%2Fstrong>到包中的各类信息<%2Fstrong>
可以使用help(rpm)查看已经定义好的变量%2C变量基本<%2Fstrong>读下就大概知道什么意思<%2Fp>
主要是RPMTAG_* 以下简单获取<%2Fstrong>自己想要的几项<%2Fp>
<%2Fp>
def+get_rpm_info(file_path)%3A ++++rpm_info+%3D+{} ++++hdr+%3D+get_hdr(file_path) ++++tag_files+%3D+[s+for+s+in+hdr[rpm.RPMTAG_FILENAMES]+if+%26quot%3B.svn%26quot%3B+not+in+s] ++++rpm_info.update({%26quot%3Btag_name%26quot%3B%3Astr(hdr[rpm.RPMTAG_NAME])}) ++++rpm_info.update({%26quot%3Btag_version%26quot%3B%3Astr(hdr[rpm.RPMTAG_VERSION])}) ++++rpm_info.update({%26quot%3Btag_release%26quot%3B%3Astr(hdr[rpm.RPMTAG_R])}) ++++rpm_info.update({%26quot%3Btag_vendor%26quot%3B%3Astr(hdr[rpm.RPMTAG_VENDOR])}) ++++rpm_info.update({%26quot%3Btag_desc%26quot%3B%3Astr(hdr[rpm.RPMTAG_SUMMARY])}) ++++rpm_info.update({%26quot%3Btag_packager%26quot%3B%3Astr(hdr[rpm.RPMTAG_PACKAGER])}) ++++rpm_info.update({%26quot%3Btag_files%26quot%3B%3Asorted(tag_files)}) ++++rpm_info.update({%26quot%3Btag_xml_files%26quot%3B%3A[s+for+s+in+hdr[rpm.RPMTAG_FILENAMES]+if+%26quot%3B.xml%26quot%3B+in+s]}) ++++rpm_info.update({%26quot%3Btag_install_path%26quot%3B%3Aos.path.commonprefix(tag_files)}) ++++return+rpm_info <%2Fpre> 从上到下依次<%2Fp>
包名,版本,release%2C开发者,描述,包所有者,包内文件列表,安装路径<%2Fp>
<%2Fp>
<%2Fp> <%2Fdiv>
来源:http%3A%2F%2Fwww.verydemo.com%2Fdemo_c122_i12298.html<%2Fa><%2Fb>