Rev 26: Add stop tracking to the logger. in lp:~jameinel/+junk/file_locking

John Arbash Meinel john at arbash-meinel.com
Mon Sep 21 22:09:14 BST 2009


At lp:~jameinel/+junk/file_locking

------------------------------------------------------------
revno: 26
revision-id: john at arbash-meinel.com-20090921210906-ryhj0sqlvkt19lrl
parent: john at arbash-meinel.com-20090921210631-yzluxr602ci0ziek
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: file_locking
timestamp: Mon 2009-09-21 16:09:06 -0500
message:
  Add stop tracking to the logger.
-------------- next part --------------
=== modified file 'file_lock.py'
--- a/file_lock.py	2009-09-21 21:06:31 +0000
+++ b/file_lock.py	2009-09-21 21:09:06 +0000
@@ -223,6 +223,7 @@
         if file_id in self._active_locks:
             raise ValueError('{%s} has an active lock' % (file_id,))
         self._tracked_ids.remove(file_id)
+        self._logger.stop_tracking(file_id)
 
 
 class FileLockLogger(object):
@@ -288,6 +289,12 @@
         stanza.add('file_id', file_id)
         self._log_stanza(stanza)
 
+    def stop_tracking(self, file_id):
+        """We stopped tracking this file id."""
+        stanza = self._create_action('untrack file-id')
+        stanza.add('file_id', file_id)
+        self._log_stanza(stanza)
+
 
 class NullFileLockLogger(FileLockLogger):
     """For testing purposes only.

=== modified file 'tests/test_file_lock.py'
--- a/tests/test_file_lock.py	2009-09-21 21:06:31 +0000
+++ b/tests/test_file_lock.py	2009-09-21 21:09:06 +0000
@@ -416,5 +416,22 @@
             'date: .*\n'
             'user: .*\n'
             'host: .*\n'
-            'file_id: .*\n',
+            'file_id: file-id-3\n',
+            flags=re.MULTILINE)
+
+    def test_stop_tracking(self):
+        logger = self.make_logger()
+        li = file_lock.FileLockingInfo(['file-id-1', 'file-id-2'], {},
+                                       logger)
+        li.stop_tracking('file-id-2')
+        logger.flush()
+        self.assertContainsRe(logger._transport.get_bytes(logger._filename),
+            '\n'# end of previous action
+            '\n'# extra separator line
+            'action: untrack file-id\n'
+            'time: \\d+\n'
+            'date: .*\n'
+            'user: .*\n'
+            'host: .*\n'
+            'file_id: file-id-2\n',
             flags=re.MULTILINE)



More information about the bazaar-commits mailing list