Exemple #1
0
 def _Run(self, loggingState):
     """Execute the function associated with the thread."""
     try:
         if loggingState is not None:
             cx_Logging.SetLoggingState(loggingState)
         self.OnThreadStart()
         try:
             self.function(*self.args, **self.keywordArgs)
         except:
             cx_Logging.Error("Exception in thread %s" % self.name)
             self.errorObj = cx_Exceptions.GetExceptionInfo(*sys.exc_info())
             cx_Logging.Error("    Message: %s" % self.errorObj.message)
             cx_Logging.Error("    TemplateId: %s" % \
                     self.errorObj.templateId)
             cx_Logging.Error("    Arguments:")
             for name, value in self.errorObj.arguments.iteritems():
                 cx_Logging.Error("        %s -> %r" % (name, value))
             cx_Logging.Error("    Traceback:")
             for line in self.errorObj.traceback:
                 cx_Logging.Error("        %s" % line)
             cx_Logging.Error("    Details:")
             for line in self.errorObj.details:
                 cx_Logging.Error("        %s" % line)
             cx_Logging.Error("Thread terminating")
     finally:
         self.stopped = True
         self.OnThreadEnd()
         if self.event:
             self.event.Set()
 def Process(self, processor):
     connection = processor.connection
     cursor = connection.cursor()
     cursor.execute("select user from dual")
     user, = cursor.fetchone()
     parser = cx_OracleParser.SimpleParser()
     sql = open(self.fileName).read()
     connectStatementClass = parser.parser.processor.ConnectStatement
     try:
         for statement in parser.IterParse(sql, user):
             if isinstance(statement, connectStatementClass):
                 connection = cx_OracleEx.Connection(
                     statement.user, statement.password
                     or connection.password, statement.dsn
                     or connection.dsn)
                 cursor = connection.cursor()
                 cx_Logging.Trace("%s", statement.GetLogMessage(cursor))
                 parser.parser.processor.owner = statement.user
             else:
                 try:
                     statement.Process(cursor)
                 except cx_Exceptions.BaseException as error:
                     lineNumber = statement.lineNumber
                     if isinstance(error, cx_OracleEx.DatabaseException) \
                             and error.dbErrorOffset is not None:
                         offset = error.dbErrorOffset
                         lineNumber += statement.sql[:offset].count("\n")
                     cx_Logging.Error("Error at line %s", lineNumber)
                     if not processor.onErrorContinue:
                         raise
                     cx_Logging.Error("%s", error.message)
     except cx_OracleParser.ParsingFailed as value:
         cx_Logging.Error("Parsing failed at line %s (%s...)",
                          value.arguments["lineNumber"],
                          value.arguments["remainingString"][:100])
Exemple #3
0
def CheckForErrors(cursor,
                   objectOwner,
                   objectName,
                   objectType,
                   errorFragment,
                   baseLineNo=0,
                   logPrefix=""):
    """Check the object for errors, and if any exist, print them."""
    cursor.execute(None, owner=objectOwner, name=objectName, type=objectType)
    errors = cursor.fetchall()
    if errors:
        cx_Logging.Error("%s***** ERROR *****", logPrefix)
        for line, position, text in errors:
            cx_Logging.Error("%s%s/%s\t%s", logPrefix, int(line + baseLineNo),
                             int(position), text)
        raise CompilationErrors(type=objectType.capitalize(),
                                name=objectName.upper(),
                                fragment=errorFragment)
Exemple #4
0
def ExceptionHandler(excType, excValue, traceback):
    """Exception handler suitable for placing in sys.excepthook."""
    error = cx_Exceptions.GetExceptionInfo(excType, excValue, traceback)
    fullTraceback = not hasattr(sys, "tracebacklimit")
    if fullTraceback:
        cx_Logging.LogException(error)
    else:
        cx_Logging.Error("%s", error.message)
    if sys.stdout.isatty() and not sys.stderr.isatty():
        print(error.message)
        if fullTraceback:
            print("See log file for more details.")
Exemple #5
0
 def run(self):
     """Execute the function associated with the thread."""
     cx_Logging.SetExceptionInfo(cx_Exceptions.BaseException,
                                 cx_Exceptions.GetExceptionInfo)
     try:
         self.OnThreadStart()
         try:
             super(Thread, self).run()
         except:
             self.errorObj = cx_Logging.LogException()
             cx_Logging.Error("Thread %r terminating", self.name)
     finally:
         self.OnThreadEnd()
         if self.event:
             self.event.set()
Exemple #6
0
 def _Run(self, loggingState):
     """Execute the function associated with the thread."""
     cx_Logging.SetExceptionInfo(cx_Exceptions.BaseException,
             cx_Exceptions.GetExceptionInfo)
     try:
         if loggingState is not None:
             cx_Logging.SetLoggingState(loggingState)
         self.OnThreadStart()
         try:
             self.function(*self.args, **self.keywordArgs)
         except:
             self.errorObj = cx_Logging.LogException()
             cx_Logging.Error("Thread %r terminating", self.name)
     finally:
         self.stopped = True
         self.OnThreadEnd()
         if self.event:
             self.event.Set()