From cd20ec6efb792f32bbdc7aea551fe002c1e85021 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Wed, 28 Mar 2012 18:33:07 +0100 Subject: fsutils.setup_device_mapping: use a regex sfdisk may omit a space between the partition name and the : if the partition name is long, so splitting into tokens doesn't always work. This regex should work better --- morphlib/fsutils.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'morphlib/fsutils.py') diff --git a/morphlib/fsutils.py b/morphlib/fsutils.py index dbe8b261..6a1ec2e2 100644 --- a/morphlib/fsutils.py +++ b/morphlib/fsutils.py @@ -14,6 +14,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os +import re def create_image(ex, image_name, size): @@ -34,14 +35,15 @@ def install_mbr(ex, image_name): break def setup_device_mapping(ex, image_name): + findstart = re.compile(r"start=\s+(\d+),") out = ex.runv(['sfdisk', '-d', image_name]) + print(out) for line in out.splitlines(): - words = line.split() - if (len(words) >= 4 and - words[2] == 'start=' and - words[3] != '0,'): - n = int(words[3][:-1]) # skip trailing comma - start = n * 512 + match = findstart.search(line) + if match is None: + continue + start = int(match.group(1)) * 512 + if start != 0: break ex.runv(['losetup', '-o', str(start), '-f', image_name]) -- cgit v1.2.1