From 080bf9cd5527faecc3fa4eeb9a9154b1559274b0 Mon Sep 17 00:00:00 2001 From: Nikos Skalkotos <skalkoto@grnet.gr> Date: Wed, 8 Oct 2014 18:19:05 +0300 Subject: [PATCH] windows: Loosen up the 'shrink QUERYMAX' regexp Do not search for specific words in it. The messages may be in a language other than English. Focus on the Numbers. --- image_creator/os_type/windows/__init__.py | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/image_creator/os_type/windows/__init__.py b/image_creator/os_type/windows/__init__.py index f1ab169..2117d8b 100644 --- a/image_creator/os_type/windows/__init__.py +++ b/image_creator/os_type/windows/__init__.py @@ -407,20 +407,20 @@ class Windows(OSBase): stdout, stderr, rc = self.vm.rexec(cmd) querymax = None + expr = re.compile( + r'.+:\s*(\d+)\s*([KMGT]?)B\s*(?:\((\d+)\s*([KMGT]?)B\))?\s*$') for line in stdout.splitlines(): # diskpart will return something like this: # - # The maximum number of reclaimable bytes is: xxxx MB - # - if line.find('reclaimable') >= 0: - answer = line.split(':')[1].strip() - m = re.search(r'(\d+)\s*([KMGT]?)B', answer, re.IGNORECASE) - if m: - querymax = m.group(1) - unit = m.group(2) - else: - raise FatalError("Unexpected output for `shrink querymax' " - "command: %s" % line) + # a) The maximum number of reclaimable bytes is: xxxx MB + # b) The maximum number of reclaimable bytes is: xxxx GB (xxxx MB) + + match = expr.match(line) + if match: + offset = 0 if match.group(3) is None else 2 + querymax = match.group(offset+1) + unit = match.group(offset+2) + break if querymax is None: raise FatalError("Error in shrinking! Couldn't find the max " @@ -472,7 +472,7 @@ class Windows(OSBase): "Shrinking failed. Please make sure the media is defragged.") for line in stdout.splitlines(): - if line.find('shrunk') >= 0: + if line.find("%d" % querymax) >= 0: self.out.output(" %s" % line) self.shrinked = True -- GitLab