add loading icon
This commit is contained in:
40
flash.py
40
flash.py
@@ -1,20 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import threading
|
||||
import loader
|
||||
from queue import Queue
|
||||
import subprocess
|
||||
import time
|
||||
import fourletterphat as flp
|
||||
|
||||
#--
|
||||
drive_blacklist = {"/boot","/"}
|
||||
q = Queue()
|
||||
t = loader.bgload(3, .1)
|
||||
#--
|
||||
|
||||
def disp_string(string):
|
||||
for letter in range(0,4):
|
||||
for letter in range(0,3) if len(string) > 3 else range(0, len(string)):
|
||||
try:
|
||||
flp.set_digit(letter, string[letter].upper())
|
||||
except IndexError:
|
||||
pass
|
||||
flp.show()
|
||||
flp.show()
|
||||
|
||||
def get_mountedlist():
|
||||
return [item[item.find("/"):] for item in subprocess.check_output(
|
||||
@@ -31,16 +35,24 @@ def get_mounted_devs():
|
||||
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
|
||||
|
||||
disp_string("GO")
|
||||
|
||||
done = set()
|
||||
while True:
|
||||
loader.q.put(dev)
|
||||
try:
|
||||
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
|
||||
except BaseException as err:
|
||||
print(err)
|
||||
disp_string('ERR')
|
||||
finally:
|
||||
loader.q.get()
|
||||
|
||||
if __name__=="__main__":
|
||||
|
||||
disp_string("GO")
|
||||
|
||||
done = set()
|
||||
while True:
|
||||
devs = get_mounted_devs()
|
||||
done = done.intersection(devs)
|
||||
for dev in devs:
|
||||
@@ -49,9 +61,7 @@ while True:
|
||||
disp_string(dev.split("/")[2])
|
||||
if flash(dev):
|
||||
print(f"Flashed {dev}")
|
||||
disp_string("DONE")
|
||||
disp_string("GO")
|
||||
time.sleep(.5)
|
||||
done.add(dev)
|
||||
time.sleep(1)
|
||||
except BaseException as err:
|
||||
disp_string("err")
|
||||
Reference in New Issue
Block a user