1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

Use Pythonic way of calling esptool, avoid fork(#5797)

Simply import the pyserial and esptool modules directly into upload.py
instead of trying to fake things with os.fork()s.  Reduces code and is
more Pythonic.
This commit is contained in:
Earle F. Philhower, III
2019-02-21 19:03:15 +00:00
committed by GitHub
parent f08346a73e
commit 472faf73a2
3 changed files with 14 additions and 23 deletions

View File

@ -3,17 +3,16 @@
# Wrapper for Arduino core / others that can call esptool.py possibly multiple times
# Adds pyserial to sys.path automatically based on the path of the current file
# First patameter is pyserial path, then a series of command arguments separated with --end
# i.e. upload.py tools/pyserial tools/esptool/esptool.py erase_flash --end write_flash file 0x0 --end
# First parameter is pyserial path, second is esptool path, then a series of command arguments separated with --end
# i.e. upload.py tools/pyserial tools/esptool erase_flash --end write_flash file 0x0 --end
import inspect
import os
import sys
sys.argv.pop(0) # Remove executable name
try:
sys.path.append(sys.argv.pop(0).replace('\\', '/')) # Add pyserial dir to search path, in UNIX format
esptool = sys.argv.pop(0).replace('\\', '/') # Full path to esptool.py, in UNIX format
sys.path.append(sys.argv.pop(0).replace('\\', '/')) # Add esptool dir to search path, in UNIX format
import esptool # If this fails, we can't continue and will bomb below
except:
sys.stderr.write("Error in command line, need pyserial path as 1st arg and esptool path as 2nd.\n")
sys.exit(1)
@ -21,14 +20,7 @@ except:
fakeargs = [];
while len(sys.argv):
if sys.argv[0] == '--end':
pid = os.fork()
if pid == 0:
sys.argv = ['esptool.py'] + fakeargs
sys.stderr.write("Running: " + " ".join(sys.argv) + "\n")
exec(open(esptool).read())
sys.exit(0)
else:
os.waitpid(pid, 0)
esptool.main(fakeargs)
sys.argv.pop(0) # Remove --end
fakeargs = []
else: