From 29b7193fcf2e51986a3f7906b279de4aac11e6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20St=C3=B6r?= Date: Sun, 17 Feb 2019 15:00:00 +0100 Subject: [PATCH] Improve esptool command assembler to support " " in file paths --- Main.py | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/Main.py b/Main.py index 41b9f92..eea3972 100644 --- a/Main.py +++ b/Main.py @@ -74,20 +74,24 @@ class FlashingThread(threading.Thread): def run(self): try: - command = "" + command = [] if not self._config.port.startswith(__auto_select__): - command += "--port %s " % self._config.port + command.append("--port") + command.append(self._config.port) - command += "--baud %s --after no_reset write_flash --flash_mode %s 0x00000 %s" % \ - (self._config.baud, self._config.mode, self._config.firmware_path) + command.extend(["--baud", str(self._config.baud), + "--after", "no_reset", + "write_flash", + "--flash_mode", self._config.mode, + "0x00000", self._config.firmware_path]) if self._config.erase_before_flash: - command += " --erase-all" + command.append("--erase-all") - print("Command: esptool.py %s\n" % command) + print("Command: esptool.py %s\n" % " ".join(command)) - esptool.main(command.split(" ")) + esptool.main(command) # The last line printed by esptool is "Staying in bootloader." -> some indication that the process is # done is needed @@ -97,25 +101,6 @@ class FlashingThread(threading.Thread): self._parent.report_error(e.strerror) raise e - @staticmethod - def connect_to_esp(initial_baud): - # stripped down version of esptool.py:2537 - ser_list = sorted(ports.device for ports in list_ports.comports()) - print("Found %d serial ports" % len(ser_list)) - esp = None - for each_port in reversed(ser_list): - print("Testing serial port %s" % each_port) - try: - esp = ESPLoader.detect_chip(each_port, initial_baud) - break # on the first detected Espressif device - except (FatalError, OSError) as err: - print("%s failed to connect: %s" % (each_port, err)) - esp = None - if esp is None: - print("\nAll of the %d available serial ports could not connect to a Espressif device." % len(ser_list)) - raise FatalError('No serial port with ESP') - return esp - # ---------------------------------------------------------------------------