Skip to content

Commit

Permalink
Use cleaner path finding code, misc. cleanup
Browse files Browse the repository at this point in the history
Instead of a bunch of nested if-elses, use a list of strings to try
iterating over to fins python(.exe).

Replace 1-line if-else with ternary operator
  • Loading branch information
earlephilhower authored and igrr committed Feb 23, 2019
1 parent c231545 commit 33969c9
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/ESP8266FS.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,7 @@ private void createAndUpload(){
File espota = new File(platform.getFolder()+"/tools");
File esptool = new File(platform.getFolder()+"/tools");
String serialPort = PreferencesData.get("serial.port");
String pythonCmd;
if(PreferencesData.get("runtime.os").contentEquals("windows"))
pythonCmd = "python.exe";
else
pythonCmd = "python";
String pythonCmd = PreferencesData.get("runtime.os").contentEquals("windows") ? "python.exe" : "python";
String uploadCmd = "";

//make sure the serial port or IP is defined
Expand All @@ -228,21 +224,12 @@ private void createAndUpload(){
uploadCmd = uploadPyFile.getAbsolutePath();
}
// Find python.exe if present, don't fail if not found for backwards compat
String toolPyCmd = pythonCmd;
if ((toolPyCmd != null ) && !toolPyCmd.isEmpty()) {
File toolPyFile = new File(platform.getFolder()+"/tools", toolPyCmd);
String[] paths = { platform.getFolder()+"/tools", platform.getFolder()+"/tools/python", PreferencesData.get("runtime.tools.python.path") };
for (String s: paths) {
File toolPyFile = new File(s, pythonCmd);
if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) {
pythonCmd = toolPyFile.getAbsolutePath();
} else {
toolPyFile = new File(platform.getFolder()+"/tools/python", toolPyCmd);
if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) {
pythonCmd = toolPyFile.getAbsolutePath();
} else {
toolPyFile = new File(PreferencesData.get("runtime.tools.python.path"), toolPyCmd);
if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) {
pythonCmd = toolPyFile.getAbsolutePath();
}
}
break;
}
}
// pythonCmd now points to either an installed exe with full path or just plain "python(.exe)"
Expand Down Expand Up @@ -338,12 +325,12 @@ private void createAndUpload(){
System.out.println("[SPIFFS] reset : "+resetMethod);
System.out.println("[SPIFFS] port : "+serialPort);
System.out.println("[SPIFFS] speed : "+uploadSpeed);
if (uploadCmd != null && !uploadCmd.isEmpty()) {
if (!uploadCmd.isEmpty()) {
System.out.println("[SPIFFS] python : "+pythonCmd);
System.out.println("[SPIFFS] uploader : "+uploadCmd);
}
System.out.println();
if (uploadCmd != null && !uploadCmd.isEmpty()) {
if (!uploadCmd.isEmpty()) {
sysExec(new String[]{pythonCmd, uploadCmd, "--chip", "esp8266", "--port", serialPort, "--baud", uploadSpeed, "write_flash", uploadAddress, imagePath, "--end"});
} else {
sysExec(new String[]{esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath});
Expand Down

0 comments on commit 33969c9

Please sign in to comment.