1 Commits

Author SHA1 Message Date
10206dd51e Update zsh completions 2019-03-13 21:35:19 -07:00
2 changed files with 9 additions and 14 deletions

View File

@ -2,7 +2,6 @@
"""Wrapper script for using dd to write to a USB drive."""
import argparse
import os
import pathlib
import re
import subprocess
@ -11,10 +10,6 @@ import subprocess
COMMENT_PATTERN = "^[#;]"
EXCLUDE_FILE = "/etc/helper-scripts/ddusb-exclude.conf"
E_BLOCKDEVICE_ERROR = 1
E_EXCLUDE_ERROR = 2
E_DD_ERROR = 3
# ========== Functions ==========
def read_exclude_file(exclude_file):
@ -51,7 +46,7 @@ block_path = args.output_file
# Ensure that block_path is really a block device
if not pathlib.Path(block_path).is_block_device():
print(f'Error: "{block_path}" is not a block device')
exit(E_BLOCKDEVICE_ERROR)
exit(1)
# Check if block_path is excluded
exclude_patterns = read_exclude_file(EXCLUDE_FILE)
@ -59,7 +54,7 @@ exclude_patterns = read_exclude_file(EXCLUDE_FILE)
for pattern in exclude_patterns:
if re.fullmatch(pattern, block_path):
print(f'Error: "{block_path}" is blacklisted from running dd')
exit(E_EXCLUDE_ERROR)
exit(2)
print(f"Input file: {input_file}")
print(f"Block device: {block_path}")
@ -77,6 +72,6 @@ try:
check=True,
)
except subprocess.CalledProcessError:
exit(E_DD_ERROR)
exit(3)
else:
os.sync()
subprocess.run("sync")