コード例 #1
0
ファイル: fancylogger.py プロジェクト: vsoch/vsc-base
    def deprecated(self,
                   msg,
                   cur_ver,
                   max_ver,
                   depth=2,
                   exception=None,
                   log_callback=None,
                   *args,
                   **kwargs):
        """
        Log deprecation message, throw error if current version is passed given threshold.

        Checks only major/minor version numbers (MAJ.MIN.x) by default, controlled by 'depth' argument.
        """
        if log_callback is None:
            log_callback = self.warning

        loose_cv = LooseVersion(cur_ver)
        loose_mv = LooseVersion(max_ver)

        loose_cv.version = loose_cv.version[:depth]
        loose_mv.version = loose_mv.version[:depth]

        if loose_cv >= loose_mv:
            self.raiseException(
                "DEPRECATED (since v%s) functionality used: %s" %
                (max_ver, msg),
                exception=exception)
        else:
            deprecation_msg = "Deprecated functionality, will no longer work in v%s: %s" % (
                max_ver, msg)
            log_callback(deprecation_msg)
コード例 #2
0
ファイル: fancylogger.py プロジェクト: ocaisa/vsc-base
    def deprecated(self, msg, cur_ver, max_ver, depth=2, exception=None, *args, **kwargs):
        """
        Log deprecation message, throw error if current version is passed given threshold.

        Checks only major/minor version numbers (MAJ.MIN.x) by default, controlled by 'depth' argument.
        """
        loose_cv = LooseVersion(cur_ver)
        loose_mv = LooseVersion(max_ver)

        loose_cv.version = loose_cv.version[:depth]
        loose_mv.version = loose_mv.version[:depth]

        if loose_cv >= loose_mv:
            self.raiseException("DEPRECATED (since v%s) functionality used: %s" % (max_ver, msg), exception=exception)
        else:
            deprecation_msg = "Deprecated functionality, will no longer work in v%s: %s" % (max_ver, msg)
            self.warning(deprecation_msg)
コード例 #3
0
ファイル: functions.py プロジェクト: jplotnikov/cikit
def ensure_version(versions, unsupported=None):
    """
    :param dict[str, str] versions:
        The required keys are "min" and "current". The value must be a valid X.Y.Z semver.
        Example:
        {
            'min': '2.4.3',
            'current': '2.0.1',
        }
    :param dict[str, list[str]] unsupported:
        Example:
        {
            '2.5.1': [
                # The list of issues that break the stuff.
                'https://github.com/ansible/ansible/issues/39007',
                'https://github.com/ansible/ansible/issues/39014',
            ],
        }
    :return LooseVersion:
        An instance of the "versions['current']".
    """
    for key, value in versions.iteritems():
        value = value.strip()

        if '' == value:
            raise ValueError('The version must be in "X.Y.Z" format.')

        versions[key] = LooseVersion(value.strip())
        # Allow 3 parts maximum.
        versions[key].version = versions[key].version[:3]

    version_current = str(versions['current'])
    error_message = []

    if unsupported is None:
        unsupported = {}

    def add_issues(text, version, spaces=2):
        return error_message.append(
            text % (version,
                    ('\n%s- ' %
                     (' ' * spaces)).join([''] + unsupported.pop(version))))

    if versions['current'] < versions['min']:
        error_message.append(
            'You must have Ansible version greater or equal to %s while the current one is %s.'
            % (
                versions['min'],
                versions['current'],
            ))

    if version_current in unsupported:
        add_issues(
            'Ansible %s is not supported due to the following issues:%s',
            version_current)

    # An error exists when the current version is less than minimum required or when it's denied for usage.
    if bool(error_message):
        # The "add_issues()" pops the key from the "unsupported" dictionary so if there is only one item
        # and the current version isn't supported the dictionary will become empty.
        if bool(unsupported):
            error_message.append(
                'Please bear in mind the following versions are not supported too:'
            )

            # Show the other unsupported versions.
            for version_unsupported in unsupported.keys():
                add_issues('  - %s%s', version_unsupported, 4)

        error('\n'.join(error_message), EINVAL)

    return versions['current']