def process_result(result): branch, trailing = result if branch is None: raise NoSuchFile(virtual_url_fragment) else: return self._transport_dispatch.makeTransport( (BRANCH_TRANSPORT, dict(id=branch.id), trailing[1:]))
def get(self, relpath): """See Transport.get().""" _abspath = self._abspath(relpath) if not _abspath in self._files: if _abspath in self._dirs: return LateReadError(relpath) else: raise NoSuchFile(relpath) return StringIO(self._files[_abspath][0])
def fetchFromArchive(self, target_path): """Fetch the foreign tree for `source_details` from the archive.""" local_name = 'foreign_tree.tar.gz' if not self.import_data_store.fetch(local_name): raise NoSuchFile(local_name) extract_tarball(local_name, target_path) tree = self._getForeignTree(target_path) tree.update() return tree
def stat(self, relpath): """See Transport.stat().""" _abspath = self._abspath(relpath) if _abspath in self._files: return MemoryStat(len(self._files[_abspath][0]), False, self._files[_abspath][1]) elif _abspath in self._dirs: return MemoryStat(0, True, self._dirs[_abspath]) else: raise NoSuchFile(_abspath)
def _translateError(self, failure): """Translate 'failure' into something suitable for a transport. This method is called as an errback by `_call`. Use it to translate errors from the server into something that users of the transport might expect. This could include translating vfs-specific errors into bzrlib errors (e.g. "couldn\'t translate" into `NoSuchFile`) or translating underlying paths into virtual paths. :param failure: A `twisted.python.failure.Failure`. """ failure.trap(TranslationError) return Failure(NoSuchFile(failure.value.virtual_url_fragment))
def rmdir(self, relpath): """See Transport.rmdir.""" _abspath = self._abspath(relpath) if _abspath in self._files: self._translate_error(IOError(errno.ENOTDIR, relpath), relpath) for path in self._files: if path.startswith(_abspath + '/'): self._translate_error(IOError(errno.ENOTEMPTY, relpath), relpath) for path in self._dirs: if path.startswith(_abspath + '/') and path != _abspath: self._translate_error(IOError(errno.ENOTEMPTY, relpath), relpath) if not _abspath in self._dirs: raise NoSuchFile(relpath) del self._dirs[_abspath]
def list_dir(self, relpath): """See Transport.list_dir().""" _abspath = self._abspath(relpath) if _abspath != '/' and _abspath not in self._dirs: raise NoSuchFile(relpath) result = [] if not _abspath.endswith('/'): _abspath += '/' for path_group in self._files, self._dirs: for path in path_group: if path.startswith(_abspath): trailing = path[len(_abspath):] if trailing and '/' not in trailing: result.append(trailing) return map(urlutils.escape, result)
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 delete(self, relpath): """See Transport.delete().""" _abspath = self._abspath(relpath) if not _abspath in self._files: raise NoSuchFile(relpath) del self._files[_abspath]
def _check_parent(self, _abspath): dir = os.path.dirname(_abspath) if dir != '/': if not dir in self._dirs: raise NoSuchFile(_abspath)
def get(self, path): raise NoSuchFile(path)
def unknown_transport_type(fail): fail.trap(UnknownTransportType) return failure.Failure(NoSuchFile(virtual_url_fragment))
def path_not_translated(fail): trap_fault(fail, faults.PathTranslationError, faults.PermissionDenied) return failure.Failure(NoSuchFile(virtual_url_fragment))