534 |
536 |
535 |
537 |
536 # Exception hooks s |
538 # Exception hooks s |
537 |
539 |
538 |
540 |
|
541 |
|
542 def LogMessageAndException(msg, exp=None): |
|
543 if exp is None: |
|
544 exp = sys.exc_info() |
|
545 if pyroserver.plcobj is not None: |
|
546 pyroserver.plcobj.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp))) |
|
547 else: |
|
548 print(msg) |
|
549 traceback.print_exception(*exp) |
|
550 |
539 def LogException(*exp): |
551 def LogException(*exp): |
540 if pyroserver.plcobj is not None: |
552 LogExceptionAndMessage("",exp) |
541 pyroserver.plcobj.LogMessage(0, '\n'.join(traceback.format_exception(*exp))) |
|
542 else: |
|
543 traceback.print_exception(*exp) |
|
544 |
|
545 |
553 |
546 sys.excepthook = LogException |
554 sys.excepthook = LogException |
547 |
555 |
548 |
556 |
549 def installThreadExcepthook(): |
557 def installThreadExcepthook(): |
586 except Exception, e: |
594 except Exception, e: |
587 print(_("WAMP import failed :"), e) |
595 print(_("WAMP import failed :"), e) |
588 wampconf = None |
596 wampconf = None |
589 |
597 |
590 # Load extensions |
598 # Load extensions |
591 for extfilename in extensions: |
599 for extention_file, extension_folder in extensions: |
592 extension_folder = os.path.split(os.path.realpath(extfilename))[0] |
|
593 sys.path.append(extension_folder) |
600 sys.path.append(extension_folder) |
594 execfile(extfilename, locals()) |
601 execfile(os.path.join(extension_folder, extention_file), locals()) |
595 |
602 |
596 if havetwisted: |
603 if havetwisted: |
597 if webport is not None: |
604 if webport is not None: |
598 try: |
605 try: |
599 website = NS.RegisterWebsite(webport) |
606 website = NS.RegisterWebsite(webport) |
600 pyruntimevars["website"] = website |
607 pyruntimevars["website"] = website |
601 statuschange.append(NS.website_statuslistener_factory(website)) |
608 statuschange.append(NS.website_statuslistener_factory(website)) |
602 except Exception, e: |
609 except Exception: |
603 print(_("Nevow Web service failed. "), e) |
610 LogMessageAndException(_("Nevow Web service failed. ")) |
604 |
611 |
605 if wampconf is not None: |
612 if wampconf is not None: |
606 try: |
613 try: |
607 _wampconf = WC.LoadWampClientConf(wampconf) |
614 _wampconf = WC.LoadWampClientConf(wampconf) |
608 if _wampconf: |
615 if _wampconf: |
609 if _wampconf["url"]: # TODO : test more ? |
616 if _wampconf["url"]: # TODO : test more ? |
610 WC.RegisterWampClient(wampconf, wampsecret) |
617 WC.RegisterWampClient(wampconf, wampsecret) |
611 pyruntimevars["wampsession"] = WC.GetSession |
618 pyruntimevars["wampsession"] = WC.GetSession |
612 WC.SetServer(pyroserver) |
619 WC.SetServer(pyroserver) |
613 else: |
620 else: |
614 print(_("WAMP config is incomplete.")) |
621 raise Exception(_("WAMP config is incomplete.")) |
615 else: |
622 else: |
616 print(_("WAMP config is missing.")) |
623 raise Exception(_("WAMP config is missing.")) |
617 except Exception, e: |
624 except Exception: |
618 print(_("WAMP client startup failed. "), e) |
625 LogMessageAndException(_("WAMP client startup failed. ")) |
619 |
626 |
620 |
627 |
621 if havetwisted or havewx: |
628 if havetwisted or havewx: |
622 pyro_thread = Thread(target=pyroserver.Loop) |
629 pyro_thread = Thread(target=pyroserver.Loop) |
623 pyro_thread.start() |
630 pyro_thread.start() |