
We only want the is_compatible() function in oslo.utils, so remove everything else from the module as we move it into place. Change-Id: Id63c7584bb3b6951897ca58dd0289b09b5d12f09
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
# Copyright (c) 2013 OpenStack Foundation
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
"""
|
|
Helpers for comparing version strings.
|
|
"""
|
|
|
|
import logging
|
|
|
|
import pkg_resources
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
def is_compatible(requested_version, current_version, same_major=True):
|
|
"""Determine whether `requested_version` is satisfied by
|
|
`current_version`; in other words, `current_version` is >=
|
|
`requested_version`.
|
|
|
|
:param requested_version: version to check for compatibility
|
|
:param current_version: version to check against
|
|
:param same_major: if True, the major version must be identical between
|
|
`requested_version` and `current_version`. This is used when a
|
|
major-version difference indicates incompatibility between the two
|
|
versions. Since this is the common-case in practice, the default is
|
|
True.
|
|
:returns: True if compatible, False if not
|
|
"""
|
|
requested_parts = pkg_resources.parse_version(requested_version)
|
|
current_parts = pkg_resources.parse_version(current_version)
|
|
|
|
if same_major and (requested_parts[0] != current_parts[0]):
|
|
return False
|
|
|
|
return current_parts >= requested_parts
|