示例#1
0
    def copy(self,
             lpath,
             rpath,
             recursive=False,
             callback=_DEFAULT_CALLBACK,
             **kwargs):
        """ 
        This method copies the contents of the local source directory to the target directory.
        This is different from the fsspec's put() because it does not copy the source folder 
        to the target directory in the case when target directory already exists.
        """

        from fsspec.implementations.local import LocalFileSystem, make_path_posix
        from fsspec.utils import other_paths

        rpath = (self.fs._strip_protocol(rpath) if isinstance(rpath, str) else
                 [self.fs._strip_protocol(p) for p in rpath])
        if isinstance(lpath, str):
            lpath = make_path_posix(lpath)
        fs = LocalFileSystem()
        lpaths = fs.expand_path(lpath, recursive=recursive)
        rpaths = other_paths(lpaths, rpath)

        callback.set_size(len(rpaths))
        for lpath, rpath in callback.wrap(zip(lpaths, rpaths)):
            callback.branch(lpath, rpath, kwargs)
            self.fs.put_file(lpath, rpath, **kwargs)
示例#2
0
    def put(self, from_path: str, to_path: str, recursive: bool = False):
        fs = self.get_filesystem(to_path)
        if recursive:
            from_path, to_path = self.recursive_paths(from_path, to_path)
            # BEGIN HACK!
            # Once https://github.com/intake/filesystem_spec/issues/724 is fixed, delete the special recursive handling
            from fsspec.implementations.local import LocalFileSystem
            from fsspec.utils import other_paths

            lfs = LocalFileSystem()
            lpaths = lfs.expand_path(from_path, recursive=recursive)
            rpaths = other_paths(lpaths, to_path)
            for l, r in zip(lpaths, rpaths):
                fs.put_file(l, r)
            return
            # END OF HACK!!
        return fs.put(from_path, to_path, recursive=recursive)