1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005-2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
so this is primarily useful for testing.
23
from __future__ import absolute_import
26
27
from stat import S_IFREG, S_IFDIR
27
28
from cStringIO import StringIO
30
34
from bzrlib.errors import (
33
37
InProcessTransport,
37
from bzrlib.trace import mutter
38
40
from bzrlib.transport import (
39
41
AppendBasedFileStream,
46
import bzrlib.urlutils as urlutils
61
59
self.st_mode = S_IFDIR | perms
64
class MemoryTransport(Transport):
62
class MemoryTransport(transport.Transport):
65
63
"""This is an in memory file system for transient data storage."""
67
65
def __init__(self, url=""):
82
80
def clone(self, offset=None):
83
81
"""See Transport.clone()."""
84
path = self._combine_paths(self._cwd, offset)
82
path = urlutils.URL._combine_paths(self._cwd, offset)
85
83
if len(path) == 0 or path[-1] != '/':
87
85
url = self._scheme + path
289
287
raise LockError('File %r already locked' % (self.path,))
290
288
self.transport._locks[self.path] = self
293
# Should this warn, or actually try to cleanup?
295
warnings.warn("MemoryLock %r not explicitly unlocked" % (self.path,))
298
290
def unlock(self):
299
291
del self.transport._locks[self.path]
300
292
self.transport = None
303
class MemoryServer(Server):
295
class MemoryServer(transport.Server):
304
296
"""Server for the MemoryTransport for testing with."""
307
"""See bzrlib.transport.Server.setUp."""
298
def start_server(self):
308
299
self._dirs = {'/':None}
311
302
self._scheme = "memory+%s:///" % id(self)
312
303
def memory_factory(url):
313
result = MemoryTransport(url)
304
from bzrlib.transport import memory
305
result = memory.MemoryTransport(url)
314
306
result._dirs = self._dirs
315
307
result._files = self._files
316
308
result._locks = self._locks
318
register_transport(self._scheme, memory_factory)
310
self._memory_factory = memory_factory
311
transport.register_transport(self._scheme, self._memory_factory)
321
"""See bzrlib.transport.Server.tearDown."""
313
def stop_server(self):
322
314
# unregister this server
315
transport.unregister_transport(self._scheme, self._memory_factory)
324
317
def get_url(self):
325
318
"""See bzrlib.transport.Server.get_url."""
326
319
return self._scheme
321
def get_bogus_url(self):
322
raise NotImplementedError
329
325
def get_test_permutations():
330
326
"""Return the permutations to be used in testing."""