# vim: ts=4 et sts=4 sw=4 autoindent import Pyro.core import Pyro.naming from Pyro.errors import NamingError from sndcs.server.EmployeeProxy import EmployeeProxyFactory from sndcs.server.LaborHedProxy import LaborHedProxyFactory from sndcs.server.LaborDtlProxy import LaborDtlProxyFactory from sndcs.server.OperationProxy import OperationProxyFactory from sndcs.server.IndirectProxy import IndirectProxyFactory from sndcs.server.TerminalProxy import TerminalProxyFactory from sndcs.server.DCSServerProxy import DCSServerProxy from sndcs.server.ScrapCodeProxy import ScrapCodeProxyFactory from sndcs.Config import config import sndcs_common from sndcs_common.PyroProxyMixin import PyroProxyMixin from sndcs_common.Logger import logger log = logger.getLogger("sndcsd") class SndcsServer(PyroProxyMixin): def start(self): log.info("Launching %s %s Server", sndcs_common.NAME, sndcs_common.VERSION) # Get the Pyro namespace from the config self.namespace = config.get("pyro", "namespace", "sndcs") log.info("Using Pyro namespace '%s'", self.namespace) Pyro.core.initServer(banner=0) self.ns=Pyro.naming.NameServerLocator().getNS() hostname = config.get("pyro", "hostname", "") self.daemon=Pyro.core.Daemon(host=hostname) self.daemon.useNameServer(self.ns) # There is always a chance of orphaning proxy objects if the client get # closed without the proper disconnect getting called. Because of that # we will set an extremely long cleanup time so we don't accidentally # disconnect an employee proxy (if an employee selected themselves and # left the screen sit for a couple of days then it will throw an # exception because the proxy object was reaped.) self.cleanupAge = 60 * 60 * 24 * 2 # 2 days self.daemon.setTransientsCleanupAge(self.cleanupAge) # Create the sndcs group if it doesn't already exist try: self.ns.createGroup(self.formatNamespace(self.namespace)) except NamingError: # Must already exist pass # In case our object names already exist we will unregister them try: self.ns.unregister(self.formatObjectString(self.namespace, ["Employee"])) except NamingError: pass self.daemon.connect(EmployeeProxyFactory(), self.formatObjectString(self.namespace, ["Employee"])) try: self.ns.unregister(self.formatObjectString(self.namespace, ["LaborHed"])) except NamingError: pass self.daemon.connect(LaborHedProxyFactory(), self.formatObjectString(self.namespace, ["LaborHed"])) try: self.ns.unregister(self.formatObjectString(self.namespace, ["LaborDtl"])) except NamingError: pass self.daemon.connect(LaborDtlProxyFactory(), self.formatObjectString(self.namespace, ["LaborDtl"])) try: self.ns.unregister(self.formatObjectString(self.namespace, ["Operation"])) except NamingError: pass self.daemon.connect(OperationProxyFactory(), self.formatObjectString(self.namespace, ["Operation"])) try: self.ns.unregister(self.formatObjectString(self.namespace, ["Indirect"])) except NamingError: pass self.daemon.connect(IndirectProxyFactory(), self.formatObjectString(self.namespace, ["Indirect"])) try: self.ns.unregister(self.formatObjectString(self.namespace, ["Terminal"])) except NamingError: pass self.daemon.connect(TerminalProxyFactory(), self.formatObjectString(self.namespace, ["Terminal"])) try: self.ns.unregister(self.formatObjectString(self.namespace, ["DCSServer"])) except NamingError: pass self.daemon.connect(DCSServerProxy(), self.formatObjectString(self.namespace, ["DCSServer"])) try: self.ns.unregister(self.formatObjectString(self.namespace, ["ScrapCode"])) except NamingError: pass self.daemon.connect(ScrapCodeProxyFactory(), self.formatObjectString(self.namespace, ["ScrapCode"])) self.daemon.requestLoop()