def __init__(self): super(IrcSQLRessourceManager, self).__init__() self.services = IrcServices() self.request = self.services.getModel() self.docked = list() self.spawnRequest= dict() for server in self.request: self.docked.append(server.emptyClone())
class IrcSQLRessourceManager(IrcRessourceManager): def __init__(self): super(IrcSQLRessourceManager, self).__init__() self.services = IrcServices() self.request = self.services.getModel() self.docked = list() self.spawnRequest= dict() for server in self.request: self.docked.append(server.emptyClone()) def addDockedChannel(self, channel, host): super(IrcSQLRessourceManager, self).addDockedChannel(channel, host) self.services.setChanStatus(channel) def addRequestChannel(self, channel, host): channel.bot = "offline" super(IrcSQLRessourceManager, self).addRequestChannel(channel, host) self.services.setChanStatus(channel) def addSpawnRequest(self, agentname, server): if not self.spawnRequest.has_key(getComputername(agentname)): self.spawnRequest[getComputername(agentname)] = list() if not server in self.spawnRequest[getComputername(agentname)]: self.spawnRequest[getComputername(agentname)].append(server) self.sendTo(agentname,SpawnEvent(brain='remote.protocols.irc.brain.IrcBrainClient')) def hasSpawnRequest(self, agentname): if not self.spawnRequest.has_key(getComputername(agentname)): return False else: if len(self.spawnRequest[getComputername(agentname)]) == 0: return False return True def getSpawnRequest(self,agentname): return self.spawnRequest[getComputername(agentname)].pop() def requestNewAgent(self, allowed, server): if len(allowed) == 0: return from random import Random rnd = Random() agentname = allowed[rnd.randint(0, len(allowed)-1)] self.addSpawnRequest(agentname, server) def getRootAgents(self): try: return self.getContext().getBean('RegistryBrain').getHostList() except: return list() def onClientInit(self, eventObj, evtMgr): source = eventObj.source print "SPAWNNN: "+str(self.spawnRequest) if self.hasSpawnRequest(source): server = self.getSpawnRequest(source) if server=="irc.worldnet.net" and getComputername(source)=='oil-ocean': self.sendTo(source, ConnectEventAction(nickname="scrutator", server="irc.worldnet.net", port=6667)) else: self.sendTo(source, ConnectEventAction(nickname=getNickName(), server=server, port=6667)) agent = Agent() agent.name = source agent.server = server self.onRegisterAgent(agent) else: print "DIE !!!" self.sendTo(source, DieEvent()) #self.sendTo(source, JoinActionEvent(channel="#funradio")) #self.sendTo(source, JoinActionEvent(channel="#cochonne")) #self.sendTo(source, JoinActionEvent(channel="#scrutator")) def hasRunnningAgentsWithName(self, name): for agent in self.getRunnningAgents(): if agent.name == name: return True return False def manageChannel(self): log.msg("Manage Channel") for server in self.request: log.msg("--> server "+server.host) for channel in server.getChannels(): log.msg("---> channel "+channel.name) agent = self.bestAgentFor(channel, server.host) if agent != None: self.sendTo(agent.name, JoinActionEvent(channel=channel.name)) #garbage collector chan for server in self.docked: for channel in server.getChannels(): #print "bot name "+channel.bot #print "runnin" +str(self.getRunnningAgents()) notfound = True if not self.hasRunnningAgentsWithName(channel.bot): log.msg("Garbage collector chan "+channel.name) self.addRequestChannel(channel, server.host) print self.spawnRequest
''' Created on 27 Nov 2009 @author: wax ''' from remote.protocols.irc.services import IrcServices def display(l): for line in l: print line if __name__ == '__main__': serv = IrcServices() for server in serv.getModel(): print server.host for chan in server.getChannels(): print "*** "+chan.name #d.addCallback(display) #reactor.run()