summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Ullmann <jokey@gentoo.org>2006-10-09 09:07:27 +0000
committerMarkus Ullmann <jokey@gentoo.org>2006-10-09 09:07:27 +0000
commit4691fee52a32d47299d75f21756f7c6bc9824305 (patch)
tree9a194d5bbc6b1eb63a1530b4510c4ac4c6d2792a /scripts
parentsys-apps/moreutils: Actually remove older versions. (diff)
downloadsunrise-4691fee52a32d47299d75f21756f7c6bc9824305.tar.gz
sunrise-4691fee52a32d47299d75f21756f7c6bc9824305.tar.bz2
sunrise-4691fee52a32d47299d75f21756f7c6bc9824305.zip
Adding out CommitAnnouncer plugin
svn path=/sunrise/; revision=1490
Diffstat (limited to 'scripts')
-rw-r--r--scripts/supybot-SunriseCIA-plugin/SunriseCIAParser.py173
-rw-r--r--scripts/supybot-SunriseCIA-plugin/__init__.py66
-rw-r--r--scripts/supybot-SunriseCIA-plugin/config.py49
-rw-r--r--scripts/supybot-SunriseCIA-plugin/plugin.py111
-rw-r--r--scripts/supybot-SunriseCIA-plugin/test.py36
5 files changed, 435 insertions, 0 deletions
diff --git a/scripts/supybot-SunriseCIA-plugin/SunriseCIAParser.py b/scripts/supybot-SunriseCIA-plugin/SunriseCIAParser.py
new file mode 100644
index 000000000..678817265
--- /dev/null
+++ b/scripts/supybot-SunriseCIA-plugin/SunriseCIAParser.py
@@ -0,0 +1,173 @@
+import sys
+import libxml2
+# import time
+# from pprint import pprint
+
+class callback:
+ def __init__(self):
+ self.inRevision = 0
+ self.inAuthor = 0
+ self.inLog = 0
+ self.inFile = 0
+ self.filelist = []
+ self.author = ""
+ self.revision = ""
+ self.logmessage = ""
+
+ def startElement(self, tag, attrs):
+ if tag == "revision":
+ self.buffer = ""
+ self.inRevision = 1
+ if tag == "author":
+ self.buffer = ""
+ self.inAuthor = 1
+ if tag == "log":
+ self.buffer = ""
+ self.inLog = 1
+ if tag == "file":
+ self.buffer = ""
+ self.inFile = 1
+
+ def characters(self, data):
+ if self.inRevision == 1 or self.inAuthor == 1 or self.inLog == 1 or self.inFile == 1:
+ self.buffer += data
+
+ def endElement(self, tag):
+ if tag == "revision":
+ self.inRevision = 0
+ self.revision = self.buffer
+ if tag == "author":
+ self.inAuthor = 0
+ self.author = self.buffer
+ if tag == "log":
+ self.inLog = 0
+ self.logmessage = self.buffer
+ if tag == "file":
+ self.inFile = 0
+ self.filelist.append(self.buffer)
+
+
+class CommitParser:
+ def __init__(self):
+ self.filename = ""
+ self.author = ""
+ self.revision = ""
+ self.pathline = ""
+ self.logmessage = ""
+ self.filecount = 0
+ self.dircount = 0
+ self.filelist = []
+ self.path = ""
+
+ def parse(self):
+ handler = callback()
+ ctxt = libxml2.createPushParser(handler,"",0,"temp.xml")
+ myfile = file(self.filename)
+ for line in myfile.readlines():
+ ctxt.parseChunk(line,len(line),0)
+ ctxt.parseChunk("",0,1)
+
+ # Let's find out what dirs were touched
+ filelist = handler.filelist
+ finished = 0
+ path = ""
+ multidir = 0
+ while finished == 0:
+ ok = 1
+ i = 0
+ subdirlinecount = 0
+ subdirslashpos = 0
+ maxi = len(filelist)
+ if (i+1) == maxi:
+ ok = 0
+ while i < maxi and ok == 1:
+ search = filelist[i].find("/")
+ if search == -1:
+ #okay, we have a fil in the "top" dir let's stop it
+ ok = 0
+ break
+ if search > -1:
+ # we have a subdir in here, so count ;)
+ subdirlinecount += 1
+ i += 1
+
+ if ok == 1 and multidir == 0:
+ if subdirlinecount == maxi:
+ #okay all dirs still have a slash
+ # everything in the same dir?
+ subdirlinecount = 0
+ lastdir = ""
+ # count dirs
+ filelist.sort()
+ for dir in filelist:
+ if dir.find("/") > -1:
+ if dir[:dir.find("/")+1] != lastdir:
+ subdirlinecount += 1
+ lastdir = dir[:dir.find("/")+1]
+
+ if subdirlinecount == 1:
+ # okay, all lines have the same slashpos.
+ # strip everything up to it
+ i = 0
+ path += filelist[0][:search+1]
+ while i < maxi:
+ filelist[i] = filelist[i][search+1:]
+ i += 1
+ filelist.sort()
+ for line in filelist:
+ if line == "":
+ filelist.remove("")
+ else:
+ #no we seem to have the topdir now..
+ dircount = subdirlinecount
+ multidir = 1
+ else:
+ finished=1
+ filecount = 0
+ dircount = 0
+ lastdir = ""
+ # count dirs
+ filelist.sort()
+ for dir in filelist:
+ if dir.find("/") > -1:
+ if dir[:dir.find("/")+1] != lastdir:
+ dircount += 1
+ lastdir = dir[:dir.find("/")+1]
+
+ filecount = maxi
+ self.author = handler.author
+ self.revision = handler.revision
+ self.logmessage = handler.logmessage
+ self.dircount = dircount
+ self.filecount = filecount
+ self.filelist = filelist
+ self.path = path
+ def generate_pathline(self):
+ self.pathline = ""
+ if (len(self.filelist) == 1):
+ self.pathline = self.path + self.filelist[0]
+ elif (self.filecount > 1 or self.filecount < 4) and self.dircount == 0:
+ self.pathline = self.path + " ("
+ for file in self.filelist:
+ self.pathline += file + " "
+ self.pathline = self.pathline[:-1] + ")"
+ elif self.filecount >= 1 and self.dircount >= 1 and self.filecount+self.dircount < 4:
+ self.pathline = self.path + " ("
+ for file in self.filelist:
+ self.pathline += file + " "
+ self.pathline = self.pathline[:-1] + ")"
+ elif self.filecount >= 1 and self.dircount >= 1 and self.filecount+self.dircount >= 4:
+ self.pathline = self.path + " ("
+ if self.filecount == 1:
+ self.pathline += "1 file"
+ if self.filecount > 1:
+ self.pathline += "%i files" % self.filecount
+ if self.dircount == 1:
+ self.pathline += " in 2 dirs"
+ if self.dircount > 1:
+ self.pathline += " in %i dirs" % (self.dircount)
+ self.pathline += ")"
+
+ def doit(self):
+ self.parse()
+ self.generate_pathline()
diff --git a/scripts/supybot-SunriseCIA-plugin/__init__.py b/scripts/supybot-SunriseCIA-plugin/__init__.py
new file mode 100644
index 000000000..9cdd18837
--- /dev/null
+++ b/scripts/supybot-SunriseCIA-plugin/__init__.py
@@ -0,0 +1,66 @@
+###
+# Copyright (c) 2006, Markus Ullmann
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions, and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions, and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the author of this software nor the name of
+# contributors to this software may be used to endorse or promote products
+# derived from this software without specific prior written consent.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+###
+
+"""
+This plugin announces CVS or SVN Commit messages given in XML
+which are primarily generated for CIA(.navi.cx).
+"""
+
+import supybot
+import supybot.world as world
+
+# Use this for the version of this plugin. You may wish to put a CVS keyword
+# in here if you're keeping the plugin in CVS or some similar system.
+__version__ = "0.1"
+
+# XXX Replace this with an appropriate author or supybot.Author instance.
+__author__ = supybot.Author('Markus Ullmann', 'jokey', 'jokey@gentoo.org')
+
+# This is a dictionary mapping supybot.Author instances to lists of
+# contributions.
+__contributors__ = {}
+
+# This is a url where the most recent plugin package can be downloaded.
+__url__ = 'www.gentoo-sunrise.org/ircplugin' # 'http://supybot.com/Members/yourname/SunriseCIA/download'
+
+import config
+import plugin
+reload(plugin) # In case we're being reloaded.
+# Add more reloads here if you add third-party modules and want them to be
+# reloaded when this plugin is reloaded. Don't forget to import them as well!
+
+if world.testing:
+ import test
+
+Class = plugin.Class
+configure = config.configure
+
+
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
diff --git a/scripts/supybot-SunriseCIA-plugin/config.py b/scripts/supybot-SunriseCIA-plugin/config.py
new file mode 100644
index 000000000..e3dadce7e
--- /dev/null
+++ b/scripts/supybot-SunriseCIA-plugin/config.py
@@ -0,0 +1,49 @@
+###
+# Copyright (c) 2006, Markus Ullmann
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions, and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions, and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the author of this software nor the name of
+# contributors to this software may be used to endorse or promote products
+# derived from this software without specific prior written consent.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+###
+
+import supybot.conf as conf
+import supybot.registry as registry
+
+def configure(advanced):
+ # This will be called by supybot to configure this module. advanced is
+ # a bool that specifies whether the user identified himself as an advanced
+ # user or not. You should effect your configuration by manipulating the
+ # registry as appropriate.
+ from supybot.questions import expect, anything, something, yn
+ conf.registerPlugin('SunriseCIA', True)
+
+
+SunriseCIA = conf.registerPlugin('SunriseCIA')
+# This is where your configuration variables (if any) should go. For example:
+# conf.registerGlobalValue(SunriseCIA, 'someConfigVariableName',
+# registry.Boolean(False, """Help for someConfigVariableName."""))
+
+
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
diff --git a/scripts/supybot-SunriseCIA-plugin/plugin.py b/scripts/supybot-SunriseCIA-plugin/plugin.py
new file mode 100644
index 000000000..bd5749606
--- /dev/null
+++ b/scripts/supybot-SunriseCIA-plugin/plugin.py
@@ -0,0 +1,111 @@
+###
+# Copyright (c) 2006, Markus Ullmann
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions, and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions, and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the author of this software nor the name of
+# contributors to this software may be used to endorse or promote products
+# derived from this software without specific prior written consent.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+###
+
+import threading
+import time
+
+import supybot.utils as utils
+from supybot.commands import *
+import supybot.ircmsgs as ircmsgs
+import supybot.plugins as plugins
+import supybot.ircutils as ircutils
+import supybot.callbacks as callbacks
+import SunriseCIAParser
+import os
+
+DIRCHECK="/var/www/sunrise.gentooexperimental.org/commitwatch"
+ANNOUNCEINCHANNEL="#gentoo-sunrise"
+
+class SunriseCIA(callbacks.Plugin):
+ """Add the help for "@plugin help SunriseCIA" here
+ This should describe *how* to use this plugin."""
+ threaded = True
+
+ def __init__(self, irc):
+ self.__parent = super(SunriseCIA,self)
+ self.__parent.__init__(irc)
+ self.filelist = []
+ self.watchactive = 0
+
+ def parsestart(self, irc, msg, args):
+ if self.watchactive == 0:
+ self.watchactive = 1
+ self.t = threading.Thread(target=self.Parseit, name="ParserWatcher",args=(irc,msg,args))
+ self.t.setDaemon(True)
+ self.t.start()
+
+ parsestart = wrap(parsestart, [('checkCapability', ANNOUNCEINCHANNEL+',op')])
+
+ def parsestop(self,irc,msg,args):
+ self.watchactive = 0
+
+ parsestop = wrap(parsestop, [('checkCapability', ANNOUNCEINCHANNEL+',op')])
+
+ def parsestatus(self, irc, msg, args):
+ if self.watchactive == 1 and self.t.isAlive():
+ irc.reply("SunriseCIA CommitWatch active")
+ else:
+ irc.reply("SunriseCIA CommitWatch disabled")
+
+ parsestatus = wrap(parsestatus)
+
+ def GetFileList(self):
+ for root, dirs, files in os.walk(DIRCHECK):
+ for name in files:
+ self.filelist.append(os.path.join(root,name))
+
+ def Parseit(self, irc, msg, args):
+ #irc.queueMsg(ircmsgs.privmsg(ANNOUNCEINCHANNEL,"SunriseCIA CommitWatch started"))
+ while(self.watchactive):
+ self.GetFileList()
+ if len(self.filelist) > 0:
+ while (1):
+ try:
+ file = self.filelist.pop()
+ except:
+ break;
+ self.log.debug("Found new file: %s",file)
+ parser = SunriseCIAParser.CommitParser( )
+ parser.filename = file
+ parser.doit()
+ tempstr = parser.logmessage.strip()
+ temppos = tempstr.find(":")
+ if temppos > 0:
+ tempstr = tempstr[(tempstr.find(":")+1):].strip()
+ s = "3%s * 10r%s %s: %s < %s >" % (parser.author,parser.revision,parser.pathline,tempstr,"http://gentoo-sunrise.org/cgi-bin/trac.cgi/changeset/" + parser.revision)
+ irc.queueMsg(ircmsgs.privmsg(ANNOUNCEINCHANNEL,s))
+ os.remove(file)
+ time.sleep(2)
+ #irc.queueMsg(ircmsgs.privmsg(ANNOUNCEINCHANNEL,"SunriseCIA CommitWatch stopped"))
+
+Class = SunriseCIA
+
+
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
diff --git a/scripts/supybot-SunriseCIA-plugin/test.py b/scripts/supybot-SunriseCIA-plugin/test.py
new file mode 100644
index 000000000..01e7c59c5
--- /dev/null
+++ b/scripts/supybot-SunriseCIA-plugin/test.py
@@ -0,0 +1,36 @@
+###
+# Copyright (c) 2006, Markus Ullmann
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions, and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions, and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the author of this software nor the name of
+# contributors to this software may be used to endorse or promote products
+# derived from this software without specific prior written consent.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+###
+
+from supybot.test import *
+
+class SunriseCIATestCase(PluginTestCase):
+ plugins = ('SunriseCIA',)
+
+# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: