Rev 6: Stash pending changes - probably broken. in http://people.canonical.com/~robertc/baz2.0/plugins/branchfeed/trunk

Robert Collins robertc at robertcollins.net
Mon Jun 21 03:50:20 BST 2010


At http://people.canonical.com/~robertc/baz2.0/plugins/branchfeed/trunk

------------------------------------------------------------
revno: 6
revision-id: robertc at robertcollins.net-20100621025019-7zk49pwfyc23xfma
parent: robertc at robertcollins.net-20080710140633-0u8ggz1jvh526b0e
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Mon 2010-06-21 14:50:19 +1200
message:
  Stash pending changes - probably broken.
=== modified file '__init__.py'
--- a/__init__.py	2008-07-10 14:06:33 +0000
+++ b/__init__.py	2010-06-21 02:50:19 +0000
@@ -26,19 +26,24 @@
 
 import os
 from stat import S_ISDIR
+from string import Template
+import time
 
 from bzrlib.commands import Command, register_command
+from bzrlib.option import Option
 from bzrlib.lazy_import import lazy_import
 lazy_import(globals(), """
 from bzrlib.branch import Branch
+from bzrlib.osutils import format_date
 from bzrlib.transport import get_transport
 """)
 try:
     from pyinotify import EventsCodes, Notifier, ProcessEvent, WatchManager
+    EventsCodes.IN_MOVED_TO | EventsCodes.IN_CREATE
     feedgen = True
-except ImportError:
+except (ImportError, AttributeError):
     feedgen = False
-from bzrlib.plugins.branchfeed.branch_feed import install_hooks, BranchFeed
+from bzrlib.plugins.branchfeed.branch_feed import install_hooks, BranchFeed, Feed
 
 
 if feedgen:
@@ -51,6 +56,20 @@
                 path = "%s" % event.path
             return path
 
+        def _emit_feed(self):
+            if self._feed is None:
+                return
+            template = Template(BranchFeed.ATOM_HEAD_TEMPLATE)
+            feeder = Feed()
+            feed = template.substitute({
+                'title':'All branches',
+                'id':'urn:bzr-istanbul.gnome.org/branches.atom',
+                'updated':format_date(time.time(), 0, 'utc', '%Y-%m-%dT%H:%M:%SZ',
+                    show_offset=False)
+                })
+            feed = feeder.generate_for_iterator(feed, self._revs)
+            get_transport('.').put_bytes(self._feed, feed.encode('utf8'))
+
         def process_default(self, event):
             return
             print event
@@ -69,6 +88,10 @@
             if path.endswith('last-revision'):
                 b, _ = Branch.open_containing(path)
                 BranchFeed(b).update()
+                revno, revid = b.last_revision_info()
+                revision = b.repository.get_revision(revid)
+                relpath = None
+                self._revs.append(("%d in %s" % (revno, relpath), revision))
                 print "updated", b.base
 
     dir_mask = EventsCodes.IN_MOVED_TO | EventsCodes.IN_CREATE #EventsCodes.ALL_EVENTS
@@ -78,8 +101,12 @@
         """Generate feeds for many branches."""
 
         takes_args = ['location?']
+        takes_options = [
+            Option('feed', type=str,
+                help='output a combined feed for all branches to this path')
+            ]
 
-        def run(self, location='.'):
+        def run(self, location='.', feed=None):
             transport = get_transport(location)
             root = transport.local_abspath('.')
             new_dirs = set('.')
@@ -98,6 +125,8 @@
             added_flag = False
             handler = ProcessClose()
             handler._bzr_wm = wm
+            handler._revs = []
+            handler._feed = feed
             notifier = Notifier(wm, handler)
             # read and process events
             try:
@@ -109,6 +138,7 @@
                     notifier.process_events()
                     if notifier.check_events():
                         notifier.read_events()
+                        handler._emit_feed()
             finally:
                 notifier.stop()
 

=== modified file 'branch_feed.py'
--- a/branch_feed.py	2008-07-10 12:24:30 +0000
+++ b/branch_feed.py	2010-06-21 02:50:19 +0000
@@ -67,7 +67,7 @@
 
     def generate_for_iterator(self, feed, revno_revision_iterator):
         template = Template(self.ATOM_ITEM_TEMPLATE)
-        for revno, revision in self.iter_revisions():
+        for revno, revision in revno_revision_iterator:
             feed += template.substitute({
                 'title':'revision %s' % revno,
                 'id':revision.revision_id,




More information about the bazaar-commits mailing list