losetup: create and attach images to loopback devices in one operation

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-06-26 12:45:35 +02:00
parent 4b3c1e922c
commit b540eb5ee7
2 changed files with 2 additions and 4 deletions

View file

@ -35,9 +35,8 @@ def mount_api(dest):
@contextlib.contextmanager
def loop_device(image):
r = subprocess.run(["losetup", "-f"], stdout=subprocess.PIPE, encoding="utf-8", check=True)
r = subprocess.run(["losetup", "--partscan", "--show", "--find", image], stdout=subprocess.PIPE, encoding="utf-8", check=True)
loop = r.stdout.strip()
r = subprocess.run(["losetup", loop, "-P", image], check=True)
try:
yield loop
finally:

View file

@ -35,9 +35,8 @@ def mount_api(dest):
@contextlib.contextmanager
def loop_device(image):
r = subprocess.run(["losetup", "-f"], stdout=subprocess.PIPE, encoding="utf-8", check=True)
r = subprocess.run(["losetup", "--partscan", "--show", "--find", image], stdout=subprocess.PIPE, encoding="utf-8", check=True)
loop = r.stdout.strip()
r = subprocess.run(["losetup", loop, "-P", image], check=True)
try:
yield loop
finally: