Skip to content

Commit

Permalink
Modify factory setup script so that it can just deploy the code files…
Browse files Browse the repository at this point in the history
… to a local folder to make releases easier
  • Loading branch information
theacodes committed Sep 28, 2020
1 parent 6116485 commit a589b0c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions experimental/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
calibrations/
bootloader.bin
firmware.uf2
distribution/
12 changes: 10 additions & 2 deletions experimental/calibrate.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import visa
import serial
import serial.tools.list_ports
import time
import math
import statistics
import win32api
import os.path
import shutil
import io
import subprocess

import utils

try:
import visa
except ImportError:
visa = None

try:
import win32api
except ImportError:
win32api = None


METER_RESOURCE_NAME = "USB0::0x05E6::0x6500::04450405::INSTR"
SOL_USB_DEVICE_ID = "239A:8062"
Expand Down
26 changes: 17 additions & 9 deletions experimental/factory_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import subprocess
import utils
import shutil
import sys
import zipfile

import requests

import calibrate

JLINK_PATH = "C:\Program Files (x86)\SEGGER\JLink\JLink.exe"
assert os.path.exists("bootloader.bin")
assert os.path.exists("firmware.uf2")

ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
FIRMWARE_DIR = os.path.join(ROOT_DIR, "firmware")
Expand Down Expand Up @@ -47,16 +46,18 @@ def program_circuitpython():
utils.copyfile("firmware.uf2", os.path.join(bootloader_drive, "NEW.uf2"))


def deploy_circuitpython_code():
def deploy_circuitpython_code(destination=None):
print("========== DEPLOYING CODE ==========")
# Wait for the circuitpython drive to show up.
time.sleep(5)
cpy_drive = utils.find_drive_by_name("CIRCUITPY")

if not destination:
destination = utils.find_drive_by_name("CIRCUITPY")

utils.clean_pycache(FIRMWARE_DIR)
utils.clean_pycache(EXAMPLES_DIR)

os.makedirs(os.path.join(cpy_drive, "lib"), exist_ok=True)
os.makedirs(os.path.join(destination, "lib"), exist_ok=True)

for src, dst in FILES_TO_DEPLOY.items():
if src.startswith("https://"):
Expand All @@ -68,21 +69,21 @@ def deploy_circuitpython_code():
file_data = zipfh.read(zip_path)

dst = os.path.join(dst, os.path.basename(zip_path))
with open(os.path.join(cpy_drive, dst), "wb") as fh:
with open(os.path.join(destination, dst), "wb") as fh:
fh.write(file_data)

else:
if os.path.isdir(src):
dst = os.path.join(cpy_drive, dst, os.path.basename(src))
dst = os.path.join(destination, dst, os.path.basename(src))
if os.path.exists(dst):
shutil.rmtree(dst)
shutil.copytree(src, dst)
else:
shutil.copy(src, os.path.join(cpy_drive, dst))
shutil.copy(src, os.path.join(destination, dst))

print(f"Copied {src} to {dst}")

utils.flush(cpy_drive)
utils.flush(destination)


def run_calibration():
Expand All @@ -91,6 +92,13 @@ def run_calibration():


def main():
if sys.argv[1] == "publish":
deploy_circuitpython_code("distribution")
return

assert os.path.exists("bootloader.bin")
assert os.path.exists("firmware.uf2")

try:
bootloader_drive = utils.find_drive_by_name("SOLBOOT")
except:
Expand Down
9 changes: 8 additions & 1 deletion experimental/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import os.path
import pathlib
import win32api
import subprocess

try:
import win32api
except ImportError:
win32api = None

def find_drive_by_name(name):
drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')[:-1]
Expand All @@ -14,6 +18,9 @@ def find_drive_by_name(name):


def flush(path):
if win32api is None:
return

drive, _ = os.path.splitdrive(path)
subprocess.run(["sync", drive], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

Expand Down

0 comments on commit a589b0c

Please sign in to comment.