change back to previous working dir

This commit is contained in:
ducoterra
2019-09-11 21:43:40 -04:00
parent a63ecd9d74
commit 2521be5a76
2 changed files with 19 additions and 2 deletions

12
flash.py Executable file → Normal file
View File

@@ -8,11 +8,13 @@ import time
import fourletterphat as flp import fourletterphat as flp
import os import os
import tempfile import tempfile
from shutil import copyfile
#-- #--
q = Queue() q = Queue()
t = loader.bgload(3, .1) t = loader.bgload(3, .1)
IMAGE = "image.img" IMAGE = "image.img"
PWD = os.getcwd()
#-- #--
def disp_string(string): def disp_string(string):
@@ -40,8 +42,10 @@ def get_mounted_devs():
def flash(dev): def flash(dev):
loader.q.put(dev) loader.q.put(dev)
try: try:
flash_cmd = ["/bin/dd", f"if=./{IMAGE}", f"of={dev}"] flash_cmd = ["/bin/dd", f"if={IMAGE}", f"of={dev}"]
output = subprocess.check_output(flash_cmd).decode("utf-8")
subprocess.run(flash_cmd)
with tempfile.TemporaryDirectory() as tempdir: with tempfile.TemporaryDirectory() as tempdir:
mount_cmd = ["mount",f"{dev}2", tempdir] mount_cmd = ["mount",f"{dev}2", tempdir]
umount_cmd = ["umount", tempdir] umount_cmd = ["umount", tempdir]
@@ -49,12 +53,16 @@ def flash(dev):
subprocess.run(mount_cmd) subprocess.run(mount_cmd)
os.chdir(tempdir) os.chdir(tempdir)
os.mkdir("ssh") os.mkdir("ssh")
os.chdir(PWD)
copyfile("wpa_supplicant.conf", tempdir)
subprocess.run(umount_cmd) subprocess.run(umount_cmd)
return True return True
except BaseException as err: except BaseException as err:
print(err) print(err)
disp_string('ERR') disp_string('ERR')
finally: finally:
loader.q.get() loader.q.get()

9
wpa_supplicant.conf Normal file
View File

@@ -0,0 +1,9 @@
country=us
update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={
scan_ssid=1
ssid="ssid"
psk="password"
}