예제 #1
0
 def loadAllModules(self):
     requestedModules = self.bot.config.itemWithDefault("modules", [])
     for module in getPlugins(IBotModule, heufybot.modules):
         if module.name in self.loadedModules:
             continue
         if module.core or module.name in requestedModules:
             self._loadModuleData(module)
     for module in requestedModules:
         if module not in self.loadedModules:
             log.msg("Module {} failed to load.".format(module), level=logging.ERROR)
 def connectionMade(self):
   """When a server connection is made, connect to the remote server."""
   destination = self.options["destination"]
   destinationPort = self.options["destination_port"]
   log.msg("Connecting to %s:%d" % (destination, destinationPort))
   factory = LineProxyClientFactory(self)
   if self.options["ssl"]:
     sslFactory = ssl.ClientContextFactory()
     sslFactory.method = ssl.SSL.TLSv1_METHOD
     reactor.connectSSL(destination,
                        destinationPort,
                        factory,
                        sslFactory)
   else:
     reactor.connectTCP(destination,
                        destinationPort,
                        factory)
    def lineReceived(self, line):
        log.msg("Received line: %s" % line)

        try:
            stats = json.loads(line)

            for stat, value in stats.items():
                if not buffers.__contains__(stat):
                    # TODO: Make this value configurable
                    buffers[stat] = CircularBuffer(10)

                buffers[stat].put(DataPoint(value)) 

        except JSONDecodeError:
            log.msg("Huh?")

        log.msg("Current buffers:")
        for name, buf in buffers.items():
            log.msg("%s: %r" % (name, buf.buffer))
    def lineReceived(self, line):
        log.msg("Received line: %s" % line)
        
        try:
            timestamp = float(line)
        except ValueError:
            log.msg("Bad timestamp")
            # TODO: Respond with an error

        data = {}
        
        for name, datapoints in buffers.items():
            log.msg("Name: %s Datapoints: %r" % (name, datapoints))
            data[name] = [ (dp.timestamp , dp.data)
                                for dp in datapoints.buffer
                                if dp is not None
                                    and dp.timestamp > timestamp ]

        self.sendLine(json.dumps(data))
 def lineReceived(self, line):
   """Forwards lines from the remote connection to the incoming connection."""
   log.msg("S: %s" % line)
   self.factory.server.sendLine(line)
 def connectionMade(self):
   """Called when the connection to the remote server is complete."""
   log.msg("Connection to client made")
   self.factory.server.setClient(self)
 def lineReceived(self, line):
   """Incoming lines are forwarded to the remote server."""
   log.msg("C: %s" % line)
   self.client.sendLine(line)
 def connectionLost(self, _):
     log.msg("Connection lost")
     self.transport.loseConnection()
 def connectionMade(self):
     log.msg("There's been a connection")