当我尝试在Linux环境中读取RPM数据库时遇到错误。在某些RHEL版本上,它可以完美运行,但有时会失败。同样适用于CentOS或RHL。
我尝试从数据库中读取软件包的名称,版本,供应商。调用该函数时,显示“ VALUE FOR OPEN RPM DB”。
首先,我们有读取已安装软件包的方法
# Read installed package
mi = self._rpmdb.dbMatch()
for h in mi:
name = h[rpm.RPMTAG_NAME].decode()
version = h[rpm.RPMTAG_VERSION].decode()
vendor = h[rpm.RPMTAG_VENDOR].decode()
appmdl = Application.objects.create()
appmdl.name = name
appmdl.version = version
appmdl.vendor = vendor
appmdl.save()
os_model.apps.add(appmdl)
self.progress += self._one_percent
current = int(self.progress * 100 / self.total)
self.main_parser.progress = str(current) + r'%'
try:
self.main_parser.check_cancelled()
except Exception as exc:
self._close_rpmdb()
raise exc
# Close RPM DB
self._close_rpmdb()
然后,我打开了databse函数:
def _open_rpmdb(self, dbpath):
'''
Open RPM database.
'''
rpmdb = ifind(dbpath)
if rpmdb:
rpm.addMacro('_dbpath', rpmdb)
solvets = rpm.TransactionSet()
logging.info("Value for open rpm DB: {}".format(solvets.openDB()))
if solvets.openDB() == 0:
self._rpmdb = solvets
在这里,我打电话给我:
# Open rpm database
self._open_rpmdb(os_root + os.sep + r'var/lib/rpm/')
有时,'format(solvets.openDB()')返回的值将返回负值,类似于-31580,这意味着未读取RPM数据库;否则,在运行读取时,返回的值为0
我尝试更新所有已安装的软件包,但是没有任何效果。从某种意义上说,我正在寻找一种方法,使其可以在RedHat的每个功能上使用