Rev 21: Change the initialize* interface to use a Transport. in lp:~jameinel/+junk/file_locking
John Arbash Meinel
john at arbash-meinel.com
Mon Sep 21 21:09:23 BST 2009
At lp:~jameinel/+junk/file_locking
------------------------------------------------------------
revno: 21
revision-id: john at arbash-meinel.com-20090921200915-w15tstoyu4rtki3m
parent: john at arbash-meinel.com-20090921195731-zjkgx23omnlaxnth
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: file_locking
timestamp: Mon 2009-09-21 15:09:15 -0500
message:
Change the initialize* interface to use a Transport.
This helps ensure that we do things in memory rather than on disk.
-------------- next part --------------
=== modified file 'file_lock.py'
--- a/file_lock.py 2009-09-21 19:42:40 +0000
+++ b/file_lock.py 2009-09-21 20:09:15 +0000
@@ -26,6 +26,7 @@
lockdir,
osutils,
rio,
+ transport,
)
# There are 2 basic sets of information that needs to be tracked.
@@ -267,6 +268,8 @@
@classmethod
def open(cls, transport):
"""Open a FileLockStore at the given URL."""
+ # TODO: This will raise NoSuchFile if the target doesn't exist.
+ # Create a Custom Exception
info_bytes = transport.get_bytes('info')
s = FileLockingInfoSerializer()
locking_info = s.from_bytes(info_bytes)
@@ -284,20 +287,25 @@
def __init__(self, wt):
self._wt = wt
- self._locking_info = None
+ self._lock_store = None
- def initialize_lock_store(self, url):
+ def initialize_lock_store(self, trans):
"""State that content will be tracked at the given url."""
# TODO: eventually this should probably create the file-locking-store
# if one does not exist yet.
self._wt.lock_write()
try:
- s = FileLockingInfoSerializer()
# Check and see if bzr-file-locking has been added
+ try:
+ lock_store = FileLockStore.open(trans)
+ except errors.NoSuchFile: # TODO: Custom exception
+ lock_store = FileLockStore.initialize(trans)
+ lock_store.unlock()
conf = self._wt.branch.get_config()
if conf.get_user_option(self._CONFIG_ENTRY) is not None:
raise ValueError('lock store already set.')
- conf.set_user_option(self._CONFIG_ENTRY, url)
+ conf.set_user_option(self._CONFIG_ENTRY, trans.base)
+ self._lock_store = lock_store
finally:
self._wt.unlock()
=== modified file 'tests/test_file_lock.py'
--- a/tests/test_file_lock.py 2009-09-21 19:42:40 +0000
+++ b/tests/test_file_lock.py 2009-09-21 20:09:15 +0000
@@ -223,20 +223,26 @@
def test_already_initialized(self):
tree, manager = self.make_tree_and_manager('.')
- manager.initialize_lock_store('.')
- self.assertRaises(ValueError, manager.initialize_lock_store, 'foo')
+ manager.initialize_lock_store(self.get_transport('lock-store'))
+ # This manager is already initialized
+ self.assertRaises(ValueError, manager.initialize_lock_store,
+ self.get_transport('foo'))
def test_initialize(self):
tree, manager = self.make_tree_and_manager('.')
- manager.initialize_lock_store('.')
+ trans = self.get_transport('lock-store')
+ manager.initialize_lock_store(trans)
conf = tree.branch.get_config()
- self.assertEqual('.',
+ self.assertEqual(trans.base,
conf.get_user_option(file_lock.FileLockManager._CONFIG_ENTRY))
+ # The locks should be created
+ lock_store = file_lock.FileLockStore.open(
+ self.get_transport('lock-store'))
def test_is_tracked_no_tracking(self):
tree, manager = self.make_tree_and_manager('.')
self.assertFalse(manager.is_tracked(''))
- manager.initialize_lock_store('.')
+ manager.initialize_lock_store(self.get_transport('lock-store'))
self.assertFalse(manager.is_tracked(''))
def test_basic_acceptance(self):
@@ -252,7 +258,7 @@
# Refresh the memory tree
tree.unlock()
tree.lock_write()
- manager.initialize_lock_store('lock-store')
+ manager.initialize_lock_store(self.get_transport('lock-store'))
self.knownFailure('not implemented yet.')
manager.track('b')
self.assertFalse(manager.is_locked('b'))
@@ -270,7 +276,7 @@
tree2.unlock()
tree2.lock_write()
# Share the lock store
- manager2.initialize_lock_store('lock-store')
+ manager2.initialize_lock_store(self.get_transport('lock-store'))
self.assertTrue(manager2.is_locked('b'))
self.assertTrue(manager2.is_locked('b/c'))
self.assertFalse(manager2.have_lock('b'))
More information about the bazaar-commits
mailing list