From 0ecdbc2065b4bc76cda5ed492ddb52d79088a21a Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Tue, 14 Jun 2022 19:23:14 +0300 Subject: [PATCH 1/2] Do not show python traceback when esptool fails Path separator already handled by python Empty strings are false, implicitly checking for length --- tools/upload.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/tools/upload.py b/tools/upload.py index 2b7016cc95..0328c23bfb 100755 --- a/tools/upload.py +++ b/tools/upload.py @@ -6,17 +6,17 @@ # First parameter is pyserial path, second is esptool path, then a series of command arguments # i.e. upload.py tools/pyserial tools/esptool write_flash file 0x0 -import sys import os +import sys import tempfile sys.argv.pop(0) # Remove executable name -toolspath = os.path.dirname(os.path.realpath(__file__)).replace('\\', '/') # CWD in UNIX format +toolspath = os.path.dirname(os.path.realpath(__file__)) try: - sys.path.insert(0, toolspath + "/pyserial") # Add pyserial dir to search path - sys.path.insert(0, toolspath + "/esptool") # Add esptool dir to search path + sys.path.insert(0, os.path.join(toolspath, "pyserial")) # Add pyserial dir to search path + sys.path.insert(0, os.path.join(toolspath, "esptool")) # Add esptool dir to search path import esptool # If this fails, we can't continue and will bomb below -except Exception: +except ImportError: sys.stderr.write("pyserial or esptool directories not found next to this upload.py tool.\n") sys.exit(1) @@ -45,25 +45,30 @@ elif thisarg == 'write_flash': write_addr = sys.argv.pop(0) binary = sys.argv.pop(0) - elif len(thisarg): + elif thisarg: cmdline = cmdline + [thisarg] cmdline = cmdline + ['write_flash'] -if len(write_option): +if write_option: cmdline = cmdline + [write_option] cmdline = cmdline + ['--flash_size', 'detect'] cmdline = cmdline + [write_addr, binary] erase_file = '' -if len(erase_addr): +if erase_addr: # Generate temporary empty (0xff) file eraser = tempfile.mkstemp() erase_file = eraser[1] - os.write(eraser[0], bytearray([255] * int(erase_len, 0))) + os.write(eraser[0], bytearray([0xff] * int(erase_len, 0))) os.close(eraser[0]) - cmdline = cmdline + [ erase_addr, erase_file ] + cmdline = cmdline + [erase_addr, erase_file] -esptool.main(cmdline) - -if len(erase_file): - os.remove(erase_file) +try: + esptool.main(cmdline) +except esptool.FatalError as e: + sys.stderr.write('\nA fatal esptool.py error occurred: %s' % e) +finally: + if len(erase_file): + os.remove(erase_file) + if sys.exc_info: + sys.exit(2) From 4b89bcb4a2b988e0005c64205767ed6832048b54 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Wed, 15 Jun 2022 01:38:08 +0300 Subject: [PATCH 2/2] Update upload.py --- tools/upload.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/upload.py b/tools/upload.py index 0328c23bfb..29819e5375 100755 --- a/tools/upload.py +++ b/tools/upload.py @@ -26,7 +26,7 @@ erase_addr = '' erase_len = '' -while len(sys.argv): +while sys.argv: thisarg = sys.argv.pop(0) # We silently replace the 921kbaud setting with 460k to enable backward @@ -68,7 +68,7 @@ except esptool.FatalError as e: sys.stderr.write('\nA fatal esptool.py error occurred: %s' % e) finally: - if len(erase_file): + if erase_file: os.remove(erase_file) if sys.exc_info: sys.exit(2) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy