/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: Robert Collins
  • Date: 2006-06-09 09:04:53 UTC
  • mfrom: (1755.2.1 add)
  • mto: (1755.1.2 integration)
  • mto: This revision was merged to the branch mainline in revision 1757.
  • Revision ID: robertc@robertcollins.net-20060609090453-10e94172dc5f670b
MergeĀ currentĀ head.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import sys
24
24
from stat import ST_MODE, S_ISDIR, ST_SIZE
25
25
import tempfile
26
 
import urllib
27
26
 
 
27
from bzrlib.osutils import (abspath, realpath, normpath, pathjoin, rename, 
 
28
                            check_legal_path, rmtree)
 
29
from bzrlib.symbol_versioning import warn
28
30
from bzrlib.trace import mutter
29
31
from bzrlib.transport import Transport, Server
30
 
from bzrlib.osutils import (abspath, realpath, normpath, pathjoin, rename, 
31
 
                            check_legal_path, rmtree)
 
32
import bzrlib.urlutils as urlutils
32
33
 
33
34
 
34
35
class LocalTransport(Transport):
36
37
 
37
38
    def __init__(self, base):
38
39
        """Set the base path where files will be stored."""
39
 
        if base.startswith('file://'):
40
 
            base = base[len('file://'):]
41
 
        # realpath is incompatible with symlinks. When we traverse
42
 
        # up we might be able to normpath stuff. RBC 20051003
43
 
        base = normpath(abspath(base))
 
40
        if not base.startswith('file://'):
 
41
            warn("Instantiating LocalTransport with a filesystem path"
 
42
                " is deprecated as of bzr 0.8."
 
43
                " Please use bzrlib.transport.get_transport()"
 
44
                " or pass in a file:// url.",
 
45
                 DeprecationWarning,
 
46
                 stacklevel=2
 
47
                 )
 
48
            base = urlutils.local_path_to_url(base)
44
49
        if base[-1] != '/':
45
50
            base = base + '/'
46
51
        super(LocalTransport, self).__init__(base)
 
52
        self._local_base = urlutils.local_path_from_url(base)
47
53
 
48
54
    def should_cache(self):
49
55
        return False
65
71
         - relative_reference does not contain '..'
66
72
         - relative_reference is url escaped.
67
73
        """
68
 
        return pathjoin(self.base, urllib.unquote(relative_reference))
 
74
        return pathjoin(self._local_base, urlutils.unescape(relative_reference))
69
75
 
70
76
    def abspath(self, relpath):
71
77
        """Return the full url to the given relative URL."""
72
78
        # TODO: url escape the result. RBC 20060523.
73
79
        assert isinstance(relpath, basestring), (type(relpath), relpath)
74
 
        result = normpath(pathjoin(self.base, urllib.unquote(relpath)))
75
 
        #if result[-1] != '/':
76
 
        #    result += '/'
77
 
        return result
 
80
        # jam 20060426 Using normpath on the real path, because that ensures
 
81
        #       proper handling of stuff like
 
82
        path = normpath(pathjoin(self._local_base, urlutils.unescape(relpath)))
 
83
        return urlutils.local_path_to_url(path)
 
84
 
 
85
    def local_abspath(self, relpath):
 
86
        """Transform the given relative path URL into the actual path on disk
 
87
 
 
88
        This function only exists for the LocalTransport, since it is
 
89
        the only one that has direct local access.
 
90
        This is mostly for stuff like WorkingTree which needs to know
 
91
        the local working directory.
 
92
        
 
93
        This function is quite expensive: it calls realpath which resolves
 
94
        symlinks.
 
95
        """
 
96
        absurl = self.abspath(relpath)
 
97
        # mutter(u'relpath %s => base: %s, absurl %s', relpath, self.base, absurl)
 
98
        return urlutils.local_path_from_url(absurl)
78
99
 
79
100
    def relpath(self, abspath):
80
101
        """Return the local path portion from a given absolute path.
81
102
        """
82
 
        from bzrlib.osutils import relpath, strip_trailing_slash
83
103
        if abspath is None:
84
104
            abspath = u'.'
85
105
 
86
 
        return relpath(strip_trailing_slash(self.base), 
87
 
                       strip_trailing_slash(abspath))
 
106
        return urlutils.file_relpath(
 
107
            urlutils.strip_trailing_slash(self.base), 
 
108
            urlutils.strip_trailing_slash(abspath))
88
109
 
89
110
    def has(self, relpath):
90
111
        return os.access(self._abspath(relpath), os.F_OK)
238
259
        """
239
260
        path = self._abspath(relpath)
240
261
        try:
241
 
            return [urllib.quote(entry) for entry in os.listdir(path)]
 
262
            return [urlutils.escape(entry) for entry in os.listdir(path)]
242
263
        except (IOError, OSError), e:
243
264
            self._translate_error(e, path)
244
265
 
328
349
 
329
350
    def get_url(self):
330
351
        """See Transport.Server.get_url."""
331
 
        # FIXME: \ to / on windows
332
 
        return "file://%s" % os.path.abspath("")
 
352
        return urlutils.local_path_to_url('')
333
353
 
334
354
 
335
355
def get_test_permutations():