Edouard@641: #!/usr/bin/env python Edouard@641: # -*- coding: utf-8 -*- Edouard@641: Edouard@641: #This file is part of Beremiz, a Integrated Development Environment for Edouard@1434: #programming IEC 61131-3 automates supporting plcopen standard and CanFestival. Edouard@641: # Edouard@641: #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD Edouard@641: # Edouard@641: #See COPYING file for copyrights details. Edouard@641: # Edouard@641: #This library is free software; you can redistribute it and/or Edouard@641: #modify it under the terms of the GNU General Public Edouard@641: #License as published by the Free Software Foundation; either Edouard@641: #version 2.1 of the License, or (at your option) any later version. Edouard@641: # Edouard@641: #This library is distributed in the hope that it will be useful, Edouard@641: #but WITHOUT ANY WARRANTY; without even the implied warranty of Edouard@641: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Edouard@641: #General Public License for more details. Edouard@641: # Edouard@641: #You should have received a copy of the GNU General Public Edouard@641: #License along with this library; if not, write to the Free Software Edouard@641: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Edouard@641: Edouard@641: import os, sys, getopt Edouard@1067: from threading import Thread Edouard@641: Edouard@641: def usage(): Edouard@641: print """ Edouard@641: Usage of Beremiz PLC execution service :\n Edouard@644: %s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir Edouard@641: -n - zeroconf service name (default:disabled) Edouard@644: -i - IP address of interface to bind to (default:localhost) Edouard@641: -p - port number default:3000 Edouard@641: -h - print this help text and quit Edouard@641: -a - autostart PLC (0:disable 1:enable) (default:0) Edouard@641: -x - enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1) Edouard@641: -t - enable/disable Twisted web interface (0:disable 1:enable) (default:1) Edouard@1437: -e - python extension (absolute path .py) Edouard@1434: Edouard@641: working_dir - directory where are stored PLC files Edouard@641: """%sys.argv[0] Edouard@641: Edouard@641: try: Edouard@1437: opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:e:h") Edouard@641: except getopt.GetoptError, err: Edouard@641: # print help information and exit: Edouard@641: print str(err) # will print something like "option -a not recognized" Edouard@641: usage() Edouard@641: sys.exit(2) Edouard@641: Edouard@641: # default values Edouard@644: given_ip = None Edouard@641: port = 3000 Edouard@641: servicename = None Edouard@641: autostart = False Edouard@641: enablewx = True Edouard@641: havewx = False Edouard@641: enabletwisted = True Edouard@641: havetwisted = False Edouard@641: Edouard@1437: extensions=[] Edouard@1437: Edouard@641: for o, a in opts: Edouard@641: if o == "-h": Edouard@641: usage() Edouard@641: sys.exit() Edouard@641: elif o == "-i": Edouard@641: if len(a.split(".")) == 4 or a == "localhost": Edouard@644: given_ip = a Edouard@644: else: Edouard@644: usage() Edouard@644: sys.exit() Edouard@641: elif o == "-p": Edouard@641: # port: port that the service runs on Edouard@641: port = int(a) Edouard@641: elif o == "-n": Edouard@641: servicename = a Edouard@641: elif o == "-x": Edouard@641: enablewx = int(a) Edouard@641: elif o == "-t": Edouard@641: enabletwisted = int(a) Edouard@641: elif o == "-a": Edouard@641: autostart = int(a) Edouard@1437: elif o == "-e": Edouard@1437: extensions.append(a) Edouard@641: else: Edouard@641: usage() Edouard@641: sys.exit() Edouard@641: Edouard@1434: CWD = os.path.split(os.path.realpath(__file__))[0] Edouard@1434: Edouard@641: if len(argv) > 1: Edouard@641: usage() Edouard@641: sys.exit() Edouard@641: elif len(argv) == 1: Edouard@641: WorkingDir = argv[0] Edouard@641: os.chdir(WorkingDir) Edouard@641: elif len(argv) == 0: Edouard@641: WorkingDir = os.getcwd() Edouard@641: argv=[WorkingDir] Edouard@641: Edouard@641: import __builtin__ Edouard@641: if __name__ == '__main__': Edouard@641: __builtin__.__dict__['_'] = lambda x: x Edouard@641: Edouard@641: if enablewx: Edouard@641: try: Edouard@641: import wx, re Edouard@641: from threading import Thread, currentThread Edouard@641: from types import * Edouard@641: havewx = True Edouard@641: except: Edouard@641: print "Wx unavailable !" Edouard@641: havewx = False Edouard@641: Edouard@641: if havewx: Edouard@641: app=wx.App(redirect=False) Edouard@1434: Edouard@641: # Import module for internationalization Edouard@641: import gettext Edouard@1434: Edouard@1067: def Bpath(*args): Edouard@1067: return os.path.join(CWD,*args) Edouard@1434: Edouard@641: # Get folder containing translation files Edouard@641: localedir = os.path.join(CWD,"locale") Edouard@641: # Get the default language Edouard@641: langid = wx.LANGUAGE_DEFAULT Edouard@641: # Define translation domain (name of translation files) Edouard@641: domain = "Beremiz" Edouard@641: Edouard@641: # Define locale for wx Edouard@641: loc = __builtin__.__dict__.get('loc', None) Edouard@641: if loc is None: Edouard@641: loc = wx.Locale(langid) Edouard@641: __builtin__.__dict__['loc'] = loc Edouard@641: # Define location for searching translation files Edouard@641: loc.AddCatalogLookupPathPrefix(localedir) Edouard@641: # Define locale domain Edouard@641: loc.AddCatalog(domain) Edouard@641: Edouard@641: def unicode_translation(message): Edouard@641: return wx.GetTranslation(message).encode("utf-8") Edouard@641: Edouard@641: if __name__ == '__main__': Edouard@641: __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation Edouard@1434: Edouard@1067: defaulticon = wx.Image(Bpath("images", "brz.png")) Edouard@1067: starticon = wx.Image(Bpath("images", "icoplay24.png")) Edouard@1067: stopicon = wx.Image(Bpath("images", "icostop24.png")) Edouard@1434: Edouard@641: class ParamsEntryDialog(wx.TextEntryDialog): Edouard@641: if wx.VERSION < (2, 6, 0): Edouard@641: def Bind(self, event, function, id = None): Edouard@641: if id is not None: Edouard@641: event(self, id, function) Edouard@641: else: Edouard@641: event(self, function) Edouard@1434: Edouard@1434: Edouard@1434: def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", Edouard@641: style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): Edouard@641: wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) Edouard@1434: Edouard@641: self.Tests = [] Edouard@641: if wx.VERSION >= (2, 8, 0): Edouard@641: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetAffirmativeId()) Edouard@641: elif wx.VERSION >= (2, 6, 0): Edouard@641: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) Edouard@641: else: Edouard@641: self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) Edouard@1434: Edouard@641: def OnOK(self, event): Edouard@641: value = self.GetValue() Edouard@641: texts = {"value" : value} Edouard@641: for function, message in self.Tests: Edouard@641: if not function(value): Edouard@641: message = wx.MessageDialog(self, message%texts, _("Error"), wx.OK|wx.ICON_ERROR) Edouard@641: message.ShowModal() Edouard@641: message.Destroy() Edouard@641: return Edouard@641: self.EndModal(wx.ID_OK) Edouard@641: event.Skip() Edouard@1434: Edouard@641: def GetValue(self): Edouard@641: return self.GetSizer().GetItem(1).GetWindow().GetValue() Edouard@1434: Edouard@641: def SetTests(self, tests): Edouard@641: self.Tests = tests Edouard@1434: Edouard@641: class BeremizTaskBarIcon(wx.TaskBarIcon): Edouard@641: TBMENU_START = wx.NewId() Edouard@641: TBMENU_STOP = wx.NewId() Edouard@641: TBMENU_CHANGE_NAME = wx.NewId() Edouard@641: TBMENU_CHANGE_PORT = wx.NewId() Edouard@641: TBMENU_CHANGE_INTERFACE = wx.NewId() Edouard@641: TBMENU_LIVE_SHELL = wx.NewId() Edouard@641: TBMENU_WXINSPECTOR = wx.NewId() Edouard@641: TBMENU_CHANGE_WD = wx.NewId() Edouard@641: TBMENU_QUIT = wx.NewId() Edouard@1434: Edouard@835: def __init__(self, pyroserver, level): Edouard@641: wx.TaskBarIcon.__init__(self) Edouard@641: self.pyroserver = pyroserver Edouard@641: # Set the image Edouard@641: self.UpdateIcon(None) Edouard@835: self.level = level Edouard@1434: Edouard@641: # bind some events Edouard@641: self.Bind(wx.EVT_MENU, self.OnTaskBarStartPLC, id=self.TBMENU_START) Edouard@641: self.Bind(wx.EVT_MENU, self.OnTaskBarStopPLC, id=self.TBMENU_STOP) Edouard@641: self.Bind(wx.EVT_MENU, self.OnTaskBarChangeName, id=self.TBMENU_CHANGE_NAME) Edouard@641: self.Bind(wx.EVT_MENU, self.OnTaskBarChangeInterface, id=self.TBMENU_CHANGE_INTERFACE) Edouard@641: self.Bind(wx.EVT_MENU, self.OnTaskBarLiveShell, id=self.TBMENU_LIVE_SHELL) Edouard@641: self.Bind(wx.EVT_MENU, self.OnTaskBarWXInspector, id=self.TBMENU_WXINSPECTOR) Edouard@641: self.Bind(wx.EVT_MENU, self.OnTaskBarChangePort, id=self.TBMENU_CHANGE_PORT) Edouard@641: self.Bind(wx.EVT_MENU, self.OnTaskBarChangeWorkingDir, id=self.TBMENU_CHANGE_WD) Edouard@641: self.Bind(wx.EVT_MENU, self.OnTaskBarQuit, id=self.TBMENU_QUIT) Edouard@1434: Edouard@641: def CreatePopupMenu(self): Edouard@641: """ Edouard@641: This method is called by the base class when it needs to popup Edouard@641: the menu for the default EVT_RIGHT_DOWN event. Just create Edouard@641: the menu how you want it and return it from this function, Edouard@641: the base class takes care of the rest. Edouard@641: """ Edouard@641: menu = wx.Menu() Edouard@641: menu.Append(self.TBMENU_START, _("Start PLC")) Edouard@641: menu.Append(self.TBMENU_STOP, _("Stop PLC")) Edouard@835: if self.level==1: Edouard@835: menu.AppendSeparator() Edouard@835: menu.Append(self.TBMENU_CHANGE_NAME, _("Change Name")) Edouard@835: menu.Append(self.TBMENU_CHANGE_INTERFACE, _("Change IP of interface to bind")) Edouard@835: menu.Append(self.TBMENU_CHANGE_PORT, _("Change Port Number")) Edouard@835: menu.Append(self.TBMENU_CHANGE_WD, _("Change working directory")) Edouard@835: menu.AppendSeparator() Edouard@835: menu.Append(self.TBMENU_LIVE_SHELL, _("Launch a live Python shell")) Edouard@835: menu.Append(self.TBMENU_WXINSPECTOR, _("Launch WX GUI inspector")) Edouard@641: menu.AppendSeparator() Edouard@641: menu.Append(self.TBMENU_QUIT, _("Quit")) Edouard@641: return menu Edouard@1434: Edouard@641: def MakeIcon(self, img): Edouard@641: """ Edouard@641: The various platforms have different requirements for the Edouard@641: icon size... Edouard@641: """ Edouard@641: if "wxMSW" in wx.PlatformInfo: Edouard@641: img = img.Scale(16, 16) Edouard@641: elif "wxGTK" in wx.PlatformInfo: Edouard@641: img = img.Scale(22, 22) Edouard@641: # wxMac can be any size upto 128x128, so leave the source img alone.... Edouard@641: icon = wx.IconFromBitmap(img.ConvertToBitmap() ) Edouard@641: return icon Edouard@1434: Edouard@641: def OnTaskBarStartPLC(self, evt): Edouard@1434: if self.pyroserver.plcobj is not None: Edouard@641: self.pyroserver.plcobj.StartPLC() Edouard@1434: Edouard@641: def OnTaskBarStopPLC(self, evt): Edouard@641: if self.pyroserver.plcobj is not None: Edouard@835: Thread(target=self.pyroserver.plcobj.StopPLC).start() Edouard@1434: Edouard@641: def OnTaskBarChangeInterface(self, evt): Edouard@644: dlg = ParamsEntryDialog(None, _("Enter the IP of the interface to bind"), defaultValue=self.pyroserver.ip_addr) Edouard@641: dlg.SetTests([(re.compile('\d{1,3}(?:\.\d{1,3}){3}$').match, _("IP is not valid!")), Edouard@644: ( lambda x :len([x for x in x.split(".") if 0 <= int(x) <= 255]) == 4, _("IP is not valid!")) Edouard@641: ]) Edouard@641: if dlg.ShowModal() == wx.ID_OK: Edouard@644: self.pyroserver.ip_addr = dlg.GetValue() Edouard@641: self.pyroserver.Stop() Edouard@1434: Edouard@641: def OnTaskBarChangePort(self, evt): Edouard@641: dlg = ParamsEntryDialog(None, _("Enter a port number "), defaultValue=str(self.pyroserver.port)) Edouard@641: dlg.SetTests([(UnicodeType.isdigit, _("Port number must be an integer!")), (lambda port : 0 <= int(port) <= 65535 , _("Port number must be 0 <= port <= 65535!"))]) Edouard@641: if dlg.ShowModal() == wx.ID_OK: Edouard@641: self.pyroserver.port = int(dlg.GetValue()) Edouard@641: self.pyroserver.Stop() Edouard@1434: Edouard@641: def OnTaskBarChangeWorkingDir(self, evt): Edouard@641: dlg = wx.DirDialog(None, _("Choose a working directory "), self.pyroserver.workdir, wx.DD_NEW_DIR_BUTTON) Edouard@641: if dlg.ShowModal() == wx.ID_OK: Edouard@641: self.pyroserver.workdir = dlg.GetPath() Edouard@641: self.pyroserver.Stop() Edouard@1434: Edouard@641: def OnTaskBarChangeName(self, evt): Edouard@641: dlg = ParamsEntryDialog(None, _("Enter a name "), defaultValue=self.pyroserver.name) Edouard@641: dlg.SetTests([(lambda name : len(name) is not 0 , _("Name must not be null!"))]) Edouard@641: if dlg.ShowModal() == wx.ID_OK: Edouard@641: self.pyroserver.name = dlg.GetValue() Edouard@641: self.pyroserver.Restart() Edouard@1434: Edouard@959: def _LiveShellLocals(self): Edouard@959: if self.pyroserver.plcobj is not None: Edouard@1049: return {"locals":self.pyroserver.plcobj.python_runtime_vars} Edouard@959: else: Edouard@959: return {} Edouard@1434: Edouard@641: def OnTaskBarLiveShell(self, evt): Edouard@959: from wx import py Edouard@959: frame = py.crust.CrustFrame(**self._LiveShellLocals()) Edouard@959: frame.Show() Edouard@1434: Edouard@641: def OnTaskBarWXInspector(self, evt): Edouard@641: # Activate the widget inspection tool Edouard@641: from wx.lib.inspection import InspectionTool Edouard@641: if not InspectionTool().initialized: Edouard@959: InspectionTool().Init(**self._LiveShellLocals()) Edouard@959: Edouard@959: wnd = wx.GetApp() Edouard@641: InspectionTool().Show(wnd, True) Edouard@1434: Edouard@641: def OnTaskBarQuit(self, evt): Laurent@1121: if wx.Platform == '__WXMSW__': Laurent@1121: Thread(target=self.pyroserver.Quit).start() Edouard@641: self.RemoveIcon() Laurent@1121: wx.CallAfter(wx.GetApp().ExitMainLoop) Edouard@1434: Edouard@641: def UpdateIcon(self, plcstatus): Edouard@641: if plcstatus is "Started" : Edouard@1067: currenticon = self.MakeIcon(starticon) Edouard@641: elif plcstatus is "Stopped": Edouard@1067: currenticon = self.MakeIcon(stopicon) Edouard@641: else: Edouard@1067: currenticon = self.MakeIcon(defaulticon) Edouard@641: self.SetIcon(currenticon, "Beremiz Service") Edouard@641: Edouard@641: from runtime import PLCObject, PLCprint, ServicePublisher Edouard@641: import Pyro.core as pyro Edouard@641: Edouard@641: if not os.path.isdir(WorkingDir): Edouard@641: os.mkdir(WorkingDir) Edouard@641: Edouard@867: def default_evaluator(tocall, *args, **kwargs): Edouard@867: try: Edouard@867: res=(tocall(*args,**kwargs), None) Edouard@1051: except Exception: Edouard@1051: res=(None, sys.exc_info()) Edouard@867: return res Edouard@641: Edouard@641: class Server(): Edouard@1438: def __init__(self, servicename, ip_addr, port, Edouard@1438: workdir, argv, autostart=False, Edouard@1438: statuschange=None, evaluator=default_evaluator, Edouard@1438: website=None): Edouard@641: self.continueloop = True Edouard@641: self.daemon = None Edouard@641: self.servicename = servicename Edouard@644: self.ip_addr = ip_addr Edouard@641: self.port = port Edouard@641: self.workdir = workdir Edouard@641: self.argv = argv Edouard@641: self.plcobj = None Edouard@641: self.servicepublisher = None Edouard@641: self.autostart = autostart Edouard@641: self.statuschange = statuschange Edouard@641: self.evaluator = evaluator Edouard@641: self.website = website Edouard@1434: Edouard@641: def Loop(self): Edouard@641: while self.continueloop: Edouard@641: self.Start() Edouard@1434: Edouard@641: def Restart(self): Edouard@641: self.Stop() Edouard@641: Edouard@641: def Quit(self): Edouard@641: self.continueloop = False Edouard@1045: if self.plcobj is not None: Edouard@1045: self.plcobj.UnLoadPLC() Edouard@641: self.Stop() Edouard@641: Edouard@641: def Start(self): Edouard@641: pyro.initServer() Edouard@644: self.daemon=pyro.Daemon(host=self.ip_addr, port=self.port) Edouard@1438: self.plcobj = PLCObject(self.workdir, self.daemon, self.argv, Edouard@1438: self.statuschange, self.evaluator, Edouard@1438: self.website) Edouard@641: uri = self.daemon.connect(self.plcobj,"PLCObject") Edouard@1434: Edouard@641: print "Pyro port :",self.port Edouard@641: print "Pyro object's uri :",uri Edouard@641: print "Current working directory :",self.workdir Edouard@1434: Edouard@641: # Configure and publish service Edouard@641: # Not publish service if localhost in address params Edouard@1434: if (self.servicename is not None and Edouard@1434: self.ip_addr is not None and Edouard@1434: self.ip_addr != "localhost" and Edouard@648: self.ip_addr != "127.0.0.1"): Edouard@641: print "Publishing service on local network" Edouard@641: self.servicepublisher = ServicePublisher.ServicePublisher() Edouard@644: self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port) Edouard@1434: Laurent@1034: if self.autostart and self.plcobj.GetPLCstatus()[0] != "Empty": Edouard@641: self.plcobj.StartPLC() Edouard@1434: Edouard@641: sys.stdout.flush() Edouard@1434: Edouard@641: self.daemon.requestLoop() Edouard@1434: Edouard@641: def Stop(self): Edouard@1045: if self.plcobj is not None: Edouard@1045: self.plcobj.StopPLC() Edouard@641: if self.servicepublisher is not None: Edouard@641: self.servicepublisher.UnRegisterService() Edouard@641: self.servicepublisher = None Edouard@641: self.daemon.shutdown(True) Edouard@641: Edouard@641: if enabletwisted: Edouard@641: import warnings Edouard@641: with warnings.catch_warnings(): Edouard@641: warnings.simplefilter("ignore") Edouard@641: try: Edouard@641: from threading import Thread, currentThread Edouard@641: if havewx: Edouard@641: from twisted.internet import wxreactor Edouard@641: wxreactor.install() Edouard@1438: from twisted.internet import reactor Edouard@1434: Edouard@641: havetwisted = True Edouard@641: except: Edouard@1438: print "Twisted unavailable." Edouard@641: havetwisted = False Edouard@641: Edouard@1438: pyruntimevars = {} Edouard@1438: statuschange = [] Edouard@1438: registerserverto = [] Edouard@1438: Edouard@641: if havetwisted: Edouard@1434: Edouard@641: if havewx: Edouard@641: reactor.registerWxApp(app) Edouard@1438: Edouard@1438: # TODO add command line switch Edouard@1438: try: Edouard@1438: import runtime.NevowServer as NS Edouard@1438: website = NS.RegisterWebsite(reactor) Edouard@1438: pyruntimevars["website"] = website Edouard@1438: statuschange.append(NS.website_statuslistener_factory(website)) Edouard@1438: except: Edouard@1438: print "Nevow Web service failed." Edouard@1438: Edouard@641: Edouard@641: if havewx: Edouard@641: from threading import Semaphore Edouard@641: wx_eval_lock = Semaphore(0) Edouard@867: main_thread = currentThread() Edouard@835: Edouard@1438: def statuschangeTskBar(status): Edouard@641: wx.CallAfter(taskbar_instance.UpdateIcon,status) Edouard@1434: Edouard@1438: statuschange.append(statuschangeTskBar) Edouard@1438: Edouard@867: def wx_evaluator(obj, *args, **kwargs): Edouard@867: tocall,args,kwargs = obj.call Edouard@867: obj.res = default_evaluator(tocall, *args, **kwargs) Edouard@867: wx_eval_lock.release() Edouard@1434: Edouard@867: def evaluator(tocall, *args, **kwargs): Edouard@867: global main_thread Edouard@867: if(main_thread == currentThread()): Edouard@1434: # avoid dead lock if called from the wx mainloop Edouard@867: return default_evaluator(tocall, *args, **kwargs) Edouard@641: else: Edouard@867: o=type('',(object,),dict(call=(tocall, args, kwargs), res=None)) Edouard@867: wx.CallAfter(wx_evaluator,o) Edouard@641: wx_eval_lock.acquire() Edouard@867: return o.res Edouard@1434: Edouard@1438: pyroserver = Server(servicename, given_ip, port, Edouard@1438: WorkingDir, argv, autostart, Edouard@1438: statuschange, evaluator, pyruntimevars) Edouard@1438: Edouard@835: taskbar_instance = BeremizTaskBarIcon(pyroserver, enablewx) Edouard@641: else: Edouard@1438: pyroserver = Server(servicename, given_ip, port, Edouard@1438: WorkingDir, argv, autostart, Edouard@1438: statuschange, pyruntimevars=pyruntimevars) Edouard@1438: Edouard@1438: for registrar in registerserverto : Edouard@1438: registrar(pyroserver) Edouard@641: Edouard@1067: # Exception hooks s Edouard@1067: import threading, traceback Edouard@1067: def LogException(*exp): Edouard@1067: if pyroserver.plcobj is not None: Edouard@1067: pyroserver.plcobj.LogMessage(0,'\n'.join(traceback.format_exception(*exp))) Edouard@1067: else: Laurent@1270: traceback.print_exception(*exp) Edouard@1067: Edouard@1067: sys.excepthook = LogException Edouard@1067: def installThreadExcepthook(): Edouard@1067: init_old = threading.Thread.__init__ Edouard@1067: def init(self, *args, **kwargs): Edouard@1067: init_old(self, *args, **kwargs) Edouard@1067: run_old = self.run Edouard@1067: def run_with_except_hook(*args, **kw): Edouard@1067: try: Edouard@1067: run_old(*args, **kw) Edouard@1067: except (KeyboardInterrupt, SystemExit): Edouard@1067: raise Edouard@1067: except: Edouard@1067: sys.excepthook(*sys.exc_info()) Edouard@1067: self.run = run_with_except_hook Edouard@1067: threading.Thread.__init__ = init Edouard@1067: installThreadExcepthook() Edouard@1067: Edouard@1437: # Load extensions Edouard@1437: for extfilename in extensions: Edouard@1437: extension_folder = os.path.split(os.path.realpath(extfilename))[0] Edouard@1437: sys.path.append(extension_folder) Edouard@1437: execfile(extfilename, locals()) Edouard@1437: Edouard@641: if havetwisted or havewx: Edouard@641: pyro_thread=Thread(target=pyroserver.Loop) Edouard@641: pyro_thread.start() Edouard@641: Edouard@641: if havetwisted: Edouard@641: reactor.run() Edouard@641: elif havewx: Edouard@641: app.MainLoop() Edouard@641: else: Edouard@641: try : Edouard@641: pyroserver.Loop() Edouard@641: except KeyboardInterrupt,e: Edouard@641: pass Edouard@641: pyroserver.Quit() Edouard@641: sys.exit(0)