Issue
I am trying to write a python program to get the list of dependencies available for a package using python Yum API.
The following is my code getting the dependencies list similar to "yum deplist chkconfig-1.3.49.3-2.el6". This resulting a list of all the needed packages regardless with the already installed list on the system.
But what i am trying is to write a wrapper that is equivalent to this command "yum update chkconfig-1.3.49.3-2.el6". This command resulting the dependencies that are not installed on the system and that are required.
The following is the code that i have tried so far. And is there any other way for accessing the python Yum API for getting our needs. This is the actual function "customMethod". Other's "compare" and "listCompare" are for comparing the rpms from a list and for getting the latest among them.
import sys, re
import yum, rpm
from yum import _
sys.path.insert(0, '/usr/share/yum-cli')
import output
class YumFrame(yum.YumBase, output.YumOutput):
def __init__(self):
try:
yum.YumBase.__init__(self)
output.YumOutput.__init__(self)
except Exception, e:
raise e
self.pattern1 = re.compile(r'^([a-zA-Z0-9_\-\+]*)-([a-zA-Z0-9_\.]*)-([a-zA-Z0-9_\.]*)')
def compare(self, pkg1, pkg2):
Info1 = self.pattern1.search(pkg1).groups()
Info2 = self.pattern1.search(pkg2).groups()
n1, v1, r1 = Info1
n2, v2, r2 = Info2
if n1 == n2:
return rpm.labelCompare(('1', v1, r1), ('1', v2, r2))
else:
return 2
def listCompare(self, input):
latest = input[0]
refinedList = []
for index, item in enumerate(input):
result = self.compare(item, latest)
if result == 1:
latest = item
elif result == 2:
refinedList.append(item)
refinedList.append(latest)
return refinedList
def customMethod(self, package):
pkgs = []
completeList = []
ematch, match, unmatch = self.pkgSack.matchPackageNames([package])
for po in ematch + match:
pkgs.append(po)
print "Matched Object: " + str(pkgs)
results = self.findDeps(pkgs)
for value in results.itervalues():
for packageObject in value.itervalues():
actualList = []
for item in packageObject:
completeList.append(item.name + "-" + item.ver + "-" + item.rel)
completeList = self.listCompare(completeList)
completeList = list(set(completeList))
return completeList
if __name__ == "__main__":
yumObj = YumFrame()
print yumObj.customMethod("chkconfig-1.3.49.3-2.el6")
Thanks in Advance,
M Ram
Solution
I am not an expert in python but in Yum CLI interface there is a simple way:
yum erase [package name]
It will show you a dependency list before actual deletion.
Hope it helps
Answered By - Ivan Answer Checked By - David Goodson (WPSolving Volunteer)