Skip to content

Commit

Permalink
esptool.py: Allow adding arguments from file via @filename.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
projectgus committed Nov 17, 2016
1 parent fb02da9 commit d9b82fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Most hardware configurations will work with `-b 230400`, some with `-b 460800`,

If you have connectivity problems then you can also set baud rates below 115200. You can also choose 74880, which is the usual baud rate used by the ESP8266 to output [boot log](#boot-log) information.

## Specifying Arguments Via File

Anywhere on the `esptool.py` command line, you can specify a file name as `@filename.txt` to read one or more arguments from text file `filename.txt`. Arguments can be separated by newlines or spaces, quotes can be used to enclose arguments that span multiple words. Arguments read from the text file are expanded exactly as if they had appeared in that order on the `esptool.py` command line.

## Commands

### Convert ELF to Binary
Expand Down
21 changes: 21 additions & 0 deletions esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import time
import base64
import zlib
import shlex

__version__ = "2.0-dev"

Expand Down Expand Up @@ -1855,6 +1856,8 @@ def add_spi_flash_subparsers(parent):
for operation in subparsers.choices.keys():
assert operation in globals(), "%s should be a module function" % operation

expand_file_arguments()

args = parser.parse_args()

print 'esptool.py v%s' % __version__
Expand Down Expand Up @@ -1896,6 +1899,24 @@ def add_spi_flash_subparsers(parent):
else:
operation_func(args)

def expand_file_arguments():
""" Any argument starting with "@" gets replaced with all values read from a text file.
Text file arguments can be split by newline or by space.
Values are added "as-is", as if they were specified in this order on the command line.
"""
new_args = []
expanded = False
for arg in sys.argv:
if arg.startswith("@"):
expanded = True
with open(arg[1:],"r") as f:
for line in f.readlines():
new_args += shlex.split(line)
else:
new_args.append(arg)
if expanded:
print "esptool.py %s" % (" ".join(new_args[1:]))
sys.argv = new_args

class FlashSizeAction(argparse.Action):
""" Custom flash size parser class to support backwards compatibility with megabit size arguments.
Expand Down

0 comments on commit d9b82fa

Please sign in to comment.