2016-04-07 140 views
1

我有一個嵌入式平臺,我在其上使用RPM部署應用程序代碼。傳統上,這是在目標平臺上的事實之後完成的(即通過控制檯通過命令行在目標平臺上安裝rpm)。爲了讓生活更輕鬆簡單(或者我認爲),我決定直接將RPM安裝到目標文件系統上,作爲主機上構建過程的一部分。我以爲要使用Python RPM模塊並且與駐留在目標文件系統上的RPM數據庫進行交互。這是我試過(注意RPM數據庫的位置已被修改爲指向目標文件系統的數據庫,而不是默認的主機上):Python rpm模塊不能使用rpm調用回調函數。RPMCALLBACK_INST_OPEN_FILE

#!/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) 

運行上面的腳本後,調用回調三次。首先,用原因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的匹配(意味着數據庫中沒有任何內容)。

任何想法?

回答

1

我想通了,只是發佈我的意見,以防其他人遇到同樣的問題。這裏的問題是,我在應用程序(ARM)和Python庫(x86_64)使用的底層RPM模塊之間存在不兼容的體系結構。我最終認定這是不可能的,因爲在目標平臺上也會有數據庫問題,並最終解決這個問題。