Rev 4: Refactor towards reuse. in http://people.ubuntu.com/~robertc/baz2.0/plugins/branchfeed/trunk
Robert Collins
robertc at robertcollins.net
Thu Jul 10 13:24:30 BST 2008
At http://people.ubuntu.com/~robertc/baz2.0/plugins/branchfeed/trunk
------------------------------------------------------------
revno: 4
revision-id: robertc at robertcollins.net-20080710122430-xz1xelrnbnh8mgbg
parent: robertc at robertcollins.net-20080710084806-sr0rp311up6yjhe3
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Thu 2008-07-10 22:24:30 +1000
message:
Refactor towards reuse.
modified:
branch_feed.py branch_feed.py-20070121145705-sx0o8hd51l0r67r1-4
=== modified file 'branch_feed.py'
--- a/branch_feed.py 2008-07-10 08:48:06 +0000
+++ b/branch_feed.py 2008-07-10 12:24:30 +0000
@@ -46,24 +46,9 @@
BranchFeed(branch).update()
-class BranchFeed(object):
- """A Branch Feed.
-
- BranchFeeds can create RSS content from a branch.
-
- Public attributes:
- now: a time tuple for the time that the feed is executing.
- item_limit: The maximum number of commit items to include. Set to -1 to
- disable.
- """
-
- ATOM_HEAD_TEMPLATE = u"""<?xml version="1.0" encoding="utf-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom">
- <title>$title</title>
- <id>$id</id>
- <updated>$updated</updated>
- <generator uri="http://atonie.org/code/atomlog" />
-"""
+class Feed(object):
+ """A Feed that can be generated."""
+
ATOM_ITEM_TEMPLATE = u"""
<entry>
<title>$title</title>
@@ -80,6 +65,40 @@
</entry>
"""
+ def generate_for_iterator(self, feed, revno_revision_iterator):
+ template = Template(self.ATOM_ITEM_TEMPLATE)
+ for revno, revision in self.iter_revisions():
+ feed += template.substitute({
+ 'title':'revision %s' % revno,
+ 'id':revision.revision_id,
+ 'author':revision.committer,
+ 'updated':format_date(revision.timestamp,
+ revision.timezone or 0, 'utc', '%Y-%m-%dT%H:%M:%SZ',
+ show_offset=False),
+ 'content':revision.message,
+ })
+ return feed
+
+
+class BranchFeed(Feed):
+ """A Branch Feed.
+
+ BranchFeeds can create RSS content from a branch.
+
+ Public attributes:
+ now: a time tuple for the time that the feed is executing.
+ item_limit: The maximum number of commit items to include. Set to -1 to
+ disable.
+ """
+
+ ATOM_HEAD_TEMPLATE = u"""<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title>$title</title>
+ <id>$id</id>
+ <updated>$updated</updated>
+ <generator uri="http://atonie.org/code/atomlog" />
+"""
+
def __init__(self, branch, now=None):
"""Create a BranchFeed on branch.
@@ -112,17 +131,10 @@
feed = template.substitute({
'title':self.branch.nick,
'id':str(self.branch.base),
- 'updated':format_date(self.now, 0, 'utc', '%Y-%m-%dT%H:%M:%SZ', show_offset=False)
+ 'updated':format_date(self.now, 0, 'utc', '%Y-%m-%dT%H:%M:%SZ',
+ show_offset=False)
})
- template = Template(self.ATOM_ITEM_TEMPLATE)
- for revno, revision in self.iter_revisions():
- feed += template.substitute({
- 'title':'revision %s' % revno,
- 'id':revision.revision_id,
- 'author':revision.committer,
- 'updated':format_date(revision.timestamp, revision.timezone or 0, 'utc', '%Y-%m-%dT%H:%M:%SZ', show_offset=False),
- 'content':revision.message,
- })
+ feed = self.generate_for_iterator(feed, self.iter_revisions())
return feed.encode('utf8')
def update(self):
More information about the bazaar-commits
mailing list