def setinfo(self, path, info): # type: (Text, RawInfo) -> None """Set info on a resource. This method is the complement to `~fs.base.FS.getinfo` and is used to set info values on a resource. Arguments: path (str): Path to a resource on the filesystem. info (dict): Dictionary of resource info. Raises: fs.errors.ResourceNotFound: If ``path`` does not exist on the filesystem The ``info`` dict should be in the same format as the raw info returned by ``getinfo(file).raw``. Example: >>> details_info = {"details": { ... "modified": time.time() ... }} >>> my_fs.setinfo('file.txt', details_info) """ raise errors.ResourceReadOnly(path)
def makedir( self, path, # type: Text permissions=None, # type: Optional[Permissions] recreate=False, # type: bool ): # type: (...) -> SubFS[FS] """Make a directory. Arguments: path (str): Path to directory from root. permissions (~fs.permissions.Permissions, optional): a `Permissions` instance, or `None` to use default. recreate (bool): Set to `True` to avoid raising an error if the directory already exists (defaults to `False`). Returns: ~fs.subfs.SubFS: a filesystem whose root is the new directory. Raises: fs.errors.DirectoryExists: If the path already exists. fs.errors.ResourceNotFound: If the path is not found. """ raise errors.ResourceReadOnly(path)
def openbin( self, path, # type: Text mode="r", # type: Text buffering=-1, # type: int **options # type: Any ): # type: (...) -> BinaryIO """Open a binary file-like object. Arguments: path (str): A path on the filesystem. mode (str): Mode to open file (must be a valid non-text mode, defaults to *r*). Since this method only opens binary files, the ``b`` in the mode string is implied. buffering (int): Buffering policy (-1 to use default buffering, 0 to disable buffering, or any positive integer to indicate a buffer size). **options: keyword arguments for any additional information required by the filesystem (if any). Returns: io.IOBase: a *file-like* object. Raises: fs.errors.FileExpected: If the path is not a file. fs.errors.FileExists: If the file exists, and *exclusive mode* is specified (``x`` in the mode). fs.errors.ResourceNotFound: If the path does not exist. """ # TODO: handle BLOB properties here if mode not in ("r", "rb"): raise errors.ResourceReadOnly(path) _res = self._getresource(path) if not _res: raise errors.ResourceNotFound(path) if not isinstance(_res, io.RawIOBase): if not isinstance(_res, db.DocumentReference) and not isinstance( _res, db.DocumentSnapshot): raise TypeError("io stream expected") # CHECKME: someone wants to read the whole document, so let's give it to them as a json dump if isinstance(_res, db.DocumentReference): doc = _res.get() else: doc = _res info = doc.to_dict() # add other doc properties too? info.update(doc.__dict__) data = json.dumps(info, indent=2, default=lambda o: repr(o)) stream = io.BytesIO(data.encode("utf-8")) name = str(doc.id) + ".json" return make_stream(name, stream, "rb") return _res
def remove(self, path): # type: (Text) -> None """Remove a file from the filesystem. Arguments: path (str): Path of the file to remove. Raises: fs.errors.FileExpected: If the path is a directory. fs.errors.ResourceNotFound: If the path does not exist. """ raise errors.ResourceReadOnly(path)
def removedir(self, path): # type: (Text) -> None """Remove a directory from the filesystem. Arguments: path (str): Path of the directory to remove. Raises: fs.errors.DirectoryNotEmpty: If the directory is not empty ( see `~fs.base.FS.removetree` for a way to remove the directory contents.). fs.errors.DirectoryExpected: If the path does not refer to a directory. fs.errors.ResourceNotFound: If no resource exists at the given path. fs.errors.RemoveRootError: If an attempt is made to remove the root directory (i.e. ``'/'``) """ raise errors.ResourceReadOnly(path)