65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
|
|
from services.validation.logic_validation import validate_logic_against_config
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(
|
|
description="Validate ICS-SimLab logic/*.py against configuration.json"
|
|
)
|
|
parser.add_argument(
|
|
"--config",
|
|
default="outputs/configuration.json",
|
|
help="Path to configuration.json",
|
|
)
|
|
parser.add_argument(
|
|
"--logic-dir",
|
|
default="logic",
|
|
help="Directory containing logic .py files",
|
|
)
|
|
|
|
# PLC: write -> callback
|
|
parser.add_argument(
|
|
"--check-callbacks",
|
|
action="store_true",
|
|
help="Enable PLC rule: every output write must be followed by state_update_callbacks[id]()",
|
|
)
|
|
parser.add_argument(
|
|
"--callback-window",
|
|
type=int,
|
|
default=3,
|
|
help="How many subsequent statements to search for the callback after an output write (default: 3)",
|
|
)
|
|
|
|
# HIL: init physical_values
|
|
parser.add_argument(
|
|
"--check-hil-init",
|
|
action="store_true",
|
|
help="Enable HIL rule: all hils[].physical_values keys must be initialized in the HIL logic file",
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
issues = validate_logic_against_config(
|
|
args.config,
|
|
args.logic_dir,
|
|
check_callbacks=args.check_callbacks,
|
|
callback_window=args.callback_window,
|
|
check_hil_init=args.check_hil_init,
|
|
)
|
|
|
|
if not issues:
|
|
print("OK: logica coerente con configuration.json")
|
|
return
|
|
|
|
print(f"TROVATI {len(issues)} PROBLEMI:")
|
|
for i in issues:
|
|
print(f"- [{i.kind}] {i.file}: '{i.key}' -> {i.message}")
|
|
|
|
raise SystemExit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|