/usr/lib/python2.6/site-packages/oslo_utils
NameSizeModeActions
locale/-0755rm
tests/-0755rm
encodeutils.py63090644editdlrm
encodeutils.pyc34620644editdlrm
eventletutils.py52660644editdlrm
eventletutils.pyc32300644editdlrm
excutils.py94070644editdlrm
excutils.pyc88180644editdlrm
fileutils.py28380644editdlrm
fileutils.pyc29850644editdlrm
fixture.py15560644editdlrm
fixture.pyc17320644editdlrm
fnmatch.py26000644editdlrm
fnmatch.pyc21000644editdlrm
imageutils.py66400644editdlrm
imageutils.pyc48470644editdlrm
importutils.py23590644editdlrm
importutils.pyc24720644editdlrm
netutils.py114780644editdlrm
netutils.pyc111440644editdlrm
reflection.py70150644editdlrm
reflection.pyc61910644editdlrm
secretutils.py13170644editdlrm
secretutils.pyc9980644editdlrm
strutils.py91050644editdlrm
strutils.pyc80680644editdlrm
timeutils.py147390644editdlrm
timeutils.pyc169140644editdlrm
units.py9220644editdlrm
units.pyc5930644editdlrm
uuidutils.py13490644editdlrm
uuidutils.pyc12650644editdlrm
versionutils.py26190644editdlrm
versionutils.pyc29240644editdlrm
_i18n.py11580644editdlrm
_i18n.pyc5400644editdlrm
__init__.py00644editdlrm
__init__.pyc1420644editdlrm
Edit: /usr/lib/python2.6/site-packages/oslo_utils/versionutils.py (2619B)
# 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 from oslo_utils._i18n import _ import pkg_resources import six 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 def convert_version_to_int(version): try: if isinstance(version, six.string_types): version = convert_version_to_tuple(version) if isinstance(version, tuple): return six.moves.reduce(lambda x, y: (x * 1000) + y, version) except Exception as ex: msg = _("Version %s is invalid.") % version six.raise_from(ValueError(msg), ex) def convert_version_to_str(version_int): version_numbers = [] factor = 1000 while version_int != 0: version_number = version_int - (version_int // factor * factor) version_numbers.insert(0, six.text_type(version_number)) version_int = version_int // factor return '.'.join(map(str, version_numbers)) def convert_version_to_tuple(version_str): return tuple(int(part) for part in version_str.split('.'))