forked from openhwgroup/core-v-verif
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openhwgroup#2164 from silabs-robin/json_vplans
New Script - (Auxiliary) Vplans in JSON
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env python3 | ||
|
||
|
||
# Copyright 2023 Silicon Labs, Inc. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1 | ||
# | ||
# Licensed under the Solderpad Hardware License v 2.1 (the "License"); you may | ||
# not use this file except in compliance with the License, or, at your option, | ||
# the Apache License version 2.0. | ||
# | ||
# You may obtain a copy of the License at | ||
# https://solderpad.org/licenses/SHL-2.1/ | ||
# | ||
# Unless required by applicable law or agreed to in writing, any work | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
""" | ||
Description: | ||
Converts ".csv" vplans to ".json". | ||
Rationale: | ||
It is an alternative to the ".csv" vplans, which in some cases might be | ||
easier to review. | ||
Usage: | ||
Run it on a ".csv" vplan. | ||
""" | ||
|
||
|
||
import csv | ||
import json | ||
import sys | ||
|
||
|
||
# Check correct usage | ||
|
||
if len(sys.argv) != 2: | ||
message = "usage: {} <csv vplan>".format(sys.argv[0]) | ||
sys.exit(message) | ||
|
||
|
||
# Read ".csv" | ||
|
||
csv_filename = sys.argv[1] | ||
csv_file = open(csv_filename, 'r', encoding='utf-8') | ||
csv_reader = csv.DictReader(csv_file) | ||
|
||
|
||
# Fill empty cells (with value of above cell) | ||
|
||
csv_rows = [] | ||
csv_row_previous = None | ||
|
||
for row in csv_reader: | ||
for key, value in row.items(): | ||
if not value and csv_row_previous: | ||
row[key] = csv_row_previous[key] | ||
# TODO not for "link-to-cov" etc | ||
|
||
csv_rows.append(row) | ||
csv_row_previous = row | ||
|
||
|
||
# Write ".json" | ||
|
||
json_string = json.dumps(csv_rows, indent = 4) | ||
json_filename = csv_filename.replace(".csv", ".json") | ||
json_file = open(json_filename, 'w', encoding='utf-8') | ||
|
||
json_file.write(json_string) |
File renamed without changes.