1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 | #!/usr/bin/env python
#
# Publish CVS commits to a RSS feed.
#
# This is a Python port of Dave Thomas's commit2rss.rb, because SourceForge
# doesn't support Ruby cvs scripts yet.
#
# To use: checkout your repository's CVSROOT module, edit loginfo, and
# add a line similar to this:
#
# ALL /path/to/commit2rss.py %{}
#
# More CVS trigger info at:
# https://www.cvshome.org/docs/manual/cvs-1.11.17/cvs_18.html#SEC167
#
# Copyright (c) 2004 Ori Peleg, all rights reserved
#
# Released under the BSD license, available at:
# http://www.opensource.org/licenses/bsd-license.php
#
# Credits:
# - Dave Thomas, for commit2rss.rb: see his post and code at:
# http://www.pragmaticautomation.com/cgi-bin/pragauto.cgi/Monitor/Loginfo2Rss.rdoc
#
# - Mark Nottingham, for module RSS.py.
# If RSS.py wasn't included with this file, you can find it at:
# http://www.mnot.net/python/RSS.py
# Plus, if you're interested in creating RSS feeds, check out:
# http://www.mnot.net/rss/tutorial/
DROP_DIR = "/path/to/drop/dir"
ITEMS_TO_KEEP = 10
CHANNEL_LINK = "" # enter link here, if you like
import sys, os, re, time, pwd
from RSS import ns, CollectionChannel
class Publisher:
def __init__(self, filename, repositoryName):
self.initChannel(filename, repositoryName)
self.addItem( self._buildItemDescription() )
self.removeExcess(ITEMS_TO_KEEP)
self.write(filename)
def initChannel(self, filename, repositoryName):
try: # parse existing channel
self.channel = CollectionChannel()
self.channel.parse("file:" + filename)
except: # create new channel
title = desc = "Commit summary: %s"%repositoryName
self.channel = self._createChannel(title, desc, CHANNEL_LINK)
def addItem(self, description):
title = time.strftime("%b %d, %H:%M") + " - " + self._getUser()
self.channel.addItem( self._createItem(title, description) )
def removeExcess(self, maxItems):
del self.channel[(ns.rss10, "items")][maxItems:]
def _createChannel(self, title, description, link):
fields = { (ns.rss10, "title"): title,
(ns.rss10, "description"): description,
(ns.rss10, "link"): link }
return CollectionChannel({ (ns.rss10, "channel"): fields })
def _createItem(self, title, description):
return { (ns.rss10, "title"): title,
(ns.rss10, "description"): description,
(ns.dc, "date"): time.ctime() }
def _buildItemDescription(self):
def format(line):
line = re.sub("\n$","", line) # chomp any trailing newline
if re.match(r"[A-Z].*:\s*$", line):
return "<p /><b>%s</b><br />" % line
return "%s<br />" % line
return "".join([format(line) for line in sys.stdin])
def _getUser(self):
try: return pwd.getpwuid(os.getuid())[0]
except: return "Unknown uid %s"%os.getuid()
def write(self, filename):
open(filename, "w").write( str(self.channel) )
# get the top-level project name
repositoryName = sys.argv[1].split("/")[0]
rssFilename = os.path.join(DROP_DIR, repositoryName+".rss")
Publisher(rssFilename, repositoryName)
|
Ouch, dang it. Maybe I have a version problem. When set up as recommended I get:
I'm pretty green at python, but I did check the xml "__init__.py" file and it seems to show that I'm on version 0.8.2 of the xml stuff.
with pyXML version >= 0.8.3 the script is working
Requires XML 0.8.3 or better. Yep, that was it. After a great deal of bureaucratic wrangling, I got 0.8.4 installed on the server in question. Now it runs just fine.
How to set up/debug commit2rss.py on Sourceforge. I have absolutely no plan about Python but I want to use commit2rss.py for my project BioWeka on Sourceforge. I installed and configured it as described:
But: There are no files within this directory after I commited changes to the repository. What did I wrong or what didn't I? How to debug it? E.g. call commit2rss.py manual from shell?
Using with cvs-1.12.x. If you're using this script with cvs-1.12.x, you need to change '%{}' to '%{p}' in your CVSROOT/loginfo file. Also make sure that 'UseNewInfoFmtStrings=yes' is set in your CVSROOT/config file if you are upgrading from an earlier version of CVS. This will get rid of the warnings about use of deprecated format strings.