From 5296fe8d2ed9ccac2f73964573895fc8f80fb22d Mon Sep 17 00:00:00 2001 From: arun3688 Date: Mon, 11 Apr 2016 15:11:02 +0200 Subject: [PATCH 1/2] add flag parsed=true for sendExpression --- OMPython/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/OMPython/__init__.py b/OMPython/__init__.py index 6103409..40ae535 100755 --- a/OMPython/__init__.py +++ b/OMPython/__init__.py @@ -57,6 +57,7 @@ import time import logging import uuid +import getpass import subprocess import tempfile import pyparsing @@ -182,7 +183,7 @@ def __init__(self, readonly=False): if sys.platform == 'win32': self._omc_log_file = open(os.path.join(self._temp_dir, "openmodelica.objid." + self._random_string+".log"), 'w') else: - self._currentUser = os.environ['USER'] + self._currentUser = getpass.getuser() if not self._currentUser: self._currentUser = "nobody" # this file must be closed in the destructor @@ -220,7 +221,7 @@ def execute(self, command): # FIXME: we should have one function which interacts with OMC. Either execute OR sendExpression. # Execute uses OMParser.check_for_values and sendExpression uses OMTypedParser.parseString. # We should have one parser. Then we can get rid of one of these functions. - def sendExpression(self, command): + def sendExpression(self, command, parsed=True): """ Sends an expression to the OpenModelica. The return type is parsed as if the expression was part of the typed OpenModelica API (see ModelicaBuiltin.mo). @@ -238,8 +239,11 @@ def sendExpression(self, command): self._omc = None return result else: - answer = OMTypedParser.parseString(result) - return answer + if (parsed==True): + answer = OMTypedParser.parseString(result) + return answer + else: + return result else: return "No connection with OMC. Create an instance of OMCSession." From 8c0f91d26d68440d1fe8c8825124e58cdf39100c Mon Sep 17 00:00:00 2001 From: arun3688 Date: Fri, 29 Apr 2016 13:45:56 +0200 Subject: [PATCH 2/2] catch PyParsing Exception results --- OMPython/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OMPython/__init__.py b/OMPython/__init__.py index 40ae535..23ea902 100755 --- a/OMPython/__init__.py +++ b/OMPython/__init__.py @@ -221,7 +221,7 @@ def execute(self, command): # FIXME: we should have one function which interacts with OMC. Either execute OR sendExpression. # Execute uses OMParser.check_for_values and sendExpression uses OMTypedParser.parseString. # We should have one parser. Then we can get rid of one of these functions. - def sendExpression(self, command, parsed=True): + def sendExpression(self, command): """ Sends an expression to the OpenModelica. The return type is parsed as if the expression was part of the typed OpenModelica API (see ModelicaBuiltin.mo). @@ -239,10 +239,10 @@ def sendExpression(self, command, parsed=True): self._omc = None return result else: - if (parsed==True): + try: answer = OMTypedParser.parseString(result) return answer - else: + except: return result else: return "No connection with OMC. Create an instance of OMCSession."