mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
6caa4a17ac
Currently the wrapper tries to figure out which version of the esp-idf-size should be started. The legacy version is used if explicitly requested by the -l/--legacy option or if json format is specified. This works fine, but if help is requested, it is printed for the wrapper as shown bellow $ idf_size.py -h usage: idf_size.py [-h] [--format FORMAT] [-l] options: -h, --help show this help message and exit --format FORMAT -l, --legacy This is not convenient and the full help from the underlying version should be displayed. Fix this by only peeking into the args to figure out if legacy or refactored version should be started and always spawn the underlying esp_idf_size python module. This is done by using exit_on_error=False and add_help=False for the ArgumentParser. When help for refactored version is requested a note as following is printed to notify users that the legacy version can still be used. $ idf_size.py -h Note: legacy esp_idf_size version can be invoked by specifying the -l/--legacy option or by setting the ESP_IDF_SIZE_LEGACY environment variable. Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
43 lines
1.8 KiB
Python
Executable File
43 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python
|
|
#
|
|
# SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
import argparse
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
if __name__ == '__main__':
|
|
# Here the argparse is used only to "peek" into arguments if
|
|
# legacy version is requested or if old json format is specified.
|
|
# In these two cases the esp_idf_size legacy version is spawned.
|
|
parser = argparse.ArgumentParser(exit_on_error=False, add_help=False)
|
|
parser.add_argument('--format')
|
|
parser.add_argument('-l', '--legacy', action='store_true', default=os.environ.get('ESP_IDF_SIZE_LEGACY', '0') == '1')
|
|
|
|
# The sys.argv is parsed with "exit_on_error", but the argparse.ArgumentError
|
|
# exception should never occur, because unknown args should be put into
|
|
# the rest variable, since the parse_known_args() method is used.
|
|
args, rest = parser.parse_known_args()
|
|
|
|
if not args.legacy and args.format != 'json':
|
|
# By default start the refactored version, unless legacy version is explicitly requested with
|
|
# -l/--legacy option or if old json format is specified.
|
|
try:
|
|
import esp_idf_size.ng # noqa: F401
|
|
except ImportError:
|
|
print('warning: refactored esp-idf-size not installed, using legacy mode', file=sys.stderr)
|
|
args.legacy = True
|
|
else:
|
|
os.environ['ESP_IDF_SIZE_NG'] = '1'
|
|
if not rest or '-h' in rest or '--help' in rest:
|
|
print(('Note: legacy esp_idf_size version can be invoked by specifying the -l/--legacy '
|
|
'option or by setting the ESP_IDF_SIZE_LEGACY environment variable.'))
|
|
|
|
if args.format is not None:
|
|
rest = ['--format', args.format] + rest
|
|
|
|
sys.exit(subprocess.run([sys.executable, '-m', 'esp_idf_size'] + rest).returncode)
|