From 7c6a41860203fcbaa8b0028ee8b059ee2f63ee81 Mon Sep 17 00:00:00 2001 From: Nikos Skalkotos Date: Tue, 25 Jun 2013 16:27:53 +0300 Subject: [PATCH] Add check_guestfs_version function This function is used to check if a specified libguestfs version is smaller, greater or equal to the installed one --- image_creator/image.py | 13 +++++-------- image_creator/util.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/image_creator/image.py b/image_creator/image.py index b27c1eb..86992b6 100644 --- a/image_creator/image.py +++ b/image_creator/image.py @@ -33,7 +33,7 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. -from image_creator.util import FatalError +from image_creator.util import FatalError, check_guestfs_version from image_creator.gpt import GPTPartitionTable from image_creator.os_type import os_cls @@ -64,14 +64,11 @@ class Image(object): # file descriptors. This can cause problems especially if the parent # process has opened pipes. Since the recovery process is an optional # feature of libguestfs, it's better to disable it. - self.g.set_recovery_proc(0) - version = self.g.version() - if version['major'] > 1 or \ - (version['major'] == 1 and (version['minor'] >= 18 or - (version['minor'] == 17 and - version['release'] >= 14))): - self.g.set_recovery_proc(1) + if check_guestfs_version(self.g, 1, 17, 14) >= 0: self.out.output("Enabling recovery proc") + self.g.set_recovery_proc(1) + else: + self.g.set_recovery_proc(0) #self.g.set_trace(1) #self.g.set_verbose(1) diff --git a/image_creator/util.py b/image_creator/util.py index fb0d0fa..a60d865 100644 --- a/image_creator/util.py +++ b/image_creator/util.py @@ -115,4 +115,23 @@ class MD5: return checksum + def check_guestfs_version(ghandler, major, minor, release): + """Checks if the version of the used libguestfs is smaller, equal or + greater than the one specified by the major, minor and release triplet + + Returns: + < 0 if the installed version is smaller than the specified one + = 0 if they are equal + > 0 if the installed one is greater than the specified one + """ + + ver = ghandler.version() + + for (a, b) in (ver['major'], major), (ver['minor'], minor), \ + (ver['release'], release): + if a != b: + return a - b + + return 0 + # vim: set sta sts=4 shiftwidth=4 sw=4 et ai : -- 1.7.10.4