Beispiel #1
0
    def open_file(self, path, mode):
        path = self.realpath(path=path)

        parent = path.parent()
        contents = self._tree.get(parent)
        if contents is None:
            raise exceptions.FileNotFound(path)

        if mode == "w" or mode == "wb":
            file = _BytesIOIsTerrible()
            self._tree = self._tree.set(parent, contents.set(path, file))
            return file

        file = contents.get(path)

        if mode == "a" or mode == "ab":
            if file is None:
                combined = _BytesIOIsTerrible()
            else:
                combined = _BytesIOIsTerrible()
                combined.write(file._hereismyvalue)
            self._tree = self._tree.set(parent, contents.set(path, combined))
            return combined
        elif file is None:
            raise exceptions.FileNotFound(path)
        else:
            return BytesIO(file._hereismyvalue)
Beispiel #2
0
    def remove_file(self, path):
        parent = path.parent()
        contents = self._tree.get(parent)
        if contents is None:
            raise exceptions.FileNotFound(path)

        if path not in contents:
            raise exceptions.FileNotFound(path)

        self._tree = self._tree.set(parent, contents.remove(path))
Beispiel #3
0
 def _tree_with(self, path):
     parent = path.parent()
     if not self.exists(path=parent):
         raise exceptions.FileNotFound(parent)
     elif not self.is_dir(path=parent):
         raise exceptions.NotADirectory(parent)
     return self._tree.set(parent, self._tree[parent].set(path, None))
Beispiel #4
0
 def remove(self, path):
     if self.is_link(path=path):
         self._links = self._links.remove(path)
     elif path not in self._tree:
         raise exceptions.FileNotFound(path)
     else:
         self._tree = self._tree.remove(path)
Beispiel #5
0
def _remove_file(fs, path):
    try:
        os.remove(str(path))
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        raise
Beispiel #6
0
def _remove_empty_directory(fs, path):
    try:
        os.rmdir(str(path))
    except (IOError, OSError) as error:
        if error.errno == exceptions.DirectoryNotEmpty.errno:
            raise exceptions.DirectoryNotEmpty(path)
        elif error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        raise
Beispiel #7
0
def _list_directory(fs, path):
    try:
        return os.listdir(str(path))
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        elif error.errno == exceptions.NotADirectory.errno:
            raise exceptions.NotADirectory(path)
        raise
Beispiel #8
0
def _create_directory(fs, path):
    try:
        os.mkdir(str(path))
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path.parent())
        elif error.errno == exceptions.FileExists.errno:
            raise exceptions.FileExists(path)
        raise
Beispiel #9
0
 def open_file(self, path, mode):
     if mode.read:
         raise exceptions.FileNotFound(path)
     else:
         file = self._parent[self._name] = _File(
             name=self._name,
             parent=self._parent,
         )
         return file.open_file(path=path, mode=mode)
Beispiel #10
0
def _open_file(fs, path, mode):
    try:
        return open(str(path), mode)
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        elif error.errno == exceptions.SymbolicLoop.errno:
            raise exceptions.SymbolicLoop(path)
        raise
Beispiel #11
0
    def create_directory(self, path):
        if self.exists(path=path):
            raise exceptions.FileExists(path)

        parent = path.parent()
        if not self.exists(path=parent):
            raise exceptions.FileNotFound(parent)

        self._tree = self._tree.set(path, pmap())
Beispiel #12
0
    def list_directory(self, path):
        if self.is_file(path=path):
            raise exceptions.NotADirectory(path)
        elif path not in self._tree:
            raise exceptions.FileNotFound(path)

        # FIXME: Inefficient
        return pset(child.basename() for child in self._tree[path]) | pset(
            subdirectory.basename() for subdirectory in self._tree
            if subdirectory.parent() == path and subdirectory != path)
Beispiel #13
0
def _lstat(fs, path):
    try:
        return os.lstat(str(path))
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        elif error.errno == exceptions.NotADirectory.errno:
            raise exceptions.NotADirectory(path)
        elif error.errno == exceptions.SymbolicLoop.errno:
            raise exceptions.SymbolicLoop(path)
        raise
Beispiel #14
0
def _link(fs, source, to):
    try:
        os.symlink(str(source), str(to))
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(to.parent())
        elif error.errno == exceptions.NotADirectory.errno:
            raise exceptions.NotADirectory(to.parent())
        elif error.errno == exceptions.FileExists.errno:
            raise exceptions.FileExists(to)
        raise
Beispiel #15
0
 def create_directory(self, path, with_parents):
     if with_parents:
         parent = self._parent.create_directory(
             path=path,
             with_parents=with_parents,
         )
         directory = parent[self._name].create_directory(
             path=path,
             with_parents=False,
         )
         return directory
     raise exceptions.FileNotFound(path.parent())
Beispiel #16
0
    def create_file(self, path):
        if self.exists(path=path) or self.is_link(path=path):
            raise exceptions.FileExists(path)

        path = self.realpath(path=path)
        parent = path.parent()
        contents = self._tree.get(parent)
        if contents is None:
            raise exceptions.FileNotFound(path)
        file = _BytesIOIsTerrible()
        self._tree = self._tree.set(parent, contents.set(path, file))
        return file
Beispiel #17
0
def _create_file(fs, path):
    try:
        fd = os.open(str(path), _CREATE_FLAGS)
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        elif error.errno == exceptions.FileExists.errno:
            raise exceptions.FileExists(path)
        elif error.errno == exceptions.SymbolicLoop.errno:
            raise exceptions.SymbolicLoop(path.parent())
        raise

    return os.fdopen(fd, "w+b")
Beispiel #18
0
def _open_file(fs, path, mode):
    mode = common._parse_mode(mode)

    try:
        return io.open(str(path), mode.io_open_string())
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        elif error.errno == exceptions.IsADirectory.errno:
            raise exceptions.IsADirectory(path)
        elif error.errno == exceptions.NotADirectory.errno:
            raise exceptions.NotADirectory(path)
        elif error.errno == exceptions.SymbolicLoop.errno:
            raise exceptions.SymbolicLoop(path)
        raise
Beispiel #19
0
def _remove_file(fs, path):
    try:
        os.remove(str(path))
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        elif error.errno == exceptions.IsADirectory.errno:
            raise exceptions.IsADirectory(path)
        elif error.errno == exceptions.NotADirectory.errno:
            raise exceptions.NotADirectory(path)
        elif error.errno == exceptions.PermissionError.errno:
            raise exceptions.PermissionError(path)
        elif error.errno == exceptions.SymbolicLoop.errno:
            raise exceptions.SymbolicLoop(path.parent())
        raise
Beispiel #20
0
def _readlink(fs, path):
    try:
        value = os.readlink(str(path))
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path)
        elif error.errno == exceptions.NotADirectory.errno:
            raise exceptions.NotADirectory(path)
        elif error.errno == exceptions.NotASymlink.errno:
            raise exceptions.NotASymlink(path)
        elif error.errno == exceptions.SymbolicLoop.errno:
            raise exceptions.SymbolicLoop(path)
        raise
    else:
        return Path.from_string(value)
Beispiel #21
0
def _create_directory(fs, path, with_parents):
    try:
        if with_parents:
            os.makedirs(str(path))
        else:
            os.mkdir(str(path))
    except (IOError, OSError) as error:
        if error.errno == exceptions.FileExists.errno:
            raise exceptions.FileExists(path)
        elif error.errno == exceptions.FileNotFound.errno:
            raise exceptions.FileNotFound(path.parent())
        elif error.errno == exceptions.NotADirectory.errno:
            raise exceptions.NotADirectory(path.parent())
        elif error.errno == exceptions.SymbolicLoop.errno:
            raise exceptions.SymbolicLoop(path.parent())
        raise
Beispiel #22
0
 def open_file(self, path, mode):
     raise exceptions.FileNotFound(path)
Beispiel #23
0
 def remove_empty_directory(self, path):
     raise exceptions.FileNotFound(path)
Beispiel #24
0
 def list_directory(self, path):
     raise exceptions.FileNotFound(path)
Beispiel #25
0
 def create_file(self, path):
     raise exceptions.FileNotFound(path)
Beispiel #26
0
 def remove_file(self, path):
     raise exceptions.FileNotFound(path)
Beispiel #27
0
 def stat(self, path):
     raise exceptions.FileNotFound(path)
Beispiel #28
0
 def readlink(self, path):
     raise exceptions.FileNotFound(path)
Beispiel #29
0
 def link(self, source, to, fs, state):
     raise exceptions.FileNotFound(to.parent())