@@ -64,196 +64,6 @@ class OMCSessionException(Exception):
6464 """
6565
6666
67- class OMCSessionCmd :
68- """
69- Implementation of Open Modelica Compiler API functions. Depreciated!
70- """
71-
72- def __init__ (self , session : OMCSession , readonly : bool = False ):
73- if not isinstance (session , OMCSession ):
74- raise OMCSessionException ("Invalid OMC process definition!" )
75- self ._session = session
76- self ._readonly = readonly
77- self ._omc_cache : dict [tuple [str , bool ], Any ] = {}
78-
79- def _ask (self , question : str , opt : Optional [list [str ]] = None , parsed : bool = True ):
80-
81- if opt is None :
82- expression = question
83- elif isinstance (opt , list ):
84- expression = f"{ question } ({ ',' .join ([str (x ) for x in opt ])} )"
85- else :
86- raise OMCSessionException (f"Invalid definition of options for { repr (question )} : { repr (opt )} " )
87-
88- p = (expression , parsed )
89-
90- if self ._readonly and question != 'getErrorString' :
91- # can use cache if readonly
92- if p in self ._omc_cache :
93- return self ._omc_cache [p ]
94-
95- try :
96- res = self ._session .sendExpression (expression , parsed = parsed )
97- except OMCSessionException as ex :
98- raise OMCSessionException (f"OMC _ask() failed: { expression } (parsed={ parsed } )" ) from ex
99-
100- # save response
101- self ._omc_cache [p ] = res
102-
103- return res
104-
105- # TODO: Open Modelica Compiler API functions. Would be nice to generate these.
106- def loadFile (self , filename ):
107- return self ._ask (question = 'loadFile' , opt = [f'"{ filename } "' ])
108-
109- def loadModel (self , className ):
110- return self ._ask (question = 'loadModel' , opt = [className ])
111-
112- def isModel (self , className ):
113- return self ._ask (question = 'isModel' , opt = [className ])
114-
115- def isPackage (self , className ):
116- return self ._ask (question = 'isPackage' , opt = [className ])
117-
118- def isPrimitive (self , className ):
119- return self ._ask (question = 'isPrimitive' , opt = [className ])
120-
121- def isConnector (self , className ):
122- return self ._ask (question = 'isConnector' , opt = [className ])
123-
124- def isRecord (self , className ):
125- return self ._ask (question = 'isRecord' , opt = [className ])
126-
127- def isBlock (self , className ):
128- return self ._ask (question = 'isBlock' , opt = [className ])
129-
130- def isType (self , className ):
131- return self ._ask (question = 'isType' , opt = [className ])
132-
133- def isFunction (self , className ):
134- return self ._ask (question = 'isFunction' , opt = [className ])
135-
136- def isClass (self , className ):
137- return self ._ask (question = 'isClass' , opt = [className ])
138-
139- def isParameter (self , className ):
140- return self ._ask (question = 'isParameter' , opt = [className ])
141-
142- def isConstant (self , className ):
143- return self ._ask (question = 'isConstant' , opt = [className ])
144-
145- def isProtected (self , className ):
146- return self ._ask (question = 'isProtected' , opt = [className ])
147-
148- def getPackages (self , className = "AllLoadedClasses" ):
149- return self ._ask (question = 'getPackages' , opt = [className ])
150-
151- def getClassRestriction (self , className ):
152- return self ._ask (question = 'getClassRestriction' , opt = [className ])
153-
154- def getDerivedClassModifierNames (self , className ):
155- return self ._ask (question = 'getDerivedClassModifierNames' , opt = [className ])
156-
157- def getDerivedClassModifierValue (self , className , modifierName ):
158- return self ._ask (question = 'getDerivedClassModifierValue' , opt = [className , modifierName ])
159-
160- def typeNameStrings (self , className ):
161- return self ._ask (question = 'typeNameStrings' , opt = [className ])
162-
163- def getComponents (self , className ):
164- return self ._ask (question = 'getComponents' , opt = [className ])
165-
166- def getClassComment (self , className ):
167- try :
168- return self ._ask (question = 'getClassComment' , opt = [className ])
169- except pyparsing .ParseException as ex :
170- logger .warning ("Method 'getClassComment(%s)' failed; OMTypedParser error: %s" ,
171- className , ex .msg )
172- return 'No description available'
173- except OMCSessionException :
174- raise
175-
176- def getNthComponent (self , className , comp_id ):
177- """ returns with (type, name, description) """
178- return self ._ask (question = 'getNthComponent' , opt = [className , comp_id ])
179-
180- def getNthComponentAnnotation (self , className , comp_id ):
181- return self ._ask (question = 'getNthComponentAnnotation' , opt = [className , comp_id ])
182-
183- def getImportCount (self , className ):
184- return self ._ask (question = 'getImportCount' , opt = [className ])
185-
186- def getNthImport (self , className , importNumber ):
187- # [Path, id, kind]
188- return self ._ask (question = 'getNthImport' , opt = [className , importNumber ])
189-
190- def getInheritanceCount (self , className ):
191- return self ._ask (question = 'getInheritanceCount' , opt = [className ])
192-
193- def getNthInheritedClass (self , className , inheritanceDepth ):
194- return self ._ask (question = 'getNthInheritedClass' , opt = [className , inheritanceDepth ])
195-
196- def getParameterNames (self , className ):
197- try :
198- return self ._ask (question = 'getParameterNames' , opt = [className ])
199- except KeyError as ex :
200- logger .warning ('OMPython error: %s' , ex )
201- # FIXME: OMC returns with a different structure for empty parameter set
202- return []
203- except OMCSessionException :
204- raise
205-
206- def getParameterValue (self , className , parameterName ):
207- try :
208- return self ._ask (question = 'getParameterValue' , opt = [className , parameterName ])
209- except pyparsing .ParseException as ex :
210- logger .warning ("Method 'getParameterValue(%s, %s)' failed; OMTypedParser error: %s" ,
211- className , parameterName , ex .msg )
212- return ""
213- except OMCSessionException :
214- raise
215-
216- def getComponentModifierNames (self , className , componentName ):
217- return self ._ask (question = 'getComponentModifierNames' , opt = [className , componentName ])
218-
219- def getComponentModifierValue (self , className , componentName ):
220- return self ._ask (question = 'getComponentModifierValue' , opt = [className , componentName ])
221-
222- def getExtendsModifierNames (self , className , componentName ):
223- return self ._ask (question = 'getExtendsModifierNames' , opt = [className , componentName ])
224-
225- def getExtendsModifierValue (self , className , extendsName , modifierName ):
226- return self ._ask (question = 'getExtendsModifierValue' , opt = [className , extendsName , modifierName ])
227-
228- def getNthComponentModification (self , className , comp_id ):
229- # FIXME: OMPython exception Results KeyError exception
230-
231- # get {$Code(....)} field
232- # \{\$Code\((\S*\s*)*\)\}
233- value = self ._ask (question = 'getNthComponentModification' , opt = [className , comp_id ], parsed = False )
234- value = value .replace ("{$Code(" , "" )
235- return value [:- 3 ]
236- # return self.re_Code.findall(value)
237-
238- # function getClassNames
239- # input TypeName class_ = $Code(AllLoadedClasses);
240- # input Boolean recursive = false;
241- # input Boolean qualified = false;
242- # input Boolean sort = false;
243- # input Boolean builtin = false "List also builtin classes if true";
244- # input Boolean showProtected = false "List also protected classes if true";
245- # output TypeName classNames[:];
246- # end getClassNames;
247- def getClassNames (self , className = None , recursive = False , qualified = False , sort = False , builtin = False ,
248- showProtected = False ):
249- opt = [className ] if className else [] + [f'recursive={ str (recursive ).lower ()} ' ,
250- f'qualified={ str (qualified ).lower ()} ' ,
251- f'sort={ str (sort ).lower ()} ' ,
252- f'builtin={ str (builtin ).lower ()} ' ,
253- f'showProtected={ str (showProtected ).lower ()} ' ]
254- return self ._ask (question = 'getClassNames' , opt = opt )
255-
256-
25767class _OMCPathReal (pathlib .PurePosixPath ):
25868 """
25969 Implementation of a basic (PurePosix)Path object which uses OMC as backend. The connection to OMC is provided via an
0 commit comments