From: Piyush Shah Date: Thu, 14 Jun 2018 10:37:26 +0000 (+0530) Subject: nvs_partition_generator: Modifications to enable using the utility as a Python library X-Git-Tag: v3.2-beta1~463^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8369bd244b1b878486a713f6137c7c3df5185e68;p=esp-idf nvs_partition_generator: Modifications to enable using the utility as a Python library And also use directly as an executable --- diff --git a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py old mode 100644 new mode 100755 index ecbe9b5db0..b895fc1ca2 --- a/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py +++ b/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py @@ -333,29 +333,42 @@ def nvs_close(nvs_instance): """ nvs_instance.__exit__(None, None, None) +def nvs_part_gen(input_filename=None, output_filename=None): + input_file = open(input_filename, 'rb') + output_file = open(output_filename, 'wb') + + with nvs_open(output_file) as nvs_obj: + reader = csv.DictReader(input_file, delimiter=',') + for row in reader: + try: + write_entry(nvs_obj, row["key"], row["type"], row["encoding"], row["value"]) + except InputError as e: + print(e) + input_file.close() + output_file.close() + exit(-2) + + input_file.close() + output_file.close() + def main(): parser = argparse.ArgumentParser(description="ESP32 NVS partition generation utility") parser.add_argument( "input", help="Path to CSV file to parse. Will use stdin if omitted", - type=argparse.FileType('rb'), default=sys.stdin) parser.add_argument( "output", help='Path to output converted binary file. Will use stdout if omitted', - type=argparse.FileType('wb'), default=sys.stdout) args = parser.parse_args() - with nvs_open(args.output) as nvs_obj: - reader = csv.DictReader(args.input, delimiter=',') - for row in reader: - try: - write_entry(nvs_obj, row["key"], row["type"], row["encoding"], row["value"]) - except InputError as e: - print(e) - exit(-2) + input_filename = args.input + output_filename = args.output + nvs_part_gen(input_filename, output_filename) + + if __name__ == "__main__": main() diff --git a/tools/ci/executable-list.txt b/tools/ci/executable-list.txt index 6fc884a001..3fe4158f94 100644 --- a/tools/ci/executable-list.txt +++ b/tools/ci/executable-list.txt @@ -7,6 +7,7 @@ components/partition_table/gen_esp32part.py components/partition_table/parttool.py components/partition_table/test_gen_esp32part_host/gen_esp32part_tests.py components/ulp/esp32ulp_mapgen.py +components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py docs/check_doc_warnings.sh docs/check_lang_folder_sync.sh docs/gen-kconfig-doc.py