#!/usr/local/bin/python """ p4rss.py - generate RSS 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 -m ' + str(maxchanges) stream = os.popen(p4changes) enttab={'<':'<', '>':'>', '&':'&', '"':'"', '\'': '''} def rr(m): ss=m.group(); return enttab[ss] def escapeEntities(s): ent=re.compile('&|>|<|"'"|'"'') return ent.sub(rr, s) print "<?xml version='1.0'?>" print "<rss version=\"0.91\">" print "<channel>\n\ \t<title>Most recent changes in Perforce (up to 10)</title>\n\ \t<link>%s</link>\n\ \t<language>en-US</language>\n\ \t<description>p4 changes -m 10 as RSS 0.91</description>\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<item>" print "\t\t<title>%s</title>" % desc['change'] print "\t\t<link>%s%s</link>" % (cgi_url, escapeEntities(desc['change'])) print "\t\t<description>%s</description>" % escapeEntities(desc['desc']) print "\t</item>" except EOFError: pass print "</channel>\n\ </rss>" # copied from xmllib.py entitydefs = {'lt': '<', # must use charref 'gt': '>', 'amp': '&', # must use charref 'quot': '"', 'apos': ''', }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#15 | 3373 | Jay Han |
set popen mode depending on os.name. also changed #! to more usual /usr/bin/python. |
||
#14 | 3361 | Jay Han | stuff description as CDATA and use XSLT substitution to turn \n to <br/> | ||
#13 | 3358 | Jay Han | added email option and updated release.bat | ||
#12 | 3352 | Jay Han | use ConfigParser to read p4rss.ini config file. | ||
#11 | 3340 | Jay Han | pubDate element is now in RFC 822 [2822] format in compliance with RSS 2.0 spec. | ||
#10 | 3339 | Jay Han |
Generate RSS 2.0. Two problems: date should be RFC 882 format and author element should include email. Otherwise p4rss.py generates valid RSS 2.0 output. |
||
#9 | 2834 | Jay Han |
set default file argument to //... (users can supply their own optional arguments) |
||
#8 | 2826 | Jay Han | take an optional file argument to narrow down scope of p4 changes. | ||
#7 | 2815 | Jay Han |
use 'p4 changes -l' rather than do expensive join of p4 changes and describe! Ugh, I cannot believe I missed -l option of p4 changes... |
||
#6 | 2813 | Jay Han | code cleanup | ||
#5 | 2812 | Jay Han | escape &, <, >, ", ' to HTML entities | ||
#4 | 2798 | Jay Han | customization information (or some lame excuses...) | ||
#3 | 2782 | Jay Han | description comes from p4 describe, not the truncated p4 changes output. | ||
#2 | 2781 | Jay Han | pull out doc from p4rss.py, set url to public.perforce.com for now, also add a sample.p4rss.xml. | ||
#1 | 2779 | Jay Han | 1st public cut of p4rss.py |