summaryrefslogtreecommitdiffstats
path: root/src/software/lmi/software/yumdb/process.py
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2013-08-22 09:37:03 +0200
committerMichal Minar <miminar@redhat.com>2013-08-23 06:47:40 +0200
commit00d048f15816a319044f192d8a12e09b96f8bf72 (patch)
tree3273f7cd1a19dcbb21ea8f2b63e55ebb808d15ff /src/software/lmi/software/yumdb/process.py
parent1ad3a75d07f2b8d1d0518d76c83c3fb26540bdbe (diff)
downloadopenlmi-providers-00d048f15816a319044f192d8a12e09b96f8bf72.tar.gz
openlmi-providers-00d048f15816a319044f192d8a12e09b96f8bf72.tar.xz
openlmi-providers-00d048f15816a319044f192d8a12e09b96f8bf72.zip
software: added FindIdentity() function
Since disablement of SoftwareIdentity enumeration, there has been no way to search for particular package (using [WC]QL query for example). This serious limitation is now treated by this addition to LMI_SoftwareInstallationService.
Diffstat (limited to 'src/software/lmi/software/yumdb/process.py')
-rw-r--r--src/software/lmi/software/yumdb/process.py33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/software/lmi/software/yumdb/process.py b/src/software/lmi/software/yumdb/process.py
index 07bca8f..1745e49 100644
--- a/src/software/lmi/software/yumdb/process.py
+++ b/src/software/lmi/software/yumdb/process.py
@@ -29,6 +29,7 @@ import logging
from multiprocessing import Process
import os
import Queue as TQueue # T as threaded
+import re
import sys
import time
import traceback
@@ -52,11 +53,14 @@ LOG = None
# *****************************************************************************
# Utilities
# ****************************************************************************
-def _get_package_filter_function(filters):
+def _get_package_filter_function(filters, exact_match=True):
"""
- @param filters is a dictionary, where keys are package property
- names and values are their desired values.
- @return a function used to filter list of packages
+ :param filters: (``dict``) Dictionary with keys of package property
+ names and values of their desired values.
+ :param exact_match: (``bool``) Whether the ``name`` should be checked
+ for exact match or for presence in package's name or summary
+ strings.
+ :rtype: (``function``) A function used to filter list of packages.
"""
if not isinstance(filters, dict):
raise TypeError("filters must be a dictionary")
@@ -78,6 +82,7 @@ def _get_package_filter_function(filters):
elif "evra" in filters:
for prop_name in ("epoch", "version", "release", "epoch"):
filters.pop(prop_name, None)
+
filter_list = []
# properties are sorted by their filtering ability
# (the most unprobable property, that can match, comes first)
@@ -85,10 +90,20 @@ def _get_package_filter_function(filters):
"release", "repoid", "arch"):
if not prop_name in filters:
continue
+ if not exact_match and 'name' in filters:
+ continue
filter_list.append((prop_name, filters.pop(prop_name)))
- def _cmp_props(pkg):
- """@return True if pkg matches properies filter"""
- return all(getattr(pkg, p) == v for p, v in filter_list)
+ if not exact_match and 'name' in filters:
+ re_name = re.compile(re.escape(filters['name']))
+ def _cmp_props(pkg):
+ """ :rtype: (``bool``) Does pkg matche properies filter? """
+ if re_name.search(pkg.name) or re_name.search(pkg.summary):
+ return all(getattr(pkg, p) == v for p, v in filter_list)
+ return False
+ else:
+ def _cmp_props(pkg):
+ """ :rtype: (``bool``) Does pkg matche properies filter? """
+ return all(getattr(pkg, p) == v for p, v in filter_list)
return _cmp_props
class RepoFilterSetter(object):
@@ -570,7 +585,7 @@ class YumWorker(Process):
@_needs_database
def _handle_filter_packages(self, kind, allow_duplicates, sort,
- include_repos=None, exclude_repos=None,
+ exact_match=True, include_repos=None, exclude_repos=None,
transform=True, **filters):
"""
Handler for filtering packages job.
@@ -588,7 +603,7 @@ class YumWorker(Process):
pkglist = self._handle_get_package_list(kind, allow_duplicates, False,
include_repos=include_repos, exclude_repos=exclude_repos,
transform=False)
- matches = _get_package_filter_function(filters)
+ matches = _get_package_filter_function(filters, exact_match)
result = [p for p in pkglist if matches(p)]
if sort is True:
result.sort()