diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2012-03-28 18:33:07 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2012-03-28 18:33:07 +0100 |
commit | cd20ec6efb792f32bbdc7aea551fe002c1e85021 (patch) | |
tree | a7f6b6a1d6e1f687841c69fb7d5616219f129f97 /morphlib | |
parent | 7a25fba0e33ff2e695bef7f9b4484121dd2dd95f (diff) | |
download | morph-cd20ec6efb792f32bbdc7aea551fe002c1e85021.tar.gz |
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
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/fsutils.py | 14 |
1 files changed, 8 insertions, 6 deletions
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]) |