From 2d857a5cac0b358725c6be2cad250ba76fe7c7eb Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Tue, 23 Oct 2018 15:33:04 -0700 Subject: [PATCH] Added process check for dd --- ddusb.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ddusb.py b/ddusb.py index 0618884..47123d7 100755 --- a/ddusb.py +++ b/ddusb.py @@ -1,13 +1,13 @@ #!/usr/bin/env python -""" ddusb - write an ISO image to a usb drive -Dependencies: - - dd (coreutils) -""" +"""Write an ISO image to a usb drive using dd.""" import argparse +import configparser import pathlib import subprocess +# TODO add a config file for blacklisting certain devices e.g. /dev/sda + parser = argparse.ArgumentParser() parser.add_argument("-b", "--bs", default=512, help="block size", metavar="bs") parser.add_argument("input_file", help="input file to write") @@ -26,8 +26,12 @@ print(f"Input file: {input_file}") print(f"Block device: {block_device}") print(f"Block size: {block_size}") -subprocess.run(["dd", f"if={input_file}", - f"of={block_device}", f"bs={block_size}", "status=progress"]) - -# ensure process is finished before exiting -subprocess.run(['sync']) +try: + subprocess.run(["dd", f"if={input_file}", + f"of={block_device}", + f"bs={block_size}", + "status=progress"], check=True) +except subprocess.CalledProcessError: + exit(1) +else: + subprocess.run(['sync'])