[英]Python rpm module not calling callback with rpm.RPMCALLBACK_INST_OPEN_FILE
我有一個使用 RPM 部署應用程序代碼的嵌入式平台。 傳統上,這是在目標平台上事后完成的(即通過控制台在目標平台上通過命令行安裝 rpm)。 為了讓生活更輕松更簡單(或者我是這么認為的),我決定將 RPM 直接安裝到目標文件系統上,作為主機上構建過程的一部分。 我想使用 Python RPM 模塊並與駐留在目標文件系統上的 RPM 數據庫進行交互。 這是我嘗試過的(請注意,RPM 數據庫位置已修改為指向目標文件系統上的數據庫,而不是主機上的默認值):
#!/usr/bin/python
import os, rpm
rpmtsCallback_fd = None
def runCallback(reason, amount, total, key, client_data):
global rpmtsCallback_fd
print 'callback called with reason' + str(reason)
if reason == rpm.RPMCALLBACK_INST_OPEN_FILE:
print "Opening file."
rpmtsCallback_fd = os.open(key, os.O_RDONLY)
return rpmtsCallback_fd
elif reason == rpm.RPMCALLBACK_INST_CLOSE_FILE:
print "Closing file"
os.close(rpmtsCallback_fd)
def installPackage(ts):
ts.initDB()
fdno = os.open("/home/mbilloo/test_rfs/application.rpm", os.O_RDONLY)
hdr = ts.hdrFromFdno(fdno)
os.close(fdno)
print 'Installing ' + str(hdr['name']) + ' to RFS'
ts.addInstall(hdr, "/home/mbilloo/test_rfs/application.rpm", 'i')
unresolved_deps = ts.check()
if unresolved_deps:
print "Have unresolved dependencies: %s" % (unresolved_deps,)
return
ts.order()
ts.run(runCallback, 1)
def checkPackage(ts):
ts.openDB()
mi = ts.dbMatch()
print 'size of mi = '+ str(len(mi))
rpm.addMacro("_dbpath", "/home/mbilloo/test_rfs/var/lib/rpm/")
trs = rpm.TransactionSet()
trs.setVSFlags(-1)
installPackage(trs)
checkPackage(trs)
運行上述腳本后,回調被調用了 3 次。 首先,原因是 rpm.RPMCALLBACK_TRANS_START,然后是原因 rpm.RPMCALLBACK_TRANS_PROGRESS,最后是原因 rpm.RPMCALLBACK_TRANS_STOP。 根據這里的說明: https ://docs.fedoraproject.org/ro/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch16s06s04.html ,我應該在安裝過程中得到一個 rpm.RPMCALLBACK_INST_OPEN_FILE ,但這從來沒有發生過。
最后,當我在安裝 RPM 后檢查以查看數據庫的內容(即“checkingPackage”)時,我得到長度 0 匹配(意味着數據庫中沒有任何內容)。
有任何想法嗎?
我想通了這一點,只是發布我的觀察,以防其他人遇到同樣的問題。 這里的問題是我在應用程序 (ARM) 和 python 庫 (x86_64) 使用的底層 RPM 模塊之間存在不兼容的架構。 我最終確定這是不可能的,因為目標平台上也會存在數據庫問題,並最終解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.