my.writeln("<pre>") my.writeln(stack_trace) my.writeln("</pre>") raise e #return try: # WARNING: if this call causes an exception, the error # will be obscure log = ExceptionLog.log(e) except Exception, e2: print "Error: Could not log exception: ", e2.__str__() my.writeln("Error '%s': Could not log exception" % e2.__str__() ) stack_trace = ExceptionLog.get_stack_trace(e2) print stack_trace my.writeln("<pre>") my.writeln(stack_trace) my.writeln("</pre>") return my.writeln("<pre>") my.writeln("An Error has occurred. Please see your Tactic Administrator<br/>") my.writeln( "Error Message: %s" % log.get_value("message") ) my.writeln("Error Id: %s" % log.get_id() ) my.writeln( log.get_value("stack_trace") ) my.writeln("</pre>") finally:
class BaseAppServer(Base): '''The base application server class that handles the top level processing of a given page. Different applications will derive off of this class to implement how the resulting html will go to the server''' ONLOAD_EVENT = "body_onload" if PROFILE: profile.object = None def __init__(my): my.top = None my.hash = None super(BaseAppServer,my).__init__() def writeln(my, string): my.buffer.write(string) def get_display(my): profile_flag = False if profile_flag: BaseAppServer.profile.object = my if os.name == 'nt': path = "C:/sthpw/profile" else: path = "/tmp/sthpw/temp/profile" profile.run( "from pyasm.web.app_server import BaseAppServer; BaseAppServer.profile()", path) p = pstats.Stats(path) p.sort_stats('cumulative').print_stats(30) print "*"*30 p.sort_stats('time').print_stats(30) else: my.execute() value = WebContainer.get_buffer().getvalue() WebContainer.clear_buffer() return value def profile(): my = BaseAppServer.profile.object my.execute() profile = staticmethod(profile) def execute(my): my.buffer = cStringIO.StringIO() try: try: # clear the main container for this thread Container.create() # clear the buffer WebContainer.clear_buffer() # initialize the web environment object and register it adapter = my.get_adapter() WebContainer.set_web(adapter) # get the display my._get_display() except SetupException, e: '''Display setup exception in the interface''' print "Setup exception: ", e.__str__() DbContainer.rollback_all() ExceptionLog.log(e) my.writeln("<h3>Tactic Setup Error</h3>" ) my.writeln("<pre>" ) my.writeln(e.__str__() ) my.writeln("</pre>" ) except DatabaseException, e: from tactic.ui.startup import DbConfigPanelWdg config_wdg = DbConfigPanelWdg() my.writeln("<pre>") my.writeln(config_wdg.get_buffer_display()) my.writeln("</pre>") except Exception, e: stack_trace = ExceptionLog.get_stack_trace(e) print stack_trace my.writeln("<pre>") my.writeln(stack_trace) my.writeln("</pre>") # it is possible that the security object was not set security = Environment.get_security() if not security: security = Security() WebContainer.set_security(security) log = None # ensure that database connections are rolled back try: DbContainer.rollback_all() except Exception, e2: print "Error: Could not rollback: ", e2.__str__() my.writeln("Error: Could not rollback: '%s'" % e2.__str__() ) stack_trace = ExceptionLog.get_stack_trace(e2) print stack_trace my.writeln("<pre>") my.writeln(stack_trace) my.writeln("</pre>") raise e
def execute(self): self.buffer = cStringIO.StringIO() error = None try: try: # clear the main container for this thread Container.create() # clear the buffer WebContainer.clear_buffer() # initialize the web environment object and register it adapter = self.get_adapter() WebContainer.set_web(adapter) # get the display self._get_display() except SetupException as e: '''Display setup exception in the interface''' print("Setup exception: ", e.__str__()) DbContainer.rollback_all() ExceptionLog.log(e) self.writeln("<h3>Tactic Setup Error</h3>") self.writeln("<pre>") self.writeln(e.__str__()) self.writeln("</pre>") error = "405: TACTIC Setup Error" except DatabaseException as e: from tactic.ui.startup import DbConfigPanelWdg config_wdg = DbConfigPanelWdg() self.writeln("<pre>") self.writeln(config_wdg.get_buffer_display()) self.writeln("</pre>") error = "405: TACTIC Database Error" except Exception as e: stack_trace = ExceptionLog.get_stack_trace(e) #print(stack_trace) self.writeln("<pre>") self.writeln(stack_trace) self.writeln("</pre>") error = "405 %s" % str(e) # it is possible that the security object was not set security = Environment.get_security() if not security: security = Security() WebContainer.set_security(security) log = None # ensure that database connections are rolled back try: DbContainer.rollback_all() except Exception as e2: print("Error: Could not rollback: ", e2.__str__()) self.writeln("Error: Could not rollback: '%s'" % e2.__str__()) stack_trace = ExceptionLog.get_stack_trace(e2) print(stack_trace) self.writeln("<pre>") self.writeln(stack_trace) self.writeln("</pre>") raise e #return try: # WARNING: if this call causes an exception, the error # will be obscure log = ExceptionLog.log(e) except Exception as e2: print("Error: Could not log exception: ", e2.__str__()) self.writeln("Error '%s': Could not log exception" % e2.__str__()) stack_trace = ExceptionLog.get_stack_trace(e2) print(stack_trace) self.writeln("<pre>") self.writeln(stack_trace) self.writeln("</pre>") return self.writeln("<pre>") self.writeln( "An Error has occurred. Please see your Tactic Administrator<br/>" ) self.writeln("Error Message: %s" % log.get_value("message")) self.writeln("Error Id: %s" % log.get_id()) #self.writeln( log.get_value("stack_trace") ) self.writeln("</pre>") finally: # ensure that database connections are always closed DbContainer.close_all() # clear the container Container.delete() WebContainer.get_buffer().write(self.buffer.getvalue()) if error: import cherrypy print("error: ", error) cherrypy.response.status = error
def execute(self): self.buffer = cStringIO.StringIO() error = None try: try: # clear the main container for this thread Container.create() # clear the buffer WebContainer.clear_buffer() # initialize the web environment object and register it adapter = self.get_adapter() WebContainer.set_web(adapter) # get the display self._get_display() except SetupException as e: '''Display setup exception in the interface''' print("Setup exception: ", e.__str__()) DbContainer.rollback_all() ExceptionLog.log(e) self.writeln("<h3>Tactic Setup Error</h3>" ) self.writeln("<pre>" ) self.writeln(e.__str__() ) self.writeln("</pre>" ) error = "405: TACTIC Setup Error" except DatabaseException as e: from tactic.ui.startup import DbConfigPanelWdg config_wdg = DbConfigPanelWdg() self.writeln("<pre>") self.writeln(config_wdg.get_buffer_display()) self.writeln("</pre>") error = "405: TACTIC Database Error" except Exception as e: stack_trace = ExceptionLog.get_stack_trace(e) #print(stack_trace) self.writeln("<pre>") self.writeln(stack_trace) self.writeln("</pre>") error = "405 %s" % str(e) # it is possible that the security object was not set security = Environment.get_security() if not security: security = Security() WebContainer.set_security(security) log = None # ensure that database connections are rolled back try: DbContainer.rollback_all() except Exception as e2: print("Error: Could not rollback: ", e2.__str__()) self.writeln("Error: Could not rollback: '%s'" % e2.__str__() ) stack_trace = ExceptionLog.get_stack_trace(e2) print(stack_trace) self.writeln("<pre>") self.writeln(stack_trace) self.writeln("</pre>") raise e #return try: # WARNING: if this call causes an exception, the error # will be obscure log = ExceptionLog.log(e) except Exception as e2: print("Error: Could not log exception: ", e2.__str__()) self.writeln("Error '%s': Could not log exception" % e2.__str__() ) stack_trace = ExceptionLog.get_stack_trace(e2) print(stack_trace) self.writeln("<pre>") self.writeln(stack_trace) self.writeln("</pre>") return self.writeln("<pre>") self.writeln("An Error has occurred. Please see your Tactic Administrator<br/>") self.writeln( "Error Message: %s" % log.get_value("message") ) self.writeln("Error Id: %s" % log.get_id() ) #self.writeln( log.get_value("stack_trace") ) self.writeln("</pre>") finally: # ensure that database connections are always closed DbContainer.close_all() # clear the container Container.delete() WebContainer.get_buffer().write( self.buffer.getvalue() ) if error: import cherrypy print("error: ", error) cherrypy.response.status = error