mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 12:14:32 +02:00
Merge branch 'task/nvs_util_file_handling' into 'master'
nvs_util: Update file I/O handling for error handling across various OS See merge request espressif/esp-idf!10051
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from __future__ import division, print_function
|
from __future__ import division, print_function
|
||||||
|
from future.moves.itertools import zip_longest
|
||||||
from builtins import int, range, bytes
|
from builtins import int, range, bytes
|
||||||
from io import open
|
from io import open
|
||||||
import sys
|
import sys
|
||||||
@@ -28,7 +29,6 @@ import random
|
|||||||
import struct
|
import struct
|
||||||
import os
|
import os
|
||||||
import array
|
import array
|
||||||
import csv
|
|
||||||
import zlib
|
import zlib
|
||||||
import codecs
|
import codecs
|
||||||
import datetime
|
import datetime
|
||||||
@@ -905,19 +905,40 @@ def generate(args, is_encr_enabled=False, encr_key=None):
|
|||||||
with open(args.input, 'rt', encoding='utf8') as input_file,\
|
with open(args.input, 'rt', encoding='utf8') as input_file,\
|
||||||
open(args.output, 'wb') as output_file,\
|
open(args.output, 'wb') as output_file,\
|
||||||
nvs_open(output_file, input_size, args.version, is_encrypt=is_encr_enabled, key=encr_key) as nvs_obj:
|
nvs_open(output_file, input_size, args.version, is_encrypt=is_encr_enabled, key=encr_key) as nvs_obj:
|
||||||
# Comments are skipped
|
|
||||||
reader = csv.DictReader(filter(lambda row: row[0] != '#',input_file), delimiter=',')
|
|
||||||
if nvs_obj.version == Page.VERSION1:
|
if nvs_obj.version == Page.VERSION1:
|
||||||
version_set = VERSION1_PRINT
|
version_set = VERSION1_PRINT
|
||||||
else:
|
else:
|
||||||
version_set = VERSION2_PRINT
|
version_set = VERSION2_PRINT
|
||||||
|
|
||||||
print("\nCreating NVS binary with version:", version_set)
|
print("\nCreating NVS binary with version:", version_set)
|
||||||
for row in reader:
|
|
||||||
|
line = input_file.readline().strip()
|
||||||
|
|
||||||
|
# Comments are skipped
|
||||||
|
while line.startswith('#'):
|
||||||
|
line = input_file.readline().strip()
|
||||||
|
if not isinstance(line, str):
|
||||||
|
line = line.encode('utf-8')
|
||||||
|
|
||||||
|
header = line.split(',')
|
||||||
|
|
||||||
|
while True:
|
||||||
|
line = input_file.readline().strip()
|
||||||
|
if not isinstance(line, str):
|
||||||
|
line = line.encode('utf-8')
|
||||||
|
|
||||||
|
value = line.split(',')
|
||||||
|
if len(value) == 1 and '' in value:
|
||||||
|
break
|
||||||
|
|
||||||
|
data = dict(zip_longest(header, value))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Check key length
|
# Check key length
|
||||||
if len(row["key"]) > 15:
|
if len(data["key"]) > 15:
|
||||||
raise InputError("Length of key `%s` should be <= 15 characters." % row["key"])
|
raise InputError("Length of key `{}` should be <= 15 characters.".format(data["key"]))
|
||||||
write_entry(nvs_obj, row["key"], row["type"], row["encoding"], row["value"])
|
write_entry(nvs_obj, data["key"], data["type"], data["encoding"], data["value"])
|
||||||
except InputError as e:
|
except InputError as e:
|
||||||
print(e)
|
print(e)
|
||||||
filedir, filename = os.path.split(args.output)
|
filedir, filename = os.path.split(args.output)
|
||||||
|
Reference in New Issue
Block a user