diff --git a/scripts/klayout/xml_drc_report_to_json.py b/scripts/klayout/xml_drc_report_to_json.py index 687e043ae..bf2cdb726 100644 --- a/scripts/klayout/xml_drc_report_to_json.py +++ b/scripts/klayout/xml_drc_report_to_json.py @@ -12,7 +12,6 @@ # 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. - import json from klayout.rdb import ReportDatabase @@ -26,17 +25,18 @@ def cli(xml_file, json_file): database = ReportDatabase("Database") json_database = {} database.load(xml_file) + total = 0 for category in database.each_category(): num_items = category.num_items() category_name = category.name() json_database[category_name] = num_items + total += num_items + + json_database = dict(sorted(json_database.items(), key=lambda item: item[1])) + json_database["total"] = total - with open(json_file, "w") as f: - f.write( - json.dumps( - dict(sorted(json_database.items(), key=lambda item: item[1])), indent=4 - ) - ) + with open(json_file, "w", encoding="utf8") as f: + json.dump(json_database, f) if __name__ == "__main__": diff --git a/scripts/tcl_commands/checkers.tcl b/scripts/tcl_commands/checkers.tcl index a339bb578..697f53614 100755 --- a/scripts/tcl_commands/checkers.tcl +++ b/scripts/tcl_commands/checkers.tcl @@ -387,24 +387,9 @@ proc quit_on_unconnected_pdn_nodes {args} { } } -proc get_violations_count {report_file} { - package require json - - set total_violations_count 0 - - set fp [open $report_file r] - set violations_json [read $fp] - close $fp - - set violations_dict [json::json2dict $violations_json] - foreach count [dict values $violations_dict] { - set total_violations_count [expr $total_violations_count + $count] - } - return $total_violations_count -} - proc quit_on_klayout_drc {report_file} { - set violations_count [get_violations_count $report_file] + set violations_dict [json::json2dict [cat $report_file]] + set violations_count [dict get $violations_dict "total"] if { $::env(QUIT_ON_KLAYOUT_DRC) && $violations_count != 0} { puts_err "There are violations in the design after KLayout DRC." puts_err "Total Number of violations is $violations_count"