Exemple #1
0
    def _load_update(self, version):
        """Load a single update file"""

        log.info("Upgrading to DB schema version %s" % version)

        update = "%s/schema/%03d.sql" % (self._dir, version)
        self._load_sql(update)
        self._set_version(version)
Exemple #2
0
    def _load_update(self, version):
        """Load a single update file"""

        log.info("Upgrading to DB schema version %s" % version)

        update = "%s/schema/%03d.sql" % (self._dir, version)
        self._load_sql(update)
        self._set_version(version)
Exemple #3
0
 def clientConnectionLost(self, connector, reason):
     addr = connector.getDestination()
     if isinstance(reason.value, error.ConnectionDone):
         log.info("Connection to %s:%s closed" % (addr.host, addr.port))
     else:
         log.warn("Connection to %s:%s lost: %s" %
                 (addr.host, addr.port, reason.value), prefix=self.logstr)
     self._connection = None
     self._reconnect()
Exemple #4
0
 def clientConnectionLost(self, connector, reason):
     addr = connector.getDestination()
     if isinstance(reason.value, error.ConnectionDone):
         log.info("Connection to %s:%s closed" % (addr.host, addr.port))
     else:
         log.warn("Connection to %s:%s lost: %s" %
                  (addr.host, addr.port, reason.value),
                  prefix=self.logstr)
     self._connection = None
     self._reconnect()
Exemple #5
0
    def joined(self, channel):
        log.info("Joined %s" % channel)
        self.channels[channel] = {'users': set(), 'topic': ""}

        event = {
            'type': 'join',
            'user': self.nickname,
            'reply_to': channel,
            'channel': channel,
            'time': time.time()
        }

        self.manager.plugins.hook(self, event)
Exemple #6
0
    def nickChanged(self, nick):
        log.info("Nick changed to: %s" % nick)
        old = self.nickname
        self.nickname = nick

        event = {
            'type': 'rename',
            'old': old,
            'new': nick,
            'time': time.time()
        }

        self.manager.plugins.hook(self, event)
Exemple #7
0
    def upgrade(self):
        required = self.required_schema()
        current = self.current_schema()

        if (current < 0):
            # Empty DB!
            current = self._load_schema(required)
        else:
            log.info("Current DB version: %s" % current)

        while current < required:
            current += 1
            self._load_update(current)
Exemple #8
0
    def joined(self, channel):
        log.info("Joined %s" % channel)
        self.channels[channel] = {'users': set(), 'topic': ""}

        event = {
                'type': 'join',
                'user': self.nickname,
                'reply_to': channel,
                'channel': channel,
                'time': time.time()
                }

        self.manager.plugins.hook(self, event)
Exemple #9
0
    def upgrade(self):
        required = self.required_schema()
        current = self.current_schema()

        if (current < 0):
            # Empty DB!
            current = self._load_schema(required)
        else:
            log.info("Current DB version: %s" % current)

        while current < required:
            current += 1
            self._load_update(current)
Exemple #10
0
    def nickChanged(self, nick):
        log.info("Nick changed to: %s" % nick)
        old = self.nickname
        self.nickname = nick

        event = {
                'type': 'rename',
                'old': old,
                'new': nick,
                'time': time.time()
                }

        self.manager.plugins.hook(self, event)
Exemple #11
0
    def disconnect(self, message=''):
        """Disconnect all configured networks"""

        self._exit_deferred = d = defer.Deferred()

        log.info("Quitting with message '%s'" % message)
        remote_d = self._remote.disconnect()
        for net in self._networks.itervalues():
            net.disconnect(message)

        d.addCallback(lambda _: remote_d)
        d.addCallback(lambda _: self.plugins.wait())
        return d
Exemple #12
0
    def disconnect(self, message=''):
        """Disconnect all configured networks"""

        self._exit_deferred = d = defer.Deferred()

        log.info("Quitting with message '%s'" % message)
        remote_d = self._remote.disconnect()
        for net in self._networks.itervalues():
            net.disconnect(message)

        d.addCallback(lambda _: remote_d)
        d.addCallback(lambda _: self.plugins.wait())
        return d
Exemple #13
0
    def left(self, channel):
        log.info("Left %s" % channel)
        del self.channels[channel]

        event = {
                'type': 'part',
                'user': self.nickname,
                'reply_to': channel,
                'channel': channel,
                'text': "",
                'time': time.time()
                }

        self.manager.plugins.hook(self, event)
Exemple #14
0
    def left(self, channel):
        log.info("Left %s" % channel)
        del self.channels[channel]

        event = {
            'type': 'part',
            'user': self.nickname,
            'reply_to': channel,
            'channel': channel,
            'text': "",
            'time': time.time()
        }

        self.manager.plugins.hook(self, event)
Exemple #15
0
    def kickedFrom(self, channel, kicker, msg):
        log.info("Kicked from %s by %s: %s" % (channel, nick(kicker), msg))
        del self.channels[channel]

        event = {
                'type': 'kick',
                'kicker': kicker,
                'kickee': self.nickname,
                'reply_to': channel,
                'channel': channel,
                'text': msg,
                'time': time.time()
                }

        self.manager.plugins.hook(self, event)
Exemple #16
0
    def kickedFrom(self, channel, kicker, msg):
        log.info("Kicked from %s by %s: %s" % (channel, nick(kicker), msg))
        del self.channels[channel]

        event = {
            'type': 'kick',
            'kicker': kicker,
            'kickee': self.nickname,
            'reply_to': channel,
            'channel': channel,
            'text': msg,
            'time': time.time()
        }

        self.manager.plugins.hook(self, event)
Exemple #17
0
def ConnectionPool(config):
    """Factory function to check/upgrade schema and return a pool"""

    args = _db_args(config)
    if args is None:
        log.info("No database configured.")
        return

    upgrader = SchemaManager(config)
    upgrader.upgrade()
    upgrader.close()

    # Everything is in order, setup the pool for all to use.
    return adbapi.ConnectionPool("MySQLdb", cp_noisy=False,
            cp_reconnect=True, cp_openfun=_connected, **args)
Exemple #18
0
def ConnectionPool(config):
    """Factory function to check/upgrade schema and return a pool"""

    args = _db_args(config)
    if args is None:
        log.info("No database configured.")
        return

    upgrader = SchemaManager(config)
    upgrader.upgrade()
    upgrader.close()

    # Everything is in order, setup the pool for all to use.
    return adbapi.ConnectionPool("MySQLdb",
                                 cp_noisy=False,
                                 cp_reconnect=True,
                                 cp_openfun=_connected,
                                 **args)
Exemple #19
0
    def signedOn(self):
        log.info("Signed On!")
        self.factory.clientConnected(self)

        for automsg in self.factory.config.findall('automsg'):
            to = automsg.get('to', None)
            msg = automsg.get('msg', None)

            if to and msg:
                self.msg(to, msg)
            else:
                log.error("Invalid automsg: %s" % ElementTree.tostring(automsg))

        for autojoin in self.factory.config.findall('autojoin'):
            chan = autojoin.get('chan', None)
            password = autojoin.get('password', None)

            if chan:
                self.join(chan, password)
            else:
                log.error("Invalid autojoin: %s" % ElementTree.tostring(autojoin))
Exemple #20
0
    def connectionMade(self):
        # Hack to auto magically set the log prefix based on network
        # name rather than class name
        self.transport.logstr = self.factory.logstr

        log.info("Connected!", prefix=self.factory.logstr)

        # Used by IRCClient
        self.nickname = self.factory.nickname
        self.username = self.factory.username
        self.realname = self.factory.realname
        self.password = self.factory.password

        # Used to track channel information
        self.channels = {}

        # Used by plugins to access global info
        self.manager = self.factory.manager
        self.network = self.factory

        irc.IRCClient.connectionMade(self)
Exemple #21
0
    def connectionMade(self):
        # Hack to auto magically set the log prefix based on network
        # name rather than class name
        self.transport.logstr = self.factory.logstr

        log.info("Connected!", prefix=self.factory.logstr)

        # Used by IRCClient
        self.nickname = self.factory.nickname
        self.username = self.factory.username
        self.realname = self.factory.realname
        self.password = self.factory.password

        # Used to track channel information
        self.channels = {}

        # Used by plugins to access global info
        self.manager = self.factory.manager
        self.network = self.factory

        irc.IRCClient.connectionMade(self)
Exemple #22
0
    def _load_schema(self, required):
        """Load the latest available schema version"""

        dump = "%s/schema-%03d.sql" % (self._dir, required)
        if not os.path.exists(dump):
            dumps = glob.glob("%s/schema-???.sql" % self._dir)
            if not dumps:
                raise DBError("No schema files found in %s" % self._dir)

            dumps.sort()
            dump = dumps[-1]

            # Goofy way of grabbing the ??? out of the above glob
            version = int(dump[-7:-4])
            assert version <= required
        else:
            version = required

        log.info("Loading DB schema version %s" % version)

        self._load_sql(dump)
        self._set_version(version)
        return version
Exemple #23
0
    def _load_schema(self, required):
        """Load the latest available schema version"""

        dump = "%s/schema-%03d.sql" % (self._dir, required)
        if not os.path.exists(dump):
            dumps = glob.glob("%s/schema-???.sql" % self._dir)
            if not dumps:
                raise DBError("No schema files found in %s" % self._dir)

            dumps.sort()
            dump = dumps[-1]

            # Goofy way of grabbing the ??? out of the above glob
            version = int(dump[-7:-4])
            assert version <= required
        else:
            version = required

        log.info("Loading DB schema version %s" % version)

        self._load_sql(dump)
        self._set_version(version)
        return version
Exemple #24
0
    def signedOn(self):
        log.info("Signed On!")
        self.factory.clientConnected(self)

        for automsg in self.factory.config.findall('automsg'):
            to = automsg.get('to', None)
            msg = automsg.get('msg', None)

            if to and msg:
                self.msg(to, msg)
            else:
                log.error("Invalid automsg: %s" %
                          ElementTree.tostring(automsg))

        for autojoin in self.factory.config.findall('autojoin'):
            chan = autojoin.get('chan', None)
            password = autojoin.get('password', None)

            if chan:
                self.join(chan, password)
            else:
                log.error("Invalid autojoin: %s" %
                          ElementTree.tostring(autojoin))
Exemple #25
0
 def startedConnecting(self, connector):
     addr = connector.getDestination()
     log.info("Connecting to %s:%s..." % (addr.host, addr.port),
              prefix=self.logstr)
Exemple #26
0
 def startedConnecting(self, connector):
     addr = connector.getDestination()
     log.info("Connecting to %s:%s..." % (addr.host, addr.port),
             prefix=self.logstr)