This repository has been archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new command to deploy to the device (#27)
PBI: 29761 Task: 29765, 29769 * add new command to deploy to the device * keep destination name the same as source * refactor directory finding method and address comments * update comment reference * Rewrite the device finding code without influence of mu * change string interpolation to a more compatible version * remove use if platform module * Update code to work on Unix devices * Break when we find the first matching device
- Loading branch information
Showing
7 changed files
with
162 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"pacificaExtension.commands.label": "Adafruit", | ||
"pacificaExtension.commands.openSimulator": "Open Simulator", | ||
"pacificaExtension.commands.runSimulator": "Run Simulator" | ||
"pacificaExtension.commands.runSimulator": "Run Simulator", | ||
"pacificaExtension.commands.newProject": "New Project", | ||
"pacificaExtension.commands.runDevice": "Deploy to Device" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from subprocess import check_output | ||
import string | ||
import os | ||
import sys | ||
if sys.platform == "win32": | ||
# pylint: disable=import-error | ||
import win32api | ||
|
||
|
||
class Adafruit: | ||
def __init__(self): | ||
self.connected = False | ||
self.error_message = None | ||
|
||
def find_device_directory(self): | ||
""" | ||
Check if the Circuit Playground Express is available/plugged in | ||
""" | ||
found_directory = None | ||
|
||
if sys.platform.startswith("linux") or sys.platform.startswith("darwin"): | ||
# Mac or Linux | ||
mounted = check_output('mount').decode('utf-8').split('\n') | ||
for mount in mounted: | ||
drive_path = mount.split()[2] if mount else "" | ||
if drive_path.endswith("CIRCUITPY"): | ||
found_directory = drive_path | ||
break | ||
elif sys.platform == "win32": | ||
# Windows | ||
for drive_letter in string.ascii_uppercase: | ||
drive_path = "{}:{}".format(drive_letter, os.sep) | ||
if (os.path.exists(drive_path)): | ||
drive_name = win32api.GetVolumeInformation(drive_path)[0] | ||
if drive_name == "CIRCUITPY": | ||
found_directory = drive_path | ||
break | ||
else: | ||
raise NotImplementedError( | ||
'The OS "{}" not supported.'.format(sys.platform)) | ||
|
||
if not found_directory: | ||
self.connected = False | ||
self.error_message = ("No Circuit Playground Express detected", | ||
"Could not find drive with name 'CIRCUITPYTHON'. Detected OS: {}".format(sys.platform)) | ||
else: | ||
self.connected = True | ||
self.error_message = None | ||
return found_directory | ||
|
||
|
||
if __name__ == "__main__": | ||
import shutil | ||
|
||
cpx = Adafruit() | ||
device_directory = cpx.find_device_directory() | ||
if cpx.error_message: | ||
print("{}:\t{}".format( | ||
cpx.error_message[0], cpx.error_message[1]), file=sys.stderr, flush=True) | ||
if cpx.connected: | ||
dest_path = os.path.join( | ||
device_directory, sys.argv[1].rsplit(os.sep, 1)[-1]) | ||
shutil.copyfile(sys.argv[1], dest_path) | ||
print("Completed", end="", flush=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters