# Path: src/stratis_cli/_errors.py
# class StratisCliStratisdVersionError(StratisCliRuntimeError):
#     """
#     Raised if stratisd version does not meet CLI version requirements.
#     """
# 
#     def __init__(self, actual_version, minimum_version, maximum_version):
#         """
#         Initializer.
#         :param tuple actual_version: stratisd's actual version
#         :param tuple minimum_version: the minimum version required
#         :param tuple maximum_version: the maximum version allowed
#         """
#         # pylint: disable=super-init-not-called
#         self.actual_version = actual_version
#         self.minimum_version = minimum_version
#         self.maximum_version = maximum_version
# 
#     def __str__(self):
#         fmt_str = (
#             "stratisd version %s does not meet stratis version "
#             "requirements; the version must be at least %s and no more "
#             "than %s"
#         )
#         return fmt_str % (
#             self.actual_version,
#             self.minimum_version,
#             self.maximum_version,
#         )
# 
# Path: src/stratis_cli/_actions/_connection.py
# def get_object(object_path):
#     """
#     Get an object from an object path.
# 
#     :param str object_path: an object path with a valid format
#     :returns: the proxy object corresponding to the object path
#     :rtype: ProxyObject
#     """
#     return Bus.get_bus().get_object(SERVICE, object_path, introspect=False)
# 
# Path: src/stratis_cli/_actions/_constants.py
# MAXIMUM_STRATISD_VERSION = "4.0.0"
# 
# MINIMUM_STRATISD_VERSION = "3.1.0"
# 
# TOP_OBJECT = "/org/storage/stratis3"


from packaging.specifiers import SpecifierSet, Version
from .._errors import StratisCliStratisdVersionError
from ._connection import get_object
from ._constants import MAXIMUM_STRATISD_VERSION, MINIMUM_STRATISD_VERSION, TOP_OBJECT
    from ._data import Manager0
#
# 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.
"""
Check version of stratisd
"""

# isort: THIRDPARTY



def check_stratisd_version():
    """
    Checks that the version of stratisd that is running is compatible with
    this version of the CLI.

    :raises StratisCliStratisdVersionError
    """
    # pylint: disable=import-outside-toplevel

    version_spec = SpecifierSet(">=%s" % MINIMUM_STRATISD_VERSION) & SpecifierSet(
        "<%s" % MAXIMUM_STRATISD_VERSION
    )
    version = Manager0.Properties.Version.Get(get_object(TOP_OBJECT))

    if Version(version) not in version_spec:
        raise StratisCliStratisdVersionError(

# Path: src/stratis_cli/_errors.py
# class StratisCliStratisdVersionError(StratisCliRuntimeError):
#     """
#     Raised if stratisd version does not meet CLI version requirements.
#     """
# 
#     def __init__(self, actual_version, minimum_version, maximum_version):
#         """
#         Initializer.
#         :param tuple actual_version: stratisd's actual version
#         :param tuple minimum_version: the minimum version required
#         :param tuple maximum_version: the maximum version allowed
#         """
#         # pylint: disable=super-init-not-called
#         self.actual_version = actual_version
#         self.minimum_version = minimum_version
#         self.maximum_version = maximum_version
# 
#     def __str__(self):
#         fmt_str = (
#             "stratisd version %s does not meet stratis version "
#             "requirements; the version must be at least %s and no more "
#             "than %s"
#         )
#         return fmt_str % (
#             self.actual_version,
#             self.minimum_version,
#             self.maximum_version,
#         )
# 
# Path: src/stratis_cli/_actions/_connection.py
# def get_object(object_path):
#     """
#     Get an object from an object path.
# 
#     :param str object_path: an object path with a valid format
#     :returns: the proxy object corresponding to the object path
#     :rtype: ProxyObject
#     """
#     return Bus.get_bus().get_object(SERVICE, object_path, introspect=False)
# 
# Path: src/stratis_cli/_actions/_constants.py
# MAXIMUM_STRATISD_VERSION = "4.0.0"
# 
# MINIMUM_STRATISD_VERSION = "3.1.0"
# 
# TOP_OBJECT = "/org/storage/stratis3"


# Path: src/stratis_cli/_actions/_stratisd_version.py
from packaging.specifiers import SpecifierSet, Version
from .._errors import StratisCliStratisdVersionError
from ._connection import get_object
from ._constants import MAXIMUM_STRATISD_VERSION, MINIMUM_STRATISD_VERSION, TOP_OBJECT
    from ._data import Manager0

#
# 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.
"""
Check version of stratisd
"""

# isort: THIRDPARTY



def check_stratisd_version():
    """
    Checks that the version of stratisd that is running is compatible with
    this version of the CLI.

    :raises StratisCliStratisdVersionError
    """
    # pylint: disable=import-outside-toplevel

    version_spec = SpecifierSet(">=%s" % MINIMUM_STRATISD_VERSION) & SpecifierSet(
        "<%s" % MAXIMUM_STRATISD_VERSION
    )
    version = Manager0.Properties.Version.Get(get_object(TOP_OBJECT))

    if Version(version) not in version_spec:
        raise StratisCliStratisdVersionError(

            version, MINIMUM_STRATISD_VERSION, MAXIMUM_STRATISD_VERSION