Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Deploy to Clue and Deploy Command Pallete Refactoring (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
vandyliu authored Mar 30, 2020
1 parent ff89634 commit 9c9bc37
Show file tree
Hide file tree
Showing 9 changed files with 465 additions and 342 deletions.
4 changes: 3 additions & 1 deletion locales/en/out/constants.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"error.debuggerServerInitFailed": "Warning : The Debugger Server cannot be opened. Please try to free the port {0} if it's already in use or select another one in your Settings 'Device Simulator Express: Debugger Server Port' and start another debug session.\n You can still debug your code but you won't be able to use the Simulator.",
"error.debuggingSessionInProgress": "[ERROR] A debugging session is currently in progress, please stop it before running your code. \n",
"error.noDevice": "No plugged in boards detected. Please double check if your board is connected and/or properly formatted",
"error.noFileToRun": "\n[ERROR] We can't find the .py file to run on simulator. Open up a new .py file, or browse through some examples\n",
"error.noFileToRun": "\n[ERROR] We can't find the .py file to run. Open up a new .py file, or browse through some examples\n",
"error.noFileToDeploy": "\n[ERROR] We can't find a Python file to deploy to your device.\n",
"error.noFolderCreated": "In order to use the Serial Monitor, you need to open a folder and reload VS Code.",
"error.noProgramFoundDebug": "Cannot find a program to debug.",
"error.noPythonPath": "We found that you don't have Python 3 installed on your computer, please install the latest version, add it to your PATH and try again.",
Expand All @@ -28,6 +29,7 @@
"info.installPythonDependencies": "Do you want us to try and install this extensions dependencies for you?",
"error.invalidFileExtensionDebug": "The file you tried to run isn\\'t a Python file.",
"info.newFile": "New to Python or the Circuit Playground Express? We are here to help!",
"info.noDeviceChosenToDeployTo": "\n[INFO] No device was selected to deploy to.\n",
"info.redirect": "You are being redirected.",
"info.runningCode": "Running user code",
"info.privacyStatement": "Privacy Statement",
Expand Down
3 changes: 1 addition & 2 deletions locales/en/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"deviceSimulatorExpressExtension.commands.common.closeSerialMonitor": "Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port",
"deviceSimulatorExpressExtension.commands.common.deployToDevice": "Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
"deviceSimulatorExpressExtension.commands.microbit.deployToDevice": "[micro:bit] Deploy to Device",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
"deviceSimulatorExpressExtension.commands.clue.openSimulator": "[Clue] Open Simulator",
Expand Down
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@
"onCommand:deviceSimulatorExpress.common.runSimulator",
"onCommand:deviceSimulatorExpress.common.selectSerialPort",
"onCommand:deviceSimulatorExpress.common.gettingStarted",
"onCommand:deviceSimulatorExpress.cpx.deployToDevice",
"onCommand:deviceSimulatorExpress.common.deployToDevice",
"onCommand:deviceSimulatorExpress.cpx.newFile",
"onCommand:deviceSimulatorExpress.cpx.openSimulator",
"onCommand:deviceSimulatorExpress.microbit.deployToDevice",
"onCommand:deviceSimulatorExpress.microbit.newFile",
"onCommand:deviceSimulatorExpress.microbit.openSimulator",
"onCommand:deviceSimulatorExpress.clue.newFile",
Expand Down Expand Up @@ -84,8 +83,8 @@
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.cpx.deployToDevice",
"title": "%deviceSimulatorExpressExtension.commands.cpx.deployToDevice%",
"command": "deviceSimulatorExpress.common.deployToDevice",
"title": "%deviceSimulatorExpressExtension.commands.common.deployToDevice%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
Expand All @@ -98,11 +97,6 @@
"title": "%deviceSimulatorExpressExtension.commands.cpx.openSimulator%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.microbit.deployToDevice",
"title": "%deviceSimulatorExpressExtension.commands.microbit.deployToDevice%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.microbit.openSimulator",
"title": "%deviceSimulatorExpressExtension.commands.microbit.openSimulator%",
Expand Down
3 changes: 1 addition & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"deviceSimulatorExpressExtension.commands.common.closeSerialMonitor": "Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port",
"deviceSimulatorExpressExtension.commands.common.deployToDevice": "Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
"deviceSimulatorExpressExtension.commands.microbit.deployToDevice": "[micro:bit] Deploy to Device",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
"deviceSimulatorExpressExtension.commands.clue.openSimulator": "[Clue] Open Simulator",
Expand Down
28 changes: 26 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const CONSTANTS = {
MICROBIT: "micro:bit",
CLUE: "CLUE",
},
DEVICE_NAME_FORMAL: {
CPX: "Circuit Playground Express",
MICROBIT: "micro:bit",
CLUE: "CLUE",
},
ERROR: {
BAD_PYTHON_PATH:
'Your interpreter is not pointing to a valid Python executable. Please select a different interpreter (CTRL+SHIFT+P and type "python.selectInterpreter") and restart the application',
Expand Down Expand Up @@ -88,12 +93,16 @@ export const CONSTANTS = {
),
NO_DEVICE: localize(
"error.noDevice",
"No plugged in boards detected. Please double check if your board is connected and/or properly formatted"
"The device is not detected. Please double check if your board is connected and/or properly formatted"
),
NO_FILE_TO_RUN: localize(
"error.noFileToRun",
'[ERROR] We can\'t find a Python file to run. Please make sure you select or open a new ".py" code file, or use the "New File" command to get started and see useful links.\n'
),
NO_FILE_TO_DEPLOY: localize(
"error.noFileToDeploy",
"[ERROR] We can't find a Python file to deploy to your device.\n"
),
NO_FOLDER_OPENED: localize(
"error.noFolderCreated",
"In order to use the Serial Monitor, you need to open a folder and reload VS Code."
Expand Down Expand Up @@ -189,6 +198,10 @@ export const CONSTANTS = {
"info.newFile",
"New to Python or the Circuit Playground Express? We are here to help!"
),
NO_DEVICE_CHOSEN_TO_DEPLOY_TO: localize(
"info.noDeviceChosenToDeployTo",
"\n[INFO] No device was selected to deploy to.\n"
),
OPENED_SERIAL_PORT: (port: string) => {
return localize(
"info.openedSerialPort",
Expand Down Expand Up @@ -243,8 +256,9 @@ export const CONSTANTS = {
DOWNLOAD_PYTHON: "https://www.python.org/downloads/",
EXAMPLE_CODE:
"https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples",
HELP:
CPX_HELP:
"https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-quickstart",
CLUE_HELP: "https://learn.adafruit.com/adafruit-clue/circuitpython",
INSTALL:
"https://github.com/microsoft/vscode-python-devicesimulator/blob/dev/docs/install.md",
PRIVACY: "https://www.adafruit.com/privacy",
Expand Down Expand Up @@ -335,6 +349,8 @@ export enum TelemetryEventName {
MICROBIT_COMMAND_NEW_FILE = "MICROBIT.COMMAND.NEW.FILE",
MICROBIT_COMMAND_OPEN_SIMULATOR = "MICROBIT.COMMAND.OPEN.SIMULATOR",

CLUE_COMMAND_DEPLOY_DEVICE = "CLUE.COMMAND.DEPLOY.DEVICE",

// Simulator interaction
CPX_SIMULATOR_BUTTON_A = "CPX.SIMULATOR.BUTTON.A",
CPX_SIMULATOR_BUTTON_B = "CPX.SIMULATOR.BUTTON.B",
Expand Down Expand Up @@ -362,6 +378,8 @@ export enum TelemetryEventName {
CPX_CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE = "CPX.CLICK.DIALOG.HELP.DEPLOY.TO.DEVICE",
CPX_CLICK_DIALOG_TUTORIALS = "CPX.CLICK.DIALOG.TUTORIALS",

CLUE_CLICK_DIALOG_HELP_DEPLOY_TO_DEVICE = "CLUE.CLICK.DIALOG.HELP.DEPLOY.TO.DEVICE",

ERROR_PYTHON_PROCESS = "ERROR.PYTHON.PROCESS",
CPX_ERROR_COMMAND_NEW_FILE = "CPX.ERROR.COMMAND.NEW.FILE",
CPX_ERROR_DEPLOY_WITHOUT_DEVICE = "CPX.ERROR.DEPLOY.WITHOUT.DEVICE",
Expand All @@ -373,6 +391,10 @@ export enum TelemetryEventName {
MICROBIT_ERROR_PYTHON_DEVICE_PROCESS = "MICROBIT.ERROR.PYTHON.DEVICE.PROCESS",
MICROBIT_SUCCESS_COMMAND_DEPLOY_DEVICE = "MICROBIT.SUCCESS.COMMAND.DEPLOY.DEVICE",

CLUE_ERROR_DEPLOY_WITHOUT_DEVICE = "CLUE.ERROR.DEPLOY.WITHOUT.DEVICE",
CLUE_ERROR_PYTHON_DEVICE_PROCESS = "CLUE.ERROR.PYTHON.DEVICE.PROCESS",
CLUE_SUCCESS_COMMAND_DEPLOY_DEVICE = "CLUE.SUCCESS.COMMAND.DEPLOY.DEVICE",

// Performance
CPX_PERFORMANCE_DEPLOY_DEVICE = "CPX.PERFORMANCE.DEPLOY.DEVICE",
CPX_PERFORMANCE_NEW_FILE = "CPX.PERFORMANCE.NEW.FILE",
Expand All @@ -382,6 +404,8 @@ export enum TelemetryEventName {
MICROBIT_PERFORMANCE_NEW_FILE = "MICROBIT.PERFORMANCE.NEW.FILE",
MICROBIT_PERFORMANCE_OPEN_SIMULATOR = "MICROBIT.PERFORMANCE.OPEN.SIMULATOR",

CLUE_PERFORMANCE_DEPLOY_DEVICE = "CLUE.PERFORMANCE.DEPLOY.DEVICE",

// Venv options
SETUP_VENV_CREATION_ERR = "SETUP.VENV.CREATION.ERR",
SETUP_NO_PIP = "SETUP.NO.PIP",
Expand Down
20 changes: 10 additions & 10 deletions src/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def __init__(self, name, file_path):
self.connected = False
self.error_message = None

def find_cpx_directory(self):
def find_adafruit_device_directory(self):
"""
Check if the Circuit Playground Express is available/plugged in
Check if the Adafruit Device is available/plugged in
"""
found_directory = None

Expand All @@ -39,7 +39,7 @@ def find_cpx_directory(self):
)
for mount in mounted:
drive_path = mount.split()[2] if mount else ""
if drive_path.endswith(CONSTANTS.CPX_DRIVE_NAME):
if drive_path.endswith(CONSTANTS.ADAFRUIT_DRIVE_NAME):
found_directory = drive_path
break
elif sys.platform == CONSTANTS.WINDOWS_OS:
Expand All @@ -48,7 +48,7 @@ def find_cpx_directory(self):
drive_path = "{}:{}".format(drive_letter, os.sep)
if os.path.exists(drive_path):
drive_name = win32api.GetVolumeInformation(drive_path)[0]
if drive_name == CONSTANTS.CPX_DRIVE_NAME:
if drive_name == CONSTANTS.ADAFRUIT_DRIVE_NAME:
found_directory = drive_path
break
else:
Expand All @@ -57,16 +57,16 @@ def find_cpx_directory(self):
if not found_directory:
self.connected = False
self.error_message = (
CONSTANTS.NO_CPX_DETECTED_ERROR_TITLE,
CONSTANTS.NO_CPX_DETECTED_ERROR_DETAIL.format(sys.platform),
CONSTANTS.NO_ADAFRUIT_DEVICE_DETECTED_ERROR_TITLE,
CONSTANTS.NO_ADAFRUIT_DEVICE_DETECTED_ERROR_DETAIL.format(sys.platform),
)
else:
self.connected = True
self.error_message = None
return found_directory

def deployToCPX(self):
device_directory = self.find_cpx_directory()
def deployToAdafruitDevice(self):
device_directory = self.find_adafruit_device_directory()
if self.error_message:
print(
"{}:\t{}".format(self.error_message[0], self.error_message[1]),
Expand Down Expand Up @@ -109,8 +109,8 @@ def deployToMicrobit(self):
def deploy(self):
if self.name == CONSTANTS.MICROBIT:
return self.deployToMicrobit()
elif self.name == CONSTANTS.CPX:
return self.deployToCPX()
elif self.name == CONSTANTS.CPX or self.name == CONSTANTS.CLUE:
return self.deployToAdafruitDevice()
else:
return {"type": "no-device"}

Expand Down
Loading

0 comments on commit 9c9bc37

Please sign in to comment.