#!/usr/local/bin/python """ p4rss.py - generate RSS 2.0 feed from 10 most recent changes from Perforce. p4 changes -m 10 To run it, python p4rss.py > /path/to/rssfile python p4rss.py ... > /path/to/rssfile python p4rss.py //depot/jay_han/... > /path/to/rssfile p4rss.py takes an optional argument of path. Other options of p4 changes, -i, -u, -s, etc are not supported. see sample.p4rss.xml for sample output. For more information see p4rss.html RSS 2.0 documentation: http://backend.userland.com/rss """ import marshal, os, re, sys, time # optinal path arg -- XXX: no safety check! args = sys.argv[1:] or [r'//...'] path = ' '.join(args) # 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) + ' ' + path 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 RSS 2.0 print "" print "" print "" print "\tMost recent changes in Perforce " print "\t%s" % public_url print "\ten-US" print "\tp4 changes -l -m 10 %s in RSS 2.0\n" % path print "\t%s" % time.asctime() try: while 1: dict = marshal.load(stream) print "\t" print "\t\t%s" % dict['change'] print "\t\t%s%s" % (cgi_url, dict['change']) print "\t\t%s" % time.asctime(time.localtime(int(dict['time']))) print "\t\t%s" % dict['user'] print "\t\t%s" % escapeEntities(dict['desc']) print "\t" except EOFError: pass print "" print ""