mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 09:09:10 -04:00
feat(mfg_gen): provision for specifying prefix counter for csv/bin files
This commit is contained in:
parent
e05fce3c9c
commit
99f1455199
@ -157,7 +157,7 @@ Running the utility
|
||||
|
||||
**Usage**::
|
||||
|
||||
python mfg_gen.py generate [-h] [--fileid FILEID] [--version {1,2}] [--keygen]
|
||||
python mfg_gen.py generate [-h] [--prefix_num start length] [--fileid FILEID] [--version {1,2}] [--keygen]
|
||||
[--inputkey INPUTKEY] [--outdir OUTDIR]
|
||||
[--key_protect_hmac] [--kp_hmac_keygen]
|
||||
[--kp_hmac_keyfile KP_HMAC_KEYFILE] [--kp_hmac_inputkey KP_HMAC_INPUTKEY]
|
||||
@ -184,6 +184,10 @@ Running the utility
|
||||
+=============================================+===============================================================================+
|
||||
| ``-h`` / ``--help`` | Show the help message and exit |
|
||||
+---------------------------------------------+-------------------------------------------------------------------------------+
|
||||
| ``--prefix_num start length`` | Prefix number start and length (in digits) to be added for each output |
|
||||
| | filename. The number is used as monotonic counter, thus different for each |
|
||||
| | file. |
|
||||
+---------------------------------------------+-------------------------------------------------------------------------------+
|
||||
| ``--fileid FILEID`` | Unique file identifier (any key in values file) |
|
||||
| | for each filename suffix (Default: numeric value(1,2,3...)) |
|
||||
+---------------------------------------------+-------------------------------------------------------------------------------+
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
import argparse
|
||||
@ -262,11 +262,14 @@ def create_intermediate_csv(args, keys_in_values_file, keys_repeat, is_encr=Fals
|
||||
values_file_reader = csv.reader(csv_values_file, delimiter=',')
|
||||
next(values_file_reader)
|
||||
|
||||
# Create new directory(if doesn't exist) to store csv file generated
|
||||
# Create new directory (if doesn't exist) to store csv file generated
|
||||
output_csv_target_dir = create_dir('csv', args.outdir)
|
||||
# Create new directory(if doesn't exist) to store bin file generated
|
||||
# Create new directory (if doesn't exist) to store bin file generated
|
||||
output_bin_target_dir = create_dir('bin', args.outdir)
|
||||
|
||||
if args.prefix_num:
|
||||
prefix_num_start, prefix_num_digits = args.prefix_num
|
||||
|
||||
for values_data_line in values_file_reader:
|
||||
key_value_data = list(zip_longest(keys_in_values_file, values_data_line))
|
||||
|
||||
@ -275,9 +278,18 @@ def create_intermediate_csv(args, keys_in_values_file, keys_repeat, is_encr=Fals
|
||||
|
||||
key_value_pair = key_value_data[:]
|
||||
|
||||
# Verify if output csv file does not exist
|
||||
csv_filename = args.prefix + '-' + file_identifier_value + '.' + 'csv'
|
||||
if args.prefix_num:
|
||||
# Create file name prefix based on user supplied start and length
|
||||
prefix_number = f'{prefix_num_start:0{prefix_num_digits}}'
|
||||
csv_filename = args.prefix + '-' + prefix_number + '-' + file_identifier_value + '.' + 'csv'
|
||||
bin_filename = args.prefix + '-' + prefix_number + '-' + file_identifier_value + '.' + 'bin'
|
||||
prefix_num_start += 1
|
||||
else:
|
||||
csv_filename = args.prefix + '-' + file_identifier_value + '.' + 'csv'
|
||||
bin_filename = args.prefix + '-' + file_identifier_value + '.' + 'bin'
|
||||
|
||||
output_csv_file = output_csv_target_dir + csv_filename
|
||||
# Verify if output csv file does not exist
|
||||
if os.path.isfile(output_csv_file):
|
||||
raise SystemExit('Target csv file: %s already exists.`' % output_csv_file)
|
||||
|
||||
@ -285,9 +297,8 @@ def create_intermediate_csv(args, keys_in_values_file, keys_repeat, is_encr=Fals
|
||||
add_data_to_file(config_data_to_write, key_value_pair, output_csv_file)
|
||||
print('\nCreated CSV file: ===>', output_csv_file)
|
||||
|
||||
# Verify if output bin file does not exist
|
||||
bin_filename = args.prefix + '-' + file_identifier_value + '.' + 'bin'
|
||||
output_bin_file = output_bin_target_dir + bin_filename
|
||||
# Verify if output bin file does not exist
|
||||
if os.path.isfile(output_bin_file):
|
||||
raise SystemExit('Target binary file: %s already exists.`' % output_bin_file)
|
||||
|
||||
@ -398,6 +409,11 @@ def main():
|
||||
default=None,
|
||||
help='Size of NVS partition in bytes\
|
||||
\n(must be multiple of 4096)')
|
||||
parser_gen.add_argument('--prefix_num',
|
||||
type=int,
|
||||
nargs=2,
|
||||
metavar=('start', 'length'),
|
||||
help='Prefix number (counter) start and length (in digits) to be added for each output filename')
|
||||
parser_gen.add_argument('--fileid',
|
||||
default=None,
|
||||
help='''Unique file identifier(any key in values file) \
|
||||
|
Loading…
x
Reference in New Issue
Block a user