def lock_write(self, relpath): """Lock the given file for exclusive (write) access. WARNING: many transports do not support this, so trying avoid using it :return: A lock object, which should be passed to Transport.unlock() """ raise errors.TransportNotPossible('http does not support lock_write()')
def put_file(self, relpath, f, mode=None): """Copy the file-like object into the location. :param relpath: Location to put the contents, relative to base. :param f: File-like object. """ raise errors.TransportNotPossible('http PUT not supported')
def _translate_error(self, resp, orig_path=None): """Raise an exception from a response""" if resp is None: what = None else: what = resp[0] if what == 'ok': return elif what == 'NoSuchFile': if orig_path is not None: error_path = orig_path else: error_path = resp[1] raise errors.NoSuchFile(error_path) elif what == 'error': raise errors.SmartProtocolError(unicode(resp[1])) elif what == 'FileExists': raise errors.FileExists(resp[1]) elif what == 'DirectoryNotEmpty': raise errors.DirectoryNotEmpty(resp[1]) elif what == 'ShortReadvError': raise errors.ShortReadvError(resp[1], int(resp[2]), int(resp[3]), int(resp[4])) elif what in ('UnicodeEncodeError', 'UnicodeDecodeError'): encoding = str(resp[1]) # encoding must always be a string val = resp[2] start = int(resp[3]) end = int(resp[4]) reason = str(resp[5]) # reason must always be a string if val.startswith('u:'): val = val[2:].decode('utf-8') elif val.startswith('s:'): val = val[2:].decode('base64') if what == 'UnicodeDecodeError': raise UnicodeDecodeError(encoding, val, start, end, reason) elif what == 'UnicodeEncodeError': raise UnicodeEncodeError(encoding, val, start, end, reason) elif what == "ReadOnlyError": raise errors.TransportNotPossible('readonly transport') elif what == "ReadError": if orig_path is not None: error_path = orig_path else: error_path = resp[1] raise errors.ReadError(error_path) elif what == "PermissionDenied": if orig_path is not None: error_path = orig_path else: error_path = resp[1] raise errors.PermissionDenied(error_path) else: raise errors.SmartProtocolError('unexpected smart server error: %r' % (resp,))
def copy_to(self, relpaths, other, mode=None, pb=None): """Copy a set of entries from self into another Transport. :param relpaths: A list/generator of entries to be copied. TODO: if other is LocalTransport, is it possible to do better than put(get())? """ # At this point HttpTransport might be able to check and see if # the remote location is the same, and rather than download, and # then upload, it could just issue a remote copy_this command. if isinstance(other, HttpTransportBase): raise errors.TransportNotPossible( 'http cannot be the target of copy_to()') else: return super(HttpTransportBase, self).\ copy_to(relpaths, other, mode=mode, pb=pb)
def _translate_io_exception(self, e, path, more_info='', failure_exc=PathError): """Translate a paramiko or IOError into a friendlier exception. :param e: The original exception :param path: The path in question when the error is raised :param more_info: Extra information that can be included, such as what was going on :param failure_exc: Paramiko has the super fun ability to raise completely opaque errors that just set "e.args = ('Failure',)" with no more information. If this parameter is set, it defines the exception to raise in these cases. """ # paramiko seems to generate detailless errors. self._translate_error(e, path, raise_generic=False) if getattr(e, 'args', None) is not None: if (e.args == ('No such file or directory', ) or e.args == ('No such file', )): raise NoSuchFile(path, str(e) + more_info) if (e.args == ('mkdir failed', ) or e.args[0].startswith('syserr: File exists')): raise FileExists(path, str(e) + more_info) # strange but true, for the paramiko server. if (e.args == ('Failure', )): raise failure_exc(path, str(e) + more_info) # Can be something like args = ('Directory not empty: # '/srv/bazaar.launchpad.net/blah...: ' # [Errno 39] Directory not empty',) if (e.args[0].startswith('Directory not empty: ') or getattr(e, 'errno', None) == errno.ENOTEMPTY): raise errors.DirectoryNotEmpty(path, str(e)) if e.args == ('Operation unsupported', ): raise errors.TransportNotPossible() mutter('Raising exception with args %s', e.args) if getattr(e, 'errno', None) is not None: mutter('Raising exception with errno %s', e.errno) raise e
def stat(self, relpath): """Return the stat information for a file. """ raise errors.TransportNotPossible('http does not support stat()')
def delete(self, relpath): """Delete the item at relpath""" raise errors.TransportNotPossible('http does not support delete()')
def move(self, rel_from, rel_to): """Move the item at rel_from to the location at rel_to""" raise errors.TransportNotPossible('http does not support move()')
def copy(self, rel_from, rel_to): """Copy the item at rel_from to the location at rel_to""" raise errors.TransportNotPossible('http does not support copy()')
def append_file(self, relpath, f, mode=None): """Append the text in the file-like object into the final location. """ raise errors.TransportNotPossible('http does not support append()')
def rmdir(self, relpath): """See Transport.rmdir.""" raise errors.TransportNotPossible('http does not support rmdir()')
def mkdir(self, relpath, mode=None): """Create a directory at the given path.""" raise errors.TransportNotPossible('http does not support mkdir()')
def test_translateTransportNotPossible(self): exception = bzr_errors.TransportNotPossible(self.getPathSegment()) self.do_translation_test(exception, filetransfer.FX_PERMISSION_DENIED)
def test_transport_not_possible(self): error = errors.TransportNotPossible('readonly', 'original error') self.assertEqualDiff( 'Transport operation not possible:' ' readonly original error', str(error))