#!/usr/local/bin/python """ <h3>Name</h3> p4rss.py - generate RSS feed from <code>p4 changes -m 10</code>. <h3>Synopsis</h3> <code>python p4rss.py > /path/to/rssfile</code><br/> <h3>Description</h3> p4rss.py converts usual output from p4 changes e.g. <pre> Change 10 on 2003/02/26 by hjh@p4rss 'Doc on RSS 0.91 vs 1.0, and cos' Change 9 on 2003/02/26 by hjh@p4rss 'Add a bit more doc. ' Change 8 on 2003/02/26 by hjh@p4rss 'Documentation and cosmetic chan' ... </pre> to RSS 0.91 format see <a href="http://radio.weblogs.com/0107481/sample.p4rss.xml">sample.p4rss.xml</a>. Run it inside a cron job to generate the RSS periodically. <p> Because p4rss.py uses vanilla p4, user can modify its behaviour with usual P4 environment variables. <h3>Bugs</h3> p4rss.py has many limitations: <ul> <li>because 'p4 changes' limits description of changelist to 31 characters, so does p4rss.py. One way to bypass this limit is to do a join with 'p4 changes' and 'p4 describe -s'. Maybe in the future.</li> <li>no way to limit the change list to specific depot/branch.</li> <li>supports only RSS 0.91 and not other versions of RSS.</li> <li>need to escape HTML entities in <description></li> <li>p4 changes returns following data fields <ul> <li>status: ignored</li> <li>client: ignored</li> <li>user: ignored </li> <li>code: ignored</li> <li>time: ignored</li> <li>change: displayed as <title> element</li> <li>desc: displayed as <description> element</li> </ul> User and time fields are useful information and need to be displayed. Maybe more extensible RSS 1.0+ should be used instead of really simple 0.91?</li> <li><link> element is set to http://127.0.0.1 for now i.e. it is not really meaningful. One solution would be make p4rss configurable and let users choose either p4db or p4web or some other web frontends. However p4web's URL is a pretty complicated (need to find some doc)</li> <li>currently number of items displayed is hardcoded to 10.</li> <li>no support for caching and other advanced features.</li> </ul> <h3>Todo</h3> <ol> <li>study web interfaces like p4db, p4web or <a href="http://pyds.muensterland.org/">PyDS</a></li> <li>trim this doc comment as it's even longer than the code!</li> </ol> <h3>Download</h3> python script: <a href="http://radio.weblogs.com/0107481/p4rss.zip">p4rss.zip</a> and sample RSS: <a href="http://radio.weblogs.com/0107481/sample.p4rss.xml">sample.p4rss.xml</a> <br/> Copyright 2003 Jay Han<br/> You are free to use it as long as you do not blame me for anything. """ import marshal, os p4changes = 'p4 -G changes -m 10' # + max stream = os.popen(p4changes) 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>http://127.0.0.1/</link>\n\ \t<language>en-US</language>\n\ \t<description>p4 changes -m 10 as RSS 0.91</description>\n" try: while 1: dict = marshal.load(stream) # sys.stdin print "\t<item>" print "\t\t<title>%s</title>" % dict['change'] print "\t\t<link>http://127.0.0.1/</link>" ## % dict['user'] print "\t\t<description>%s</description>" % dict['desc'] print "\t</item>" except EOFError: pass print "</channel>\n\ </rss>"
# | 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 |