/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

  • Committer: Martin Pool
  • Date: 2006-11-02 10:20:19 UTC
  • mfrom: (2114 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2119.
  • Revision ID: mbp@sourcefrog.net-20061102102019-9a5a02f485dff6f6
merge bzr.dev and reconcile several changes, also some test fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
This is a fairly thin wrapper on regular file IO.
20
20
"""
21
21
 
 
22
import os
 
23
from stat import ST_MODE, S_ISDIR, ST_SIZE, S_IMODE
 
24
import sys
 
25
 
 
26
from bzrlib.lazy_import import lazy_import
 
27
lazy_import(globals(), """
22
28
import errno
23
 
import os
24
29
import shutil
25
 
import sys
26
 
from stat import ST_MODE, S_ISDIR, ST_SIZE, S_IMODE
27
 
import tempfile
28
30
 
29
31
from bzrlib import (
30
32
    atomicfile,
31
33
    osutils,
32
34
    urlutils,
 
35
    symbol_versioning,
33
36
    )
34
 
from bzrlib.osutils import (abspath, realpath, normpath, pathjoin, rename,
35
 
                            check_legal_path, rmtree)
36
 
from bzrlib.symbol_versioning import warn
37
37
from bzrlib.trace import mutter
 
38
""")
 
39
 
38
40
from bzrlib.transport import Transport, Server
39
41
 
40
42
 
48
50
    def __init__(self, base):
49
51
        """Set the base path where files will be stored."""
50
52
        if not base.startswith('file://'):
51
 
            warn("Instantiating LocalTransport with a filesystem path"
 
53
            symbol_versioning.warn(
 
54
                "Instantiating LocalTransport with a filesystem path"
52
55
                " is deprecated as of bzr 0.8."
53
56
                " Please use bzrlib.transport.get_transport()"
54
57
                " or pass in a file:// url.",
91
94
        assert isinstance(relpath, basestring), (type(relpath), relpath)
92
95
        # jam 20060426 Using normpath on the real path, because that ensures
93
96
        #       proper handling of stuff like
94
 
        path = normpath(pathjoin(self._local_base, urlutils.unescape(relpath)))
 
97
        path = osutils.normpath(osutils.pathjoin(
 
98
                    self._local_base, urlutils.unescape(relpath)))
95
99
        return urlutils.local_path_to_url(path)
96
100
 
97
101
    def local_abspath(self, relpath):
145
149
        path = relpath
146
150
        try:
147
151
            path = self._abspath(relpath)
148
 
            check_legal_path(path)
 
152
            osutils.check_legal_path(path)
149
153
            fp = atomicfile.AtomicFile(path, 'wb', new_mode=mode)
150
154
        except (IOError, OSError),e:
151
155
            self._translate_error(e, path)
165
169
        path = relpath
166
170
        try:
167
171
            path = self._abspath(relpath)
168
 
            check_legal_path(path)
 
172
            osutils.check_legal_path(path)
169
173
            fp = atomicfile.AtomicFile(path, 'wb', new_mode=mode)
170
174
        except (IOError, OSError),e:
171
175
            self._translate_error(e, path)
366
370
 
367
371
        try:
368
372
            # this version will delete the destination if necessary
369
 
            rename(path_from, path_to)
 
373
            osutils.rename(path_from, path_to)
370
374
        except (IOError, OSError),e:
371
375
            # TODO: What about path_to?
372
376
            self._translate_error(e, path_from)
470
474
            return True
471
475
 
472
476
 
473
 
class LocalRelpathServer(Server):
474
 
    """A pretend server for local transports, using relpaths."""
475
 
 
476
 
    def get_url(self):
477
 
        """See Transport.Server.get_url."""
478
 
        return "."
479
 
 
480
 
 
481
 
class LocalAbspathServer(Server):
482
 
    """A pretend server for local transports, using absolute paths."""
483
 
 
484
 
    def get_url(self):
485
 
        """See Transport.Server.get_url."""
486
 
        return os.path.abspath("")
487
 
 
488
 
 
489
477
class LocalURLServer(Server):
490
 
    """A pretend server for local transports, using file:// urls."""
 
478
    """A pretend server for local transports, using file:// urls.
 
479
    
 
480
    Of course no actual server is required to access the local filesystem, so
 
481
    this just exists to tell the test code how to get to it.
 
482
    """
491
483
 
492
484
    def get_url(self):
493
485
        """See Transport.Server.get_url."""
496
488
 
497
489
def get_test_permutations():
498
490
    """Return the permutations to be used in testing."""
499
 
    return [(LocalTransport, LocalRelpathServer),
500
 
            (LocalTransport, LocalAbspathServer),
 
491
    return [
501
492
            (LocalTransport, LocalURLServer),
502
493
            ]