Merge pull request #2706 from fatbox/rpm-faster-version

Speed up yum/rpm version() if we're not looking for something specific
This commit is contained in:
Thomas S Hatch 2012-11-26 09:29:31 -08:00
commit be8ecf2cd4

View File

@ -175,7 +175,18 @@ def version(name):
salt '*' pkg.version <package name>
'''
pkgs = list_pkgs(name)
# since list_pkgs is used to support matching complex versions
# we can search for a digit in the name and if one doesn't exist
# then just use the dbMatch function, which is 1000 times quicker
m = re.search("[0-9]", name)
if m:
pkgs = list_pkgs(name)
else:
ts = rpm.TransactionSet()
mi = ts.dbMatch('name', name)
pkgs = {}
for h in mi:
pkgs[h['name']] = "-".join([h['version'], h['release']])
if name in pkgs:
return pkgs[name]
else: