Subversion Repositories Scribus


Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

# Copyright (c) 2007, Oleksandr Moskalenko
# All rights reserved.
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <>.
import svnxmlparser

import threading
import time

from supybot.commands import *
import supybot.conf as conf
import supybot.utils as utils
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.ircmsgs as ircmsgs
import supybot.registry as registry
import supybot.callbacks as callbacks

class Svnwatch(callbacks.Plugin):
    """Main class of the plugin."""
    threaded = True
    def __init__(self, irc):
        self.__parent = super(Svnwatch, self)
            self.xmluri = self.registryValue('xmluri')
            self.wait = self.registryValue('fetchPeriod')
            self.postfrequency = self.registryValue('postFrequency')
            self.channels = self.registryValue('channels')
            self.lastrev = self.registryValue('lastRevision')
            self.lastfetch = time.time() - self.wait - 1
            self.log.debug("%s; %s, %s, %s, %s" % (self.xmluri, self.wait, self.postfrequency, self.channels, self.lastrev))
        except registry.NonExistentRegistryEntry:
            self.log.debug('%s is not a registered URI.', self.xmluri)
            irc.error('Can\'t get configuration variables.', Raise=True)

    def canGetNewCommit(self, irc):
        """Checks if more then fetchPeriod time lapsed since our last fetch.
        Returns True is that's the case and False if we need to wait longer.""" = time.time()
        self.log.debug("Current time: %s; Last fetch: %s; Difference: %d sec" % (, self.lastfetch, int( - self.lastfetch)))
        if - self.lastfetch > self.wait:
            self.log.debug("Enough time passed, fetching new commit...")
            return True
            self.log.debug("Not enough time passed, standing by...")
            return False

    def getHead(self, xmluri):
        """Fetches the head revision number for internal processing. Returns 'HEAD'
        in case of error or misconfiguration."""

        self.xmluri = xmluri
        self.rev = "HEAD"
        self.rawxml = svnxmlparser.fetchXml(self.xmluri, self.rev)
        self.commitdata = svnxmlparser.getCommit(self.rawxml)
        if self.commitdata == None:
  "Cannot fetch revision %s" % (self.rev))
#            raise "Cannot fetch head revision id"
            return None
            return self.commitdata.keys()[0]

    def getCommit(self, irc):
        self.channels = self.registryValue('channels')
        self.log.debug("Reporting channels: %s", self.channels)
        self.lastrev = self.registryValue('lastRevision')
#        if self.canGetNewCommit(irc):
            self.log.debug('Fetching HEAD revision number from %s', self.xmluri)
            self.headid = self.getHead(self.xmluri)
            self.log.debug('Current HEAD revision number: %s', self.headid)
            if self.headid == None:
                self.log.debug('Error occured while fetching HEAD revision from %s', self.xmluri)
       = time.time()
                self.lastfetch =
                self.log.debug("Failed to fetch 'HEAD' at %s" % (
            elif int(self.headid) == self.lastrev:
                self.log.debug("Fetched 'HEAD' - no new commmits at %s", self.xmluri)
       = time.time()
                self.lastfetch =
                self.log.debug("Fetched new 'HEAD' revision at %s" % (
                self.oldestnewrev = self.lastrev + 1
                self.revid = "%s:HEAD" % self.oldestnewrev
                self.revuri = self.xmluri + "?" + self.revid
                self.log.debug("Fetching new commit(s) for %s" % self.revuri)
                self.rawxml = svnxmlparser.fetchXml(self.xmluri, self.revid)
                self.log.debug("Fetched xml %s" % self.rawxml)
                self.resultcommitdata = svnxmlparser.getCommit(self.rawxml)
                self.log.debug("Fetched data %s" % self.resultcommitdata)
                self.shortdata = svnxmlparser.shortoutput(self.resultcommitdata)
                self.log.debug("Short data: %s" % self.shortdata)
                if len(self.shortdata) == 1:
                    self.revisiondata = " ".join(self.shortdata)
                    self.log.debug("Formatted data: %s" % self.revisiondata)
                    self.lastrev = int(self.revisiondata.split(" ")[1])
                    self.log.debug("Revision ID: %s" % self.lastrev)
                    for in self.channels:
                        irc.replies(self.revisiondata, joiner='',, prefixNick=False, private=True)
                    for self.revisiondata in self.shortdata:
                        self.log.debug("Revision data: %s" % self.revisiondata)
                        self.lastrev = int(self.revisiondata.split(" ")[1])
                        self.log.debug("Last revision ID: %s" % self.lastrev)
                        for in self.channels:
                            irc.replies(self.revisiondata, joiner='',, prefixNick=False, private=True)
       = time.time()
                self.lastfetch =
                self.log.debug("Fetched new commit(s) up to revision %s at %s"
                        % (self.lastrev,

    def __call__(self, irc, msg):
        self.__parent.__call__(irc, msg)
        irc = callbacks.SimpleProxy(irc, msg)
        if self.canGetNewCommit(irc):
            self.log.debug("Invoking __call__")

Class = Svnwatch

# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: