#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
import re
import six
"""Returns a tuple of (valid, error) indicating whether the provided
string is a valid name for a link mediation. 'valid' is a boolean
and 'error' is None or a string containing the error."""
return True, None
return False, _("'{0}' is not a valid mediator; only alphanumeric "
"""Returns a tuple of (valid, error) indicating whether the provided
string is a valid mediator version for a link mediation. 'valid' is
a boolean and 'error' is None or a string containing the error."""
error = ""
try:
return True, None
except version.VersionError as e:
if error:
return False, _("'{value}' is not a valid mediator-version: "
"""Parses the provided mediator implementation string for a link and
returns a tuple of (name, version) where 'name' is a string containing
the name of the implementation and 'version' is None or a pkg.version
object representing the version. If the implementation is not valid
a tuple of (None, None) will be returned."""
return None, None
if "@" in value:
try:
except (ValueError, AttributeError):
# Can't parse implementation correctly, so
# return a tuple of None.
return None, None
else:
impl_ver = None
if impl_ver:
try:
except version.VersionError:
# If part of implementation can't be parsed, then
# return nothing at all.
return None, None
"""Returns a tuple of (valid, error) indicating whether the provided
string is a valid mediator implementation for mediated links. 'valid' is
a boolean and 'error' is None or a string containing the error."""
error = ""
if "@" in value:
else:
try:
except version.VersionError as e:
return True, None
if error:
return False, _("'{value}' is not a valid "
"mediator-implementation; only alphanumeric characters and "
"a version dot-sequence following a single '@' are allowed: "
return False, _("'{0}' is not a valid mediator-implementation; only "
"alphanumeric characters and a version dot-sequence following a "
"""Returns a tuple of (valid, error) indicating whether the provided
string is a valid mediator priority for mediated links. 'valid' is
a boolean and 'error' is None or a string containing the error."""
return True, None
return False, _("'{0}' is not a valid mediator-priority; valid values "
# A ranking dictionary used by cmp_mediations for sorting mediatoins based on
# mediator priority for mediated links.
_MED_PRIORITIES = {
"site": 1,
"vendor": 2
}
def cmp_mediations(a, b):
"""Custom mediation sorting routine. Sort is done by
priority, version, implementation name, implementation
version.
"""
if res != 0:
return res
aver = a[1]
bver = b[1]
if res != 0:
# Invert version sort so greatest is first.
return res * -1
if res != 0:
return res
if res != 0:
# Invert version sort so greatest is first.
return res * -1
return 0
def mediator_impl_matches(a, b):
"""Returns a boolean indicating whether two given mediator implementation
strings match. This is needed because an unversioned implementation is
matches both versioned and unversioned implementations. This function
assumes that the values being compared are valid.
"""
if a == b:
return True
return False
# If version component of either a or b is None, that
# means the implementation was specified as 'impl'
# which allows any version to match. Otherwise,
# version components must match exactly.