I was a bit bored last night so I wrote a little Python script which
take the results of the index.html file in GUMP and turn it into RSS. 
This allows me to keep track of the status of hourly builds without
firing up a browser.

The script either looks for a gumprss.config file in the local directory
or you can pass in the location on the command-line:

./gumprss.py [/path/to/config]

The result is a status.rss file created in the same directory as the
index.html.  Since RSS will only display 16 items, a GUMP run like
jakarta's won't be that useful but I did add a config parameter which
takes a comma-delimited list of projects you are interested and will
only put those into the RSS file.  That is working for me.

I'm sure there are plenty of Python design errors but the script is
working for me so I thought I'd send it off.


josh
#!/usr/bin/env python

from xml.dom.ext.reader.HtmlLib import *
from xml.dom.html.HTMLDocument import *
from xml.dom.html.HTMLTableElement import *
from xml.dom.Element import *
from ConfigParser import *

import types,time

class GumpRssBuilder:
    def __init__(self):
        self.gumpdir = ""
        self.contactperson = ""
        self.rsslink = ""
        self.projects = ""
        self.indexhtml = "index.html"
        self.lines = []
        self.timestamp = None
        self.init()
        self.parseGump()
        self.buildTime()
        self.buildRss()

    def init(self):
        cp = ConfigParser()
        if len(sys.argv) == 1:
            conffile = "gumprss.config"
        else:
            conffile = sys.argv[1]
        cp.read(conffile)
        self.gumpdir = cp.get('gump','gumpdir')
        self.contactperson = cp.get('gump','contactperson')
        self.rsslink = cp.get('gump','rsslink')
        pStr = cp.get('gump','projects')
        if pStr != "" or pStr != None:
            self.projects = string.split(pStr,",")
        self.rssfile = open(self.gumpdir + "status.rss","wb")


    def parseGump(self):
        doc = FromHtmlFile(self.gumpdir + self.indexhtml)

        nl = doc.getElementsByTagName("TABLE")

        for n in nl:
            att =  n.attributes.getNamedItem("border")

            if att.value == "1":
                trList = n.getElementsByTagName("TR")
                for tr in trList:
                    tdList = tr.getElementsByTagName("TD")
                    tmpList = tdList[:]
                    if len(tmpList) > 0:
                        time = tmpList[0].firstChild.nodeValue
                        status = tmpList[2].firstChild.nodeValue
                        link = tmpList[1].firstChild.nextSibling.attributes.getNamedItem("href").value
                        name = tmpList[1].firstChild.nextSibling.firstChild.nodeValue
                        line =  "%s -- %s at %s" % (string.strip(name), 
                                                    string.strip(status), 
                                                    string.strip(time))
                        self.lines.append(line)

    def buildRss(self):
        self.writeHeader()
        self.writeItems()
        self.writeFooter()

    def writeHeader(self):
        f = self.rssfile
        f.write("<?xml version=\"1.0\"?>\n")
        f.write("<!DOCTYPE rss PUBLIC \"-//Netscape Communications//DTD RSS 0.91//EN\" \"http://my.netscape.com/publish/formats/rss-0.91.dtd\";>\n")
        f.write("<rss version=\"0.91\">\n")
        f.write("\t<channel>\n")
        f.write("\t<title>GUMP Status</title>\n")
        f.write("\t<link>%s</link>\n" % self.rsslink)
        f.write("\t<description>Hourly build status</description>")
        f.write("\t<language>en-us</language>\n")
        f.write("\t<pubDate>%s</pubDate>\n" % self.timestamp)
        f.write("\t<lastBuildDate>%s</lastBuildDate>\n" % self.timestamp)
        f.write("\t<managingEditor>%s</managingEditor>\n" % self.contactperson)
        f.write("\t<webMaster>%s</webMaster>\n" % self.contactperson)

    def writeItems(self):
        f = self.rssfile
        plen = len(self.projects)
        if plen > 1:
            for line in self.lines:
                tmp = string.split(line,"--")
                if self.projects.count(tmp[0].strip()) > 0:
                    f.write("\t<item>\n")
                    f.write("\t\t<title>%s</title>\n" % line)
                    f.write("\t\t<link>%s%s.html</link>\n" % (self.rsslink,tmp[0].strip()))
                    f.write("\t\t<description>%s</description>\n" % line)
                    f.write("\t</item>\n")
        else:
            for line in self.lines:
                f.write("\t<item>\n")
                f.write("\t\t<title>%s</title>\n" % line)
                tmp = string.split(line,"--")
                f.write("\t\t<link>%s%s.html</link>\n" % (self.rsslink,tmp[0].strip()))
                f.write("\t\t<description>%s</description>\n" % line)
                f.write("\t</item>\n")
           
    def writeFooter(self):
        f = self.rssfile
        f.write("\t</channel>\n")
        f.write("</rss>\n")

    def buildTime(self):
        local = time.gmtime(time.time())
        self.timestamp = "%s, %s %s %s %s:%s:%s GMT" % (time.strftime("%a",local),
                              time.strftime("%d",local),
                              time.strftime("%b",local),
                              time.strftime("%Y",local),
                              time.strftime("%H",local),
                              time.strftime("%M",local),
                              time.strftime("%S",local))

            
if __name__=="__main__": GumpRssBuilder() 
[gump]

#the path to the directory where index.html is at
gumpdir=

#the rss file needs an email address
contactperson=

#web location of index.html and other projects html files
#for example, http://jakarta.apache.org/builds/gump/latest/
rsslink=

#since RSS can only display 16 projects, you can give a comma-delimited list 
#of projects you are interested in
projects=

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to