Commit 64fa21a1 authored by Adam Blank's avatar Adam Blank
Browse files

Update transfer.py

parent 1b586cc6
No related merge requests found
Showing with 17 additions and 26 deletions
+17 -26
import subprocess
import time
import platform
import shutil
import os
import ports
import psutil
import urllib.request
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
import os
import shutil
import platform
import time
from pathlib import Path
import subprocess
ssl._create_default_https_context = ssl._create_unverified_context
def get_drive():
......@@ -52,36 +52,27 @@ if not trinkey:
print("Could not find the Trinkey to connect to...try removing it from the USB drive and plugging it back in.")
exit(1)
# Kill any running program
trinkey.write(bytes(chr(0x03), 'utf-8'))
trinkey.flush()
print("Connected to Trinkey! Transfering files...")
shutil.rmtree(os.path.join('src', '__pycache__'), True)
shutil.rmtree(os.path.join('support', '__pycache__'), True)
shutil.rmtree(os.path.join(disk, '__pycache__'), True)
for x in os.listdir(disk):
try:
os.unlink(os.path.join(disk, x))
except (PermissionError, FileNotFoundError, OSError):
pass
shutil.rmtree(disk, True)
shutil.rmtree(os.path.join(disk, 'lib'), True)
shutil.rmtree(os.path.join(disk, 'src'), True)
shutil.copytree('src', os.path.join(disk, 'src'), dirs_exist_ok=True)
shutil.rmtree(os.path.join(disk, 'support'), True)
shutil.copytree('support', os.path.join(disk, 'support'), dirs_exist_ok=True)
shutil.copy('code.py', os.path.join(disk, 'code.py'))
# Kill any running program
trinkey.write(bytes(chr(0x03), 'utf-8'))
trinkey.flush()
Path(os.path.join(disk, 'code.py')).write_bytes(Path("code.py").read_bytes())
print("Files transfered...connecting to Trinkey...")
time.sleep(1)
trinkey.flush()
time.sleep(5)
print("Restarting Trinkey!")
# Kill any running program
trinkey.write(bytes(chr(0x04), 'utf-8'))
trinkey.flush()
time.sleep(1)
miniterm = ports.connect_to_serial(trinkey)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment