コード例 #1
0
def compare_versions_with_python_apt(version1, operator, version2):
    """
    Compare Debian package versions using the python-apt_ binding. Compatible
    with newer versions of python-apt_ (:py:func:`apt_pkg.version_compare()`)
    and older versions (:py:func:`apt.VersionCompare()`). Raises
    :py:exc:`NotImplementedError` if python-apt_ is not available (neither of
    the mentioned functions can be imported).

    :param version1: The version on the left side of the comparison (a string).
    :param operator: The operator to use in the comparison (a string).
    :param version2: The version on the right side of the comparison (a string).
    :returns: ``True`` if the comparison succeeds, ``False`` if it fails.
    """
    if not have_python_apt:
        raise NotImplementedError("The python-apt binding is not installed!"
                                  " (or at least the import failed)")
    else:
        result = apt_version_compare(version1, version2)
        return ((operator == '<<' and result < 0) or
                (operator == '>>' and result > 0) or
                (operator in ('<', '<=') and result <= 0) or
                (operator in ('>', '>=') and result >= 0) or
                (operator == '=' and result == 0))
コード例 #2
0
def compare_versions_with_python_apt(version1, operator, version2):
    """
    Compare Debian package versions using the python-apt_ binding. Compatible
    with newer versions of python-apt_ (:py:func:`apt_pkg.version_compare()`)
    and older versions (:py:func:`apt.VersionCompare()`). Raises
    :py:exc:`NotImplementedError` if python-apt_ is not available (neither of
    the mentioned functions can be imported).

    :param version1: The version on the left side of the comparison (a string).
    :param operator: The operator to use in the comparison (a string).
    :param version2: The version on the right side of the comparison (a string).
    :returns: ``True`` if the comparison succeeds, ``False`` if it fails.
    """
    if not have_python_apt:
        raise NotImplementedError("The python-apt binding is not installed!"
                                  " (or at least the import failed)")
    else:
        result = apt_version_compare(version1, version2)
        return ((operator == '<<' and result < 0)
                or (operator == '>>' and result > 0)
                or (operator in ('<', '<=') and result <= 0)
                or (operator in ('>', '>=') and result >= 0)
                or (operator == '=' and result == 0))
コード例 #3
0
def compare_versions_with_python_apt(version1, operator, version2):
    """
    Compare Debian package versions using the python-apt_ binding.

    :param version1: The version on the left side of the comparison (a string).
    :param operator: The operator to use in the comparison (a string).
    :param version2: The version on the right side of the comparison (a string).
    :returns: :data:`True` if the comparison succeeds, :data:`False` if it fails.
    :raises: :exc:`~exceptions.NotImplementedError` if python-apt_ is not
             available (neither of the functions mentioned below can be
             imported).

    This function is compatible with newer versions of python-apt_
    (:func:`apt_pkg.version_compare()`) and older versions
    (:func:`apt.VersionCompare()`).
    """
    if not have_python_apt:
        raise NotImplementedError()
    result = apt_version_compare(version1, version2)
    return ((operator == '<<' and result < 0) or
            (operator == '>>' and result > 0) or
            (operator in ('<', '<=') and result <= 0) or
            (operator in ('>', '>=') and result >= 0) or
            (operator == '=' and result == 0))
コード例 #4
0
ファイル: version.py プロジェクト: zumbi/python-deb-pkg-tools
def compare_versions_with_python_apt(version1, operator, version2):
    """
    Compare Debian package versions using the python-apt_ binding.

    :param version1: The version on the left side of the comparison (a string).
    :param operator: The operator to use in the comparison (a string).
    :param version2: The version on the right side of the comparison (a string).
    :returns: :data:`True` if the comparison succeeds, :data:`False` if it fails.
    :raises: :exc:`~exceptions.NotImplementedError` if python-apt_ is not
             available (neither of the functions mentioned below can be
             imported).

    This function is compatible with newer versions of python-apt_
    (:func:`apt_pkg.version_compare()`) and older versions
    (:func:`apt.VersionCompare()`).
    """
    if not have_python_apt:
        raise NotImplementedError()
    result = apt_version_compare(version1, version2)
    return ((operator == '<<' and result < 0)
            or (operator == '>>' and result > 0)
            or (operator in ('<', '<=') and result <= 0)
            or (operator in ('>', '>=') and result >= 0)
            or (operator == '=' and result == 0))