summaryrefslogtreecommitdiffstats
path: root/src/yum/providers/util/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/yum/providers/util/common.py')
-rw-r--r--src/yum/providers/util/common.py115
1 files changed, 58 insertions, 57 deletions
diff --git a/src/yum/providers/util/common.py b/src/yum/providers/util/common.py
index 7d918a4..f70d22b 100644
--- a/src/yum/providers/util/common.py
+++ b/src/yum/providers/util/common.py
@@ -168,63 +168,6 @@ def match_pkg(pkg, **kwargs):
return False
return True
-def object_path2pkg(env, op, package_list='installed'):
- """
- @param package_list one of {'installed', 'all', 'available'}
- says, where to look for given package
- """
- if not isinstance(op, pywbem.CIMInstanceName):
- raise TypeError("op must be an instance of CIMInstanceName")
- if not isinstance(package_list, basestring):
- raise TypeError("package_list must be a string")
- if not package_list in ('installed', 'all', 'available'):
- raise ValueError('unsupported package list "%s"'%package_list)
-
- tos = get_target_operating_system()[0]
- if ( not op['Name'] or not op['SoftwareElementID']
- or not op['SoftwareElementID'].startswith(op['Name'])
- or op['SoftwareElementID'].find(op['Version']) == -1):
- raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "Wrong keys.")
-# if op['SoftwareElementState'] not in ("2", 2):
-# raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
-# "Only \"Executable\" software element state supported")
- if not check_target_operating_system(op['TargetOperatingSystem']):
- raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
- "Wrong target operating system.")
- if not op['Name'] or not op['Version']:
- raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
- 'Both "Name" and "Version" must be given')
- m = re_nevra.match(op['SoftwareElementID'])
- if not m:
- raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
- "Wrong SotwareElementID. Expected valid nevra"
- " (name-epoch:version-release.arch).")
- if op['Version'] != m.group('ver'):
- raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
- "Version does not match version part in SoftwareElementID.")
- kwargs = dict((k, m.group(k)) for k in
- ('name', 'epoch', 'ver', 'rel', 'arch'))
- with YumDB.getInstance(env) as yb:
- if ( package_list == 'installed'
- and not yb.rpmdb.installed(**kwargs)):
- raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
- "Package not installed")
-
- pl = yb.doPackageLists(package_list,
- showdups=package_list != 'installed')
- if package_list != 'all':
- pl = getattr(pl, package_list)
- else:
- # NOTE: available ∩ installed = ∅
- pl = itertools.chain(pl.available, pl.installed)
- exact,_,_ = yum.packages.parsePackages(pl, [op['Name']])
- for pkg in yum.misc.unique(exact):
- if pkg.evra == m.group('evra'): break
- else:
- raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
- "No matching package found")
- return pkg
-
class YumPackage:
"""
Just a namespace for common function related to YumPackage provider.
@@ -588,6 +531,64 @@ class YumPackage:
return pywbem.Uint16(res)
@staticmethod
+ def object_path2pkg(env, op, package_list='installed'):
+ """
+ @param package_list one of {'installed', 'all', 'available'}
+ says, where to look for given package
+ """
+ if not isinstance(op, pywbem.CIMInstanceName):
+ raise TypeError("op must be an instance of CIMInstanceName")
+ if not isinstance(package_list, basestring):
+ raise TypeError("package_list must be a string")
+ if not package_list in ('installed', 'all', 'available'):
+ raise ValueError('unsupported package list "%s"'%package_list)
+
+ tos = get_target_operating_system()[0]
+ if ( not op['Name'] or not op['SoftwareElementID']
+ or not op['SoftwareElementID'].startswith(op['Name'])
+ or op['SoftwareElementID'].find(op['Version']) == -1):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "Wrong keys.")
+# if op['SoftwareElementState'] not in ("2", 2):
+# raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+# "Only \"Executable\" software element state supported")
+ if not check_target_operating_system(op['TargetOperatingSystem']):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "Wrong target operating system.")
+ if not op['Name'] or not op['Version']:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ 'Both "Name" and "Version" must be given')
+ m = re_nevra.match(op['SoftwareElementID'])
+ if not m:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "Wrong SotwareElementID. Expected valid nevra"
+ " (name-epoch:version-release.arch).")
+ if op['Version'] != m.group('ver'):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "Version does not match version part in SoftwareElementID.")
+ kwargs = dict((k, m.group(k)) for k in
+ ('name', 'epoch', 'ver', 'rel', 'arch'))
+ with YumDB.getInstance(env) as yb:
+ if ( package_list == 'installed'
+ and not yb.rpmdb.installed(**kwargs)):
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "Package not installed")
+
+ pl = yb.doPackageLists(package_list,
+ showdups=package_list != 'installed')
+ if package_list != 'all':
+ pl = getattr(pl, package_list)
+ else:
+ # NOTE: available ∩ installed = ∅
+ pl = itertools.chain(pl.available, pl.installed)
+ exact,_,_ = yum.packages.parsePackages(pl, [op['Name']])
+ for pkg in yum.misc.unique(exact):
+ if pkg.evra == m.group('evra'): break
+ else:
+ raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND,
+ "No matching package found")
+ return pkg
+
+ @staticmethod
def pkg2model_wrapper(namespace, classname):
"""
@return a function that transforms YumAvailablePackage object