-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmh_debug_enumerate_simulink_blocks
executable file
·83 lines (64 loc) · 3.28 KB
/
mh_debug_enumerate_simulink_blocks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
##############################################################################
## ##
## MATLAB Independent, Small & Safe, High Integrity Tools ##
## ##
## Copyright (C) 2020, Florian Schanda ##
## ##
## This file is part of MISS_HIT. ##
## ##
## MATLAB Independent, Small & Safe, High Integrity Tools (MISS_HIT) is ##
## free software: you can redistribute it and/or modify it under the ##
## terms of the GNU General Public License as published by the Free ##
## Software Foundation, either version 3 of the License, or (at your ##
## option) any later version. ##
## ##
## MISS_HIT is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with MISS_HIT. If not, see <http://www.gnu.org/licenses/>. ##
## ##
##############################################################################
# This is a small helper tool that, when given a directory, will
# display all Simulink block types in all slx models in that
# directory.
import os
import argparse
from miss_hit_core import command_line
from miss_hit_core.config import Config
from miss_hit_core.errors import Message_Handler
from miss_hit_core.s_parser import Simulink_SLX_Parser
def process(mh, root_dir, file_name):
# pylint: disable=unused-argument
# short_name = file_name[len(root_dir.rstrip("/")) + 1:]
mh.register_file(file_name)
rv = set()
slp = Simulink_SLX_Parser(mh, file_name, Config())
n_container = slp.parse_file()
if n_container:
for n_block in n_container.iter_all_blocks():
rv.add(n_block.kind)
return rv
def main():
ap = argparse.ArgumentParser()
ap.add_argument("root_dir")
options = ap.parse_args()
mh = Message_Handler("debug")
mh.sort_messages = False
all_block_kinds = set()
for path, _, files in os.walk(options.root_dir):
for f in files:
if f.endswith(".slx"):
all_block_kinds |= process(mh,
options.root_dir,
os.path.join(path, f))
print("Sorted list of all Simulink blocks types (%u) present:" %
len(all_block_kinds))
for block_type in sorted(all_block_kinds):
print(" %s" % block_type)
mh.summary_and_exit()
if __name__ == "__main__":
command_line.ice_handler(main)