File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 33import sys
44from typing import Dict , List
55from pathlib import Path
6- from natsort import natsorted
76from enum import Enum
7+ from datetime import datetime
8+ from platform import platform
9+
10+ from natsort import natsorted
811
912from .register_checks import InspectorMessage
1013from .utils import FilePathType
1114
15+ try :
16+ from importlib .metadata import version
17+
18+ inspector_version = version ("nwbinspector" )
19+ except ModuleNotFoundError : # Remove the except clause when minimal supported version becomes 3.8
20+ from pkg_resources import get_distribution
21+
22+ inspector_version = get_distribution ("nwbinspector" ).version
23+
24+
25+ def get_report_header ():
26+ """Grab basic information from system at time of report generation."""
27+ return dict (Timestamp = str (datetime .now ().astimezone ()), Platform = platform (), NWBInspector_version = inspector_version )
28+
1229
1330def _sort_unique_values (unique_values : list , reverse : bool = False ):
1431 """Technically, the 'set' method applies basic sorting to the unique contents, but natsort is more general."""
Original file line number Diff line number Diff line change 1818
1919from . import available_checks
2020from .inspector_tools import (
21+ get_report_header ,
2122 organize_messages ,
2223 format_organized_results_output ,
2324 print_to_console ,
@@ -201,8 +202,12 @@ def inspect_all_cli(
201202 )
202203 )
203204 if json_file_path is not None :
205+ if Path (json_file_path ).exists () and not overwrite :
206+ raise FileExistsError (f"The file { json_file_path } already exists! Specify the '-o' flag to overwrite." )
204207 with open (file = json_file_path , mode = "w" ) as fp :
205- json .dump (obj = messages , fp = fp , cls = InspectorOutputJSONEncoder )
208+ json_report = dict (header = get_report_header (), messages = messages )
209+ json .dump (obj = json_report , fp = fp , cls = InspectorOutputJSONEncoder )
210+ print (f"{ os .linesep * 2 } Report saved to { str (Path (json_file_path ).absolute ())} !{ os .linesep } " )
206211 if len (messages ):
207212 organized_results = organize_messages (messages = messages , levels = ["file_path" , "importance" ])
208213 formatted_results = format_organized_results_output (organized_results = organized_results )
You can’t perform that action at this time.
0 commit comments