commit 00a6c92e6524a8e1eac0a37662764d19e2a8f1c5 Author: Reese Date: Sun Jul 28 11:29:01 2019 -0400 Add new file diff --git a/flash.py b/flash.py new file mode 100644 index 0000000..833df44 --- /dev/null +++ b/flash.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +import subprocess +import time + +#-- +drive_blacklist = {"/boot","/"} +#-- + +def get_mountedlist(): + return [item[item.find("/"):] for item in subprocess.check_output( + ["/bin/bash", "-c", "lsblk"]).decode("utf-8").split("\n") if "/" in item] + +def get_mounted_devs(): + cmd = ["/bin/bash", "-c", "lsblk"] + output = subprocess.check_output(cmd).decode("utf-8").split("\n") + res = set() + for item in output: + if item.startswith("sd"): + # print(f"Found /dev/{item.split(' ')[0]}") + res.add(f"/dev/{item.split(' ')[0]}") + return res + +def flash(dev): + flash_cmd = ["/bin/dd", "if=/home/pi/Downloads/2019-07-10-raspbian-buster-lite.img", f"of={dev}"] + output = subprocess.check_output(flash_cmd).decode("utf-8") + print(output) + return True + +done = set() +while True: + devs = get_mounted_devs() + done = done.intersection(devs) + for dev in devs: + if dev not in done: + print(f"Flashing {dev}") + if flash(dev): + print(f"Flashed {dev}") + done.add(dev) + time.sleep(1) \ No newline at end of file