#!/usr/local/bin/python """ p4rss.py - generate RSS 0.91 feed from 10 most recent changes from Perforce. p4 changes -m 10 To run it, python p4rss.py > /path/to/rssfile see sample.p4rss.xml for sample output. For more information see p4rss.html """ import marshal, os, re # begin-customization # change the values to your Perforce URL public_url = 'http://public.perforce.com' cgi_url = public_url+'/cgi-bin/p4db/changeView.cgi?CH=' maxchanges = 10 # end-of-cusotmization p4changes = 'p4 -G changes -l -m ' + str(maxchanges) stream = os.popen(p4changes) # enttab borrowed from xmllib.py enttab={'<':'<', '>':'>', '&':'&', '"':'"', '\'': '''} def replaceEntity(match): rawEntity=match.group() return enttab[rawEntity] def escapeEntities(s): ent=re.compile('&|>|<|"'"|'"'') return ent.sub(replaceEntity, s) print "" print "" print "\n\ \tMost recent changes in Perforce (up to 10)\n\ \t%s\n\ \ten-US\n\ \tp4 changes -m 10 as RSS 0.91\n" % public_url try: while 1: dict = marshal.load(stream) # sys.stdin #p4desc = 'p4 -G describe -s ' + dict['change'] #s = os.popen(p4desc) #desc = marshal.load(s) print "\t" print "\t\t%s" % dict['change'] print "\t\t%s%s" % (cgi_url, dict['change']) print "\t\t%s" % escapeEntities(dict['desc']) print "\t" except EOFError: pass print "\n\ "