Skip to content

Commit c231545

Browse files
earlephilhowerigrr
authored andcommitted
Add upload.py and internal python in tools
When present, use a tools-installed python executable for any python calls. When tools/upload.py is present, use it in place of esptool-ck.exe. When neither of these are present, as in releases 2.5.0 and prior, use the prior behavior, unchanged.
1 parent fb11cba commit c231545

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed

Diff for: src/ESP8266FS.java

+51-18
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ private void createAndUpload(){
208208
File espota = new File(platform.getFolder()+"/tools");
209209
File esptool = new File(platform.getFolder()+"/tools");
210210
String serialPort = PreferencesData.get("serial.port");
211+
String pythonCmd;
212+
if(PreferencesData.get("runtime.os").contentEquals("windows"))
213+
pythonCmd = "python.exe";
214+
else
215+
pythonCmd = "python";
216+
String uploadCmd = "";
211217

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

225+
// Find upload.py, don't fail if not present for backwards compat
226+
File uploadPyFile = new File(platform.getFolder()+"/tools", "upload.py");
227+
if (uploadPyFile.exists() && uploadPyFile.isFile()) {
228+
uploadCmd = uploadPyFile.getAbsolutePath();
229+
}
230+
// Find python.exe if present, don't fail if not found for backwards compat
231+
String toolPyCmd = pythonCmd;
232+
if ((toolPyCmd != null ) && !toolPyCmd.isEmpty()) {
233+
File toolPyFile = new File(platform.getFolder()+"/tools", toolPyCmd);
234+
if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) {
235+
pythonCmd = toolPyFile.getAbsolutePath();
236+
} else {
237+
toolPyFile = new File(platform.getFolder()+"/tools/python", toolPyCmd);
238+
if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) {
239+
pythonCmd = toolPyFile.getAbsolutePath();
240+
} else {
241+
toolPyFile = new File(PreferencesData.get("runtime.tools.python.path"), toolPyCmd);
242+
if (toolPyFile.exists() && toolPyFile.isFile() && toolPyFile.canExecute()) {
243+
pythonCmd = toolPyFile.getAbsolutePath();
244+
}
245+
}
246+
}
247+
}
248+
// pythonCmd now points to either an installed exe with full path or just plain "python(.exe)"
249+
219250
//find espota if IP else find esptool
220251
if(serialPort.split("\\.").length == 4){
221252
isNetwork = true;
@@ -233,7 +264,7 @@ private void createAndUpload(){
233264
esptool = new File(platform.getFolder()+"/tools/esptool", esptoolCmd);
234265
if(!esptool.exists()){
235266
esptool = new File(PreferencesData.get("runtime.tools.esptool.path"), esptoolCmd);
236-
if (!esptool.exists()) {
267+
if (!esptool.exists() && uploadCmd.isEmpty()) {
237268
System.err.println();
238269
editor.statusError("SPIFFS Error: esptool not found!");
239270
return;
@@ -278,10 +309,10 @@ private void createAndUpload(){
278309
}
279310

280311
editor.statusNotice("SPIFFS Creating Image...");
281-
System.out.println("[SPIFFS] data : "+dataPath);
282-
System.out.println("[SPIFFS] size : "+((spiEnd - spiStart)/1024));
283-
System.out.println("[SPIFFS] page : "+spiPage);
284-
System.out.println("[SPIFFS] block : "+spiBlock);
312+
System.out.println("[SPIFFS] data : "+dataPath);
313+
System.out.println("[SPIFFS] size : "+((spiEnd - spiStart)/1024));
314+
System.out.println("[SPIFFS] page : "+spiPage);
315+
System.out.println("[SPIFFS] block : "+spiBlock);
285316

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

298329
editor.statusNotice("SPIFFS Uploading Image...");
299-
System.out.println("[SPIFFS] upload : "+imagePath);
330+
System.out.println("[SPIFFS] upload : "+imagePath);
300331

301332
if(isNetwork){
302-
String pythonCmd;
303-
if(PreferencesData.get("runtime.os").contentEquals("windows"))
304-
pythonCmd = "python.exe";
305-
else
306-
pythonCmd = "python";
307-
308-
System.out.println("[SPIFFS] IP : "+serialPort);
333+
System.out.println("[SPIFFS] IP : "+serialPort);
309334
System.out.println();
310335
sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-s", "-f", imagePath});
311336
} else {
312-
System.out.println("[SPIFFS] address: "+uploadAddress);
313-
System.out.println("[SPIFFS] reset : "+resetMethod);
314-
System.out.println("[SPIFFS] port : "+serialPort);
315-
System.out.println("[SPIFFS] speed : "+uploadSpeed);
337+
System.out.println("[SPIFFS] address : "+uploadAddress);
338+
System.out.println("[SPIFFS] reset : "+resetMethod);
339+
System.out.println("[SPIFFS] port : "+serialPort);
340+
System.out.println("[SPIFFS] speed : "+uploadSpeed);
341+
if (uploadCmd != null && !uploadCmd.isEmpty()) {
342+
System.out.println("[SPIFFS] python : "+pythonCmd);
343+
System.out.println("[SPIFFS] uploader : "+uploadCmd);
344+
}
316345
System.out.println();
317-
sysExec(new String[]{esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath});
346+
if (uploadCmd != null && !uploadCmd.isEmpty()) {
347+
sysExec(new String[]{pythonCmd, uploadCmd, "--chip", "esp8266", "--port", serialPort, "--baud", uploadSpeed, "write_flash", uploadAddress, imagePath, "--end"});
348+
} else {
349+
sysExec(new String[]{esptool.getAbsolutePath(), "-cd", resetMethod, "-cb", uploadSpeed, "-cp", serialPort, "-ca", uploadAddress, "-cf", imagePath});
350+
}
318351
}
319352
}
320353

0 commit comments

Comments
 (0)