Skip to content

Add upload.py and internal python in tools #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 23, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 51 additions & 18 deletions src/ESP8266FS.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ 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 uploadCmd = "";

//make sure the serial port or IP is defined
if (serialPort == null || serialPort.isEmpty()) {
Expand All @@ -216,6 +222,31 @@ private void createAndUpload(){
return;
}

// Find upload.py, don't fail if not present for backwards compat
File uploadPyFile = new File(platform.getFolder()+"/tools", "upload.py");
if (uploadPyFile.exists() && uploadPyFile.isFile()) {
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);
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();
}
}
}
}
// pythonCmd now points to either an installed exe with full path or just plain "python(.exe)"

//find espota if IP else find esptool
if(serialPort.split("\\.").length == 4){
isNetwork = true;
Expand All @@ -233,7 +264,7 @@ private void createAndUpload(){
esptool = new File(platform.getFolder()+"/tools/esptool", esptoolCmd);
if(!esptool.exists()){
esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd);
if (!esptool.exists()) {
if (!esptool.exists() && uploadCmd.isEmpty()) {
System.err.println();
editor.statusError("SPIFFS Error: esptool not found!");
return;
Expand Down Expand Up @@ -278,10 +309,10 @@ private void createAndUpload(){
}

editor.statusNotice("SPIFFS Creating Image...");
System.out.println("[SPIFFS] data : "+dataPath);
System.out.println("[SPIFFS] size : "+((spiEnd - spiStart)/1024));
System.out.println("[SPIFFS] page : "+spiPage);
System.out.println("[SPIFFS] block : "+spiBlock);
System.out.println("[SPIFFS] data : "+dataPath);
System.out.println("[SPIFFS] size : "+((spiEnd - spiStart)/1024));
System.out.println("[SPIFFS] page : "+spiPage);
System.out.println("[SPIFFS] block : "+spiBlock);

try {
if(listenOnProcess(new String[]{toolPath, "-c", dataPath, "-p", spiPage+"", "-b", spiBlock+"", "-s", (spiEnd - spiStart)+"", imagePath}) != 0){
Expand All @@ -296,25 +327,27 @@ private void createAndUpload(){
}

editor.statusNotice("SPIFFS Uploading Image...");
System.out.println("[SPIFFS] upload : "+imagePath);
System.out.println("[SPIFFS] upload : "+imagePath);

if(isNetwork){
String pythonCmd;
if(PreferencesData.get("runtime.os").contentEquals("windows"))
pythonCmd = "python.exe";
else
pythonCmd = "python";

System.out.println("[SPIFFS] IP : "+serialPort);
System.out.println("[SPIFFS] IP : "+serialPort);
System.out.println();
sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-s", "-f", imagePath});
} else {
System.out.println("[SPIFFS] address: "+uploadAddress);
System.out.println("[SPIFFS] reset : "+resetMethod);
System.out.println("[SPIFFS] port : "+serialPort);
System.out.println("[SPIFFS] speed : "+uploadSpeed);
System.out.println("[SPIFFS] address : "+uploadAddress);
System.out.println("[SPIFFS] reset : "+resetMethod);
System.out.println("[SPIFFS] port : "+serialPort);
System.out.println("[SPIFFS] speed : "+uploadSpeed);
if (uploadCmd != null && !uploadCmd.isEmpty()) {
System.out.println("[SPIFFS] python : "+pythonCmd);
System.out.println("[SPIFFS] uploader : "+uploadCmd);
}
System.out.println();
sysExec(new String[]{esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath});
if (uploadCmd != null && !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