LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 04-08-2016, 10:30 AM   #1
mbilloo
LQ Newbie
 
Registered: Apr 2016
Posts: 2

Rep: Reputation: Disabled
Python RPM API not installing to non-default RPM database


I have an embedded platform on which I deploy application code using RPMs. Traditionally this was done after the fact on the target platform (i.e. installing rpm via command line on the target platform through a console). 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. I thought to use the Python RPM module and interacting with the RPM database that resides on the target filesystem. 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):

Code:
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)

rpm.addMacro("_dbpath", "/home/mbilloo/test_rfs/var/lib/rpm/")
trs = rpm.TransactionSet()

fdno = os.open("/home/mbilloo/test_rfs/application.rpm", os.O_RDONLY)
hdr = trs.hdrFromFdno(fdno)
os.close(fdno)

print 'Installing ' + str(hdr['name']) + ' to RFS'
trs.addInstall(hdr, "/home/mbilloo/test_rfs/application.rpm", 'u')
unresolved_deps = trs.check()
if unresolved_deps:
        print "Have unresolved dependencies: %s" % (unresolved_deps,)
        exit
trs.order()
trs.run(runCallback, None)

mi = trs.dbMatch()
print 'size of mi = ' + str(len(mi))
for h in mi:
        print h['name']
A few interesting things happen. First, the RPM database in the target filesystem doesn't get populated (len returned is 0). Secondly, my callback does not get called with reason rpm.RPMCALLBACK_INST_OPEN_FILE nor rpm.RPMCALLBACK_INST_CLOSE_FILE. It first gets called with reason rpm.RPMCALLBACK_TRANS_START, then with reason rpm.RPMCALLBACK_TRANS_PROGRESS, then finally with reason rpm.RPMCALLBACK_TRANS_STOP. Why doesn't the RPM actually get installed into the database after the transaction occurs?
 
Old 04-08-2016, 01:24 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
why not just use yum ???

this is what it is for
 
Old 04-08-2016, 01:59 PM   #3
mbilloo
LQ Newbie
 
Registered: Apr 2016
Posts: 2

Original Poster
Rep: Reputation: Disabled
It's not feasible to install unnecessary binaries such as yum on the embedded platform due to space limitations.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] RPM file conflict when installing a set of files to the same directory as another RPM package brigitor Red Hat 4 01-19-2016 06:51 PM
Python 2.6 dependencies error installing python-sqlite2-2.5.5-1.1.i586.rpm jmp007 Linux - Newbie 1 02-11-2011 11:05 AM
Error message while installing rpm in python janarthananefx Linux - Newbie 3 04-21-2010 10:50 PM
Querying with the RPM Python API 7ofClubs Programming 1 06-11-2007 09:56 AM
RPM database error while installing using yum in fedora core 6 me4linux Fedora 4 04-25-2007 11:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 07:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration