Пример #1
0
 def execute(self, create_API_object=False):
   """
   :param bool createAPIObject: True if the runner should create the API object
   :returns str: error from execution
   Executes as a string if there is no filepath. Otherwise,
   executes from the filepath.
   """
   if create_API_object:
     error = self._createAPIObject()
     if error is not None:
       return error
   executer = ProgramExecuter(self._program_filename,
       self._program, self._table.getNamespace())
   if not self._user_directory is None:
     sys.path.append(self._user_directory)
   # Check syntax here because there may be an uncorrected
   # syntax error in a column
   msg = executer.execute()
   # Update the table columns
   namespace = executer.getNamespace()
   if API_OBJECT in namespace:
     api_object = namespace[API_OBJECT]
     api_object.updateColumnFromColumnVariables()
     api_object.controller.endProgram(
         details="After updateColumnFromColumnVariables")
   return msg
Пример #2
0
 def do(self):
     """
 Construct the statement
 :return str: error or None
 """
     error = None
     if self._formula is None:
         self._statement = None
         self._isExpression = False
         self._isStatement = False
         return
     exception_stmt = None
     exception_expr = None
     try:
         # See if this is an expression
         _ = compile(self._formula, "string", "eval")
         statement = "%s = %s" % (self._name, self._formula)
         self._isExpression = True
         self._statement = statement
     except SyntaxError as err:
         linenumber = 1
         error = "At line %d, %s" % (linenumber, str(err))
     if error is not None:
         executer = ProgramExecuter(self._name, self._formula, {})
         error = executer.checkSyntax()
         self._isExpression = False
         self._statement = self._formula
     return error
Пример #3
0
 def do(self):
   """
   Construct the statement
   :return str: error or None
   """
   error = None
   if self._formula is None:
     self._statement = None
     self._isExpression = False
     self._isStatement = False
     return
   exception_stmt = None
   exception_expr = None
   try:
     # See if this is an expression
     _ = compile(self._formula, "string", "eval")
     statement = "%s = %s" % (self._name, 
         self._formula)
     self._isExpression = True
     self._statement = statement
   except SyntaxError as err:
     linenumber = 1
     error = "At line %d, %s" % (linenumber, str(err))
   if error is not None:
     executer = ProgramExecuter(self._name,
         self._formula, {})
     error = executer.checkSyntax()
     self._isExpression = False
     self._statement = self._formula
   return error
Пример #4
0
 def execute(self, create_API_object=False):
     """
 :param bool createAPIObject: True if the runner should create the API object
 :returns str: error from execution
 Executes as a string if there is no filepath. Otherwise,
 executes from the filepath.
 """
     if create_API_object:
         error = self._createAPIObject()
         if error is not None:
             return error
     executer = ProgramExecuter(self._program_filename, self._program,
                                self._table.getNamespace())
     if not self._user_directory is None:
         sys.path.append(self._user_directory)
     # Check syntax here because there may be an uncorrected
     # syntax error in a column
     msg = executer.execute()
     # Update the table columns
     namespace = executer.getNamespace()
     if API_OBJECT in namespace:
         api_object = namespace[API_OBJECT]
         api_object.updateColumnFromColumnVariables()
         api_object.controller.endProgram(
             details="After updateColumnFromColumnVariables")
     return msg
Пример #5
0
 def _runProgram(self, program_name, program, exc_lineno):
     """
 Executes the program.
 :param str program_name:
 :param str program:
 :param int exc_lineno: line number of exception (0 if None)
 :return str: message from syntax checking and program execution
 """
     executer = ProgramExecuter(program_name, program, self.namespace)
     msg = executer.execute()
     if msg is None:
         msg = executer.execute()
         if exc_lineno == 0:
             self.assertIsNone(msg)
         else:
             self.assertTrue(str(exc_lineno) in msg)
     return msg
Пример #6
0
  def _createAPIObject(self):  
    """
    Creates the API object needed for the runtime.
    Note that the APIFormulas object is created in the program
    to avoid circular imports.
    :return str error: error from execution
    """
    namespace = self._table.getNamespace()
    namespace['_table'] = self._table
    program = """
from scisheets.core import api as api
%s = api.APIFormulas(_table, is_logging=True, debug=%s)
""" % (API_OBJECT, self.debug)
    executer = ProgramExecuter("ProgramRunner._createAPIObject", program, 
        namespace)
    result = executer.execute()
    namespace[API_OBJECT] = executer.getNamespace()[API_OBJECT]
    return result
 def _runProgram(self, program_name, program, exc_lineno):
   """
   Executes the program.
   :param str program_name:
   :param str program:
   :param int exc_lineno: line number of exception (0 if None)
   :return str: message from syntax checking and program execution
   """
   executer = ProgramExecuter(program_name, program,
       self.namespace)
   msg = executer.execute()
   if msg is None:
     msg = executer.execute()
     if exc_lineno == 0:
       self.assertIsNone(msg)
     else:
       self.assertTrue(str(exc_lineno) in msg)
   return msg
Пример #8
0
    def _createAPIObject(self):
        """
    Creates the API object needed for the runtime.
    Note that the APIFormulas object is created in the program
    to avoid circular imports.
    :return str error: error from execution
    """
        namespace = self._table.getNamespace()
        namespace['_table'] = self._table
        program = """
from scisheets.core import api as api
%s = api.APIFormulas(_table, is_logging=True, debug=%s)
""" % (API_OBJECT, self.debug)
        executer = ProgramExecuter("ProgramRunner._createAPIObject", program,
                                   namespace)
        result = executer.execute()
        try:
            namespace[API_OBJECT] = executer.getNamespace()[API_OBJECT]
        except Exception as e:
            import pdb
            pdb.set_trace()
            pass
        return result