Make winexe an optional dependency
authorNikos Skalkotos <skalkoto@grnet.gr>
Mon, 6 Jan 2014 17:35:32 +0000 (19:35 +0200)
committerNikos Skalkotos <skalkoto@grnet.gr>
Mon, 6 Jan 2014 17:35:32 +0000 (19:35 +0200)
Check the presence of the winexe executable at runtime only if the
input media is a Windows system

image_creator/os_type/windows.py
image_creator/winexe.py

index 7c4c127..b758e03 100644 (file)
@@ -139,6 +139,11 @@ class Windows(OSBase):
             raise FatalError(
                 'For windows support libguestfs 1.16.11 or above is required')
 
+        # Check if winexe is installed
+        if not WinEXE.is_installed():
+            raise FatalError(
+                "For windows support `Winexe' needs to be installed")
+
         device = self.image.g.part_to_dev(self.root)
 
         self.last_part_num = self.image.g.part_list(device)[-1]['part_num']
index ebac409..b6c00bc 100644 (file)
@@ -38,6 +38,7 @@
 import subprocess
 import time
 import signal
+import distutils
 
 from image_creator.util import FatalError
 
@@ -50,6 +51,10 @@ class WinexeTimeout(FatalError):
 class WinEXE:
     """Wrapper class for the winexe command"""
 
+    @staticmethod
+    def is_installed(program='winexe'):
+        return distutils.spawn.find_executable(program) is not None
+
     def __init__(self, username, password, hostname, program='winexe'):
         self._host = hostname
         self._user = username