简体   繁体   English

Python rpm 模块不使用 rpm.RPMCALLBACK_INST_OPEN_FILE 调用回调

[英]Python rpm module not calling callback with rpm.RPMCALLBACK_INST_OPEN_FILE

I have an embedded platform on which I deploy application code using RPMs.我有一个使用 RPM 部署应用程序代码的嵌入式平台。 Traditionally this was done after the fact on the target platform (ie installing rpm via command line on the target platform through a console).传统上,这是在目标平台上事后完成的(即通过控制台在目标平台上通过命令行安装 rpm)。 To make life easier and simpler (or so I thought), I decided to directly install the RPM onto the target filesystem as part of the build process on the host.为了让生活更轻松更简单(或者我是这么认为的),我决定将 RPM 直接安装到目标文件系统上,作为主机上构建过程的一部分。 I thought to use the Python RPM module and interacting with the RPM database that resides on the target filesystem.我想使用 Python RPM 模块并与驻留在目标文件系统上的 RPM 数据库进行交互。 Here's what I tried (note that the RPM database location has been modified to point to the database on the target filesystem as opposed to the default on the host):这是我尝试过的(请注意,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)

After running the above script, the callback is called three times.运行上述脚本后,回调被调用了 3 次。 First, with reason rpm.RPMCALLBACK_TRANS_START, then with reason rpm.RPMCALLBACK_TRANS_PROGRESS, then finally with reason rpm.RPMCALLBACK_TRANS_STOP.首先,原因是 rpm.RPMCALLBACK_TRANS_START,然后是原因 rpm.RPMCALLBACK_TRANS_PROGRESS,最后是原因 rpm.RPMCALLBACK_TRANS_STOP。 According to the instructions here: https://docs.fedoraproject.org/ro/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch16s06s04.html , I should be getting a rpm.RPMCALLBACK_INST_OPEN_FILE during the installation, but this never happens.根据这里的说明: https ://docs.fedoraproject.org/ro/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch16s06s04.html ,我应该在安装过程中得到一个 rpm.RPMCALLBACK_INST_OPEN_FILE ,但这从来没有发生过。

Finally, when I check to the see the contents of the database (ie "checkingPackage") after installing the RPM, I get length 0 match (meaning there is nothing in the database).最后,当我在安装 RPM 后检查以查看数据库的内容(即“checkingPackage”)时,我得到长度 0 匹配(意味着数据库中没有任何内容)。

Any ideas?有任何想法吗?

I figured this out and just posting my observations in case anyone else runs into the same issue.我想通了这一点,只是发布我的观察,以防其他人遇到同样的问题。 The problem here was that I had an incompatible architecture between the application (ARM) and the underlying RPM module used by the python library (x86_64).这里的问题是我在应用程序 (ARM) 和 python 库 (x86_64) 使用的底层 RPM 模块之间存在不兼容的架构。 I ultimately determined that this is not possible as there will be database issues on the target platform as well, and ended up working around this issue.我最终确定这是不可能的,因为目标平台上也会存在数据库问题,并最终解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM