Skip to content

Instantly share code, notes, and snippets.

@evenprimes
Created October 31, 2022 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evenprimes/ce82740fea3bcfe1ac82a3f9a6f4c2da to your computer and use it in GitHub Desktop.
Save evenprimes/ce82740fea3bcfe1ac82a3f9a6f4c2da to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Copy a CircuitPython project onto a device
.DESCRIPTION
A longer description of the function, its purpose, common use cases, etc.
.NOTES
Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
Test-MyTestFunction -Verbose
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>
# Find the sentinal file for this project.
$SentinalList = Get-ChildItem .\*.zzz
if ($SentinalList.Count -eq 0) {
Write-Error "No Sentinal files found."
Exit 1
}
else {
$Sentinal = $SentinalList[0]
}
Write-Host Sentinal file: $Sentinal.Name -ForegroundColor Yellow
# Write-Host $Sentinal.Length
# Find the drive with where the CircuitPython device is mounted.
Get-PSDrive -PSProvider FileSystem | ForEach-Object {
if (Test-Path -Path $(Join-Path -Path $_.Root -ChildPath $Sentinal.Name)) {
Write-Host Found $Sentinal.Name on $_.Root -ForegroundColor Yellow
$cpdrive = $_.Root
}
}
if ($cpdrive -eq '') {
Write-Error 'CircuitPython device not found, is it connected?'
Exit 1
}
if ($Sentinal.Length -eq 0) {
# Sentinal file is empty, just copy over code.py
Write-Host Copying 'code.py' to $cpdrive -ForegroundColor Green
Copy-Item -Path .\code.py -Destination $cpdrive -Force
}
else {
# Sentinal file isn't empty, copy each line over
Get-Content $Sentinal | ForEach-Object {
Write-Host Copy $_ -ForegroundColor Green
$parts = Split-Path -Path $_ -Parent
if ($parts.Length -eq 0) {
# Simple copy to the root
Copy-Item -path $_ -Destination $cpdrive
}else {
# Make sure that the path exists on the CP
$dest = Join-Path -Path $cpdrive -ChildPath $parts
$outVar = New-Item -Force -ItemType Directory -Path $dest
Copy-Item -Path $_ -Destination $dest
}
}
}
Write-Host 'Done!' -ForegroundColor Yellow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment