Added process check for dd

This commit is contained in:
Eric Torres 2018-10-23 15:33:04 -07:00
parent f655fed5e9
commit 2d857a5cac

View File

@ -1,13 +1,13 @@
#!/usr/bin/env python #!/usr/bin/env python
""" ddusb - write an ISO image to a usb drive """Write an ISO image to a usb drive using dd."""
Dependencies:
- dd (coreutils)
"""
import argparse import argparse
import configparser
import pathlib import pathlib
import subprocess import subprocess
# TODO add a config file for blacklisting certain devices e.g. /dev/sda
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-b", "--bs", default=512, help="block size", metavar="bs") parser.add_argument("-b", "--bs", default=512, help="block size", metavar="bs")
parser.add_argument("input_file", help="input file to write") 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 device: {block_device}")
print(f"Block size: {block_size}") print(f"Block size: {block_size}")
subprocess.run(["dd", f"if={input_file}", try:
f"of={block_device}", f"bs={block_size}", "status=progress"]) subprocess.run(["dd", f"if={input_file}",
f"of={block_device}",
# ensure process is finished before exiting f"bs={block_size}",
subprocess.run(['sync']) "status=progress"], check=True)
except subprocess.CalledProcessError:
exit(1)
else:
subprocess.run(['sync'])