Rev 5: Crude inotify watcher - bzr feedgen. in http://people.ubuntu.com/~robertc/baz2.0/plugins/branchfeed/trunk
Robert Collins
robertc at robertcollins.net
Thu Jul 10 15:06:34 BST 2008
At http://people.ubuntu.com/~robertc/baz2.0/plugins/branchfeed/trunk
------------------------------------------------------------
revno: 5
revision-id: robertc at robertcollins.net-20080710140633-0u8ggz1jvh526b0e
parent: robertc at robertcollins.net-20080710122430-xz1xelrnbnh8mgbg
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Fri 2008-07-11 00:06:33 +1000
message:
Crude inotify watcher - bzr feedgen.
modified:
__init__.py __init__.py-20070121145705-sx0o8hd51l0r67r1-3
=== modified file '__init__.py'
--- a/__init__.py 2007-01-29 17:50:01 +0000
+++ b/__init__.py 2008-07-10 14:06:33 +0000
@@ -24,7 +24,93 @@
items, but it is planned to be made configurable.
"""
-from branch_feed import install_hooks
+import os
+from stat import S_ISDIR
+
+from bzrlib.commands import Command, register_command
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
+from bzrlib.branch import Branch
+from bzrlib.transport import get_transport
+""")
+try:
+ from pyinotify import EventsCodes, Notifier, ProcessEvent, WatchManager
+ feedgen = True
+except ImportError:
+ feedgen = False
+from bzrlib.plugins.branchfeed.branch_feed import install_hooks, BranchFeed
+
+
+if feedgen:
+ class ProcessClose(ProcessEvent):
+
+ def event_path(self, event):
+ if event.name:
+ path = "%s" % os.path.join(event.path, event.name)
+ else:
+ path = "%s" % event.path
+ return path
+
+ def process_default(self, event):
+ return
+ print event
+ # import pdb;pdb.set_trace()
+
+ def _process_IN_CLOSE(self, event):
+ """Update a branch when last-revision is written."""
+ print "%s: closed" % self.event_path(event)
+
+ def process_IN_CREATE(self, event):
+ if event.is_dir:
+ self._bzr_wm.add_watch(self.event_path(event), dir_mask)
+
+ def process_IN_MOVED_TO(self, event):
+ path = self.event_path(event)
+ if path.endswith('last-revision'):
+ b, _ = Branch.open_containing(path)
+ BranchFeed(b).update()
+ print "updated", b.base
+
+ dir_mask = EventsCodes.IN_MOVED_TO | EventsCodes.IN_CREATE #EventsCodes.ALL_EVENTS
+
+
+ class cmd_feedgen(Command):
+ """Generate feeds for many branches."""
+
+ takes_args = ['location?']
+
+ def run(self, location='.'):
+ transport = get_transport(location)
+ root = transport.local_abspath('.')
+ new_dirs = set('.')
+ relpaths = set('.')
+ while relpaths:
+ relpath = relpaths.pop()
+ paths = transport.list_dir(relpath)
+ for path in paths:
+ st = transport.stat(relpath + '/' + path)
+ if S_ISDIR(st.st_mode):
+ if path != '.bzr':
+ new_dirs.add(relpath + '/' + path)
+ relpaths.add(relpath + '/' + path)
+ # gather all dirs
+ wm = WatchManager()
+ added_flag = False
+ handler = ProcessClose()
+ handler._bzr_wm = wm
+ notifier = Notifier(wm, handler)
+ # read and process events
+ try:
+ while True:
+ if new_dirs:
+ for path in new_dirs:
+ wm.add_watch(root + '/' + path, dir_mask)
+ new_dirs = set()
+ notifier.process_events()
+ if notifier.check_events():
+ notifier.read_events()
+ finally:
+ notifier.stop()
def test_suite():
@@ -33,3 +119,5 @@
install_hooks()
+if feedgen:
+ register_command(cmd_feedgen)
More information about the bazaar-commits
mailing list