Rev 37: Support parsing the active locks section back out of the file. in lp:~jameinel/+junk/file_locking

John Arbash Meinel john at arbash-meinel.com
Wed Sep 23 05:29:05 BST 2009


At lp:~jameinel/+junk/file_locking

------------------------------------------------------------
revno: 37
revision-id: john at arbash-meinel.com-20090923042855-oi2y3cqj5yc3oay0
parent: john at arbash-meinel.com-20090923042011-2yf08hrrtsown8dk
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: file_locking
timestamp: Tue 2009-09-22 23:28:55 -0500
message:
  Support parsing the active locks section back out of the file.
-------------- next part --------------
=== modified file 'file_lock.py'
--- a/file_lock.py	2009-09-23 04:20:11 +0000
+++ b/file_lock.py	2009-09-23 04:28:55 +0000
@@ -151,7 +151,19 @@
             tracked_ids = []
         else:
             tracked_ids = stanza.get_all('t')
-        return FileLockingInfo(tracked_ids, {}, logger)
+        active_locks_stanza = rio.read_stanza(as_file)
+        if active_locks_stanza is None:
+            raise ValueError('no "active_locks:" line')
+        num_active_locks = int(active_locks_stanza['active_locks'])
+        active_locks = {}
+        for lock_num in xrange(num_active_locks):
+            # TODO: Handle having a repeated file-id
+            stanza = rio.read_stanza(as_file)
+            # TODO: Test this
+            # if stanza is None:
+            #     raise ValueError
+            active_locks[stanza['file_id']] = stanza
+        return FileLockingInfo(tracked_ids, active_locks, logger)
 
     def to_bytes(self, locking_info):
         content = [self._HEADER, '\n']

=== modified file 'tests/test_file_lock.py'
--- a/tests/test_file_lock.py	2009-09-23 04:20:11 +0000
+++ b/tests/test_file_lock.py	2009-09-23 04:28:55 +0000
@@ -41,7 +41,7 @@
 
     def test_from_bytes(self):
         s = file_lock.FileLockingInfoSerializer()
-        li = s.from_bytes('%s\n' % s._HEADER)
+        li = s.from_bytes('%s\n\nactive_locks: 0\n' % s._HEADER)
         self.assertEqual(set(), li._tracked_ids)
 
     def test_from_bytes_with_ids(self):
@@ -49,9 +49,35 @@
         li = s.from_bytes('%s\n'
                           't: file-id-1\n'
                           't: dir-id-2\n'
+                          '\n'
+                          'active_locks: 0\n'
                           % s._HEADER)
         self.assertEqual(set(['file-id-1', 'dir-id-2']), li._tracked_ids)
 
+    def test_from_bytes_with_active_locks(self):
+        s = file_lock.FileLockingInfoSerializer()
+        li = s.from_bytes('%s\n'
+                          't: file-id-1\n'
+                          't: file-id-2\n'
+                          '\n'
+                          'active_locks: 1\n'
+                          '\n'
+                          'file_id: file-id-1\n'
+                          'host: localhost\n'
+                          'nonce: b80nt21jmniqbetst31l\n'
+                          'pid: 12345\n'
+                          'time: 1253679708\n'
+                          'user: I Am <sam at iam.com>\n'
+                          '\n' % (s._HEADER,))
+        self.assertEqual(1, len(li._active_locks))
+        info = li._active_locks['file-id-1']
+        self.assertEqual('file-id-1', info['file_id'])
+        self.assertEqual('localhost', info['host'])
+        self.assertEqual('b80nt21jmniqbetst31l', info['nonce'])
+        self.assertEqual('12345', info['pid'])
+        self.assertEqual('1253679708', info['time'])
+        self.assertEqual('I Am <sam at iam.com>', info['user'])
+
     def test_to_bytes_trivial(self):
         li = file_lock.FileLockingInfo([], {})
         s = file_lock.FileLockingInfoSerializer()



More information about the bazaar-commits mailing list