~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/local.py

  • Committer: Robert Collins
  • Date: 2006-01-02 22:37:32 UTC
  • mfrom: (1185.50.33 bzr-jam-integration)
  • Revision ID: robertc@robertcollins.net-20060102223732-d5221b37ff0f7888
Merge in John Meinels integration branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
from bzrlib.trace import mutter
28
28
from bzrlib.transport import Transport
29
 
from bzrlib.osutils import abspath
 
29
from bzrlib.osutils import abspath, realpath, normpath, pathjoin, rename
30
30
 
31
31
 
32
32
class LocalTransport(Transport):
38
38
            base = base[7:]
39
39
        # realpath is incompatible with symlinks. When we traverse
40
40
        # up we might be able to normpath stuff. RBC 20051003
41
 
        super(LocalTransport, self).__init__(
42
 
            os.path.normpath(abspath(base)))
 
41
        super(LocalTransport, self).__init__(normpath(abspath(base)))
43
42
 
44
43
    def should_cache(self):
45
44
        return False
59
58
        This can be supplied with a string or a list
60
59
        """
61
60
        assert isinstance(relpath, basestring), (type(relpath), relpath)
62
 
        return os.path.join(self.base, urllib.unquote(relpath))
 
61
        return pathjoin(self.base, urllib.unquote(relpath))
63
62
 
64
63
    def relpath(self, abspath):
65
64
        """Return the local path portion from a given absolute path.
83
82
        except (IOError, OSError),e:
84
83
            self._translate_error(e, path)
85
84
 
86
 
    def put(self, relpath, f):
 
85
    def put(self, relpath, f, mode=None):
87
86
        """Copy the file-like or string object into the location.
88
87
 
89
88
        :param relpath: Location to put the contents, relative to base.
94
93
        path = relpath
95
94
        try:
96
95
            path = self.abspath(relpath)
97
 
            fp = AtomicFile(path, 'wb')
 
96
            fp = AtomicFile(path, 'wb', new_mode=mode)
98
97
        except (IOError, OSError),e:
99
98
            self._translate_error(e, path)
100
99
        try:
115
114
            else:
116
115
                yield relpath
117
116
 
118
 
    def mkdir(self, relpath):
 
117
    def mkdir(self, relpath, mode=None):
119
118
        """Create a directory at the given path."""
120
119
        path = relpath
121
120
        try:
122
121
            path = self.abspath(relpath)
123
122
            os.mkdir(path)
 
123
            if mode is not None:
 
124
                os.chmod(path, mode)
124
125
        except (IOError, OSError),e:
125
126
            self._translate_error(e, path)
126
127
 
148
149
        path_to = self.abspath(rel_to)
149
150
 
150
151
        try:
151
 
            os.rename(path_from, path_to)
 
152
            rename(path_from, path_to)
152
153
        except (IOError, OSError),e:
153
154
            # TODO: What about path_to?
154
155
            self._translate_error(e, path_from)
163
164
            # TODO: What about path_to?
164
165
            self._translate_error(e, path)
165
166
 
166
 
    def copy_to(self, relpaths, other, pb=None):
 
167
    def copy_to(self, relpaths, other, mode=None, pb=None):
167
168
        """Copy a set of entries from self into another Transport.
168
169
 
169
170
        :param relpaths: A list/generator of entries to be copied.
179
180
            for path in relpaths:
180
181
                self._update_pb(pb, 'copy-to', count, total)
181
182
                try:
182
 
                    shutil.copy(self.abspath(path), other.abspath(path))
 
183
                    mypath = self.abspath(path)
 
184
                    otherpath = other.abspath(path)
 
185
                    shutil.copy(mypath, otherpath)
 
186
                    if mode is not None:
 
187
                        os.chmod(otherpath, mode)
183
188
                except (IOError, OSError),e:
184
189
                    self._translate_error(e, path)
185
190
                count += 1
186
191
            return count
187
192
        else:
188
 
            return super(LocalTransport, self).copy_to(relpaths, other, pb=pb)
 
193
            return super(LocalTransport, self).copy_to(relpaths, other, mode=mode, pb=pb)
189
194
 
190
195
    def listable(self):
191
196
        """See Transport.listable."""