From ea65ce8a97cda17407e4f6a34699736d5e9afb0f Mon Sep 17 00:00:00 2001 From: Nikos Skalkotos <skalkoto@grnet.gr> Date: Wed, 25 Jun 2014 11:44:12 +0300 Subject: [PATCH] Add check_version method in OSBase This method can be used to compare the OS version against one specified by the user. --- image_creator/os_type/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/image_creator/os_type/__init__.py b/image_creator/os_type/__init__.py index 00cbbf0..bd3ae62 100644 --- a/image_creator/os_type/__init__.py +++ b/image_creator/os_type/__init__.py @@ -401,6 +401,23 @@ class OSBase(object): if not silent: self.out.success('done') + def check_version(self, major, minor): + """Checks the OS version against the one specified by the major, minor + tuple. + + Returns: + < 0 if the OS version is smaller than the specified one + = 0 if they are equal + > 0 if it is greater + """ + guestfs = self.image.g + for a, b in ((guestfs.inspect_get_major_version(self.root), major), + (guestfs.inspect_get_minor_version(self.root), minor)): + if a != b: + return a - b + + return 0 + def _is_sysprep(self, obj): """Checks if an object is a sysprep""" return getattr(obj, 'sysprep', False) and callable(obj) -- GitLab