File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import argparse
2+ import xml .etree .ElementTree as ET
3+ import shutil
4+ from pathlib import Path
5+
6+
7+ def get_matlab_root () -> Path :
8+ ml = shutil .which ("matlab" )
9+ if ml is None :
10+ raise FileNotFoundError ("MATLAB executable not found in PATH." )
11+
12+ return Path (ml ).parents [1 ]
13+
14+
15+ def get_matlab_version (root : Path ) -> str :
16+ if not root .is_dir ():
17+ raise NotADirectoryError (f"{ root } is not a valid directory." )
18+
19+ xmlPath = root / "VersionInfo.xml"
20+ if not xmlPath .is_file ():
21+ raise FileNotFoundError (xmlPath )
22+
23+ tree = ET .parse (xmlPath )
24+ root = tree .getroot ()
25+
26+ return root .find ('version' ).text
27+
28+
29+ if __name__ == "__main__" :
30+ parser = argparse .ArgumentParser (description = "Get MATLAB version from VersionInfo.xml" )
31+ parser .add_argument ('matlab_root' , nargs = '?' , help = "Path to MATLAB root directory" )
32+ args = parser .parse_args ()
33+
34+ root = Path (args .matlab_root ) if args .matlab_root else get_matlab_root ()
35+
36+ print (get_matlab_version (root ))
You can’t perform that action at this time.
0 commit comments