mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
optionally use rpm python module instead of calling a
external executable, to avoid the cost of forking. Since python-rpm is not automatically present, we still fallback on the slower rpm fork method.
This commit is contained in:
parent
9482815b71
commit
0d8b81cd95
1 changed files with 9 additions and 0 deletions
|
@ -76,11 +76,18 @@ import json
|
|||
import shlex
|
||||
import os
|
||||
import sys
|
||||
try:
|
||||
import rpm
|
||||
USE_PYTHON = True
|
||||
except ImportError:
|
||||
USE_PYTHON = False
|
||||
|
||||
URPMI_PATH = '/usr/sbin/urpmi'
|
||||
URPME_PATH = '/usr/sbin/urpme'
|
||||
|
||||
def query_package(module, name):
|
||||
if USE_PYTHON:
|
||||
return rpm.TransactionSet().dbMatch(rpm.RPMTAG_NAME, name).count() != 0
|
||||
|
||||
# rpm -q returns 0 if the package is installed,
|
||||
# 1 if it is not installed
|
||||
|
@ -91,6 +98,8 @@ def query_package(module, name):
|
|||
return False
|
||||
|
||||
def query_package_provides(module, name):
|
||||
if USE_PYTHON:
|
||||
return rpm.TransactionSet().dbMatch(rpm.RPMTAG_PROVIDES, name).count() != 0
|
||||
|
||||
# rpm -q returns 0 if the package is installed,
|
||||
# 1 if it is not installed
|
||||
|
|
Loading…
Reference in a new issue