Example #1
0
File: fs.py Project: trallard/dvc
def copyfile(src, dest, no_progress_bar=False, name=None):
    """Copy file with progress bar"""
    from dvc.exceptions import DvcException
    from dvc.progress import Tqdm
    from dvc.system import System

    src = fspath_py35(src)
    dest = fspath_py35(dest)

    name = name if name else os.path.basename(dest)
    total = os.stat(src).st_size

    if os.path.isdir(dest):
        dest = os.path.join(dest, os.path.basename(src))

    try:
        System.reflink(src, dest)
    except DvcException:
        with open(src, "rb") as fsrc, open(dest, "wb+") as fdest:
            with Tqdm.wrapattr(
                    fdest,
                    "write",
                    desc=name,
                    disable=no_progress_bar,
                    total=total,
                    bytes=True,
            ) as fdest_wrapped:
                while True:
                    buf = fsrc.read(LOCAL_CHUNK_SIZE)
                    if not buf:
                        break
                    fdest_wrapped.write(buf)
Example #2
0
 def reflink(self, from_info, to_info):
     tmp_info = to_info.parent / tmp_fname("")
     System.reflink(from_info, tmp_info)
     # NOTE: reflink has its own separate inode, so you can set permissions
     # that are different from the source.
     os.chmod(tmp_info, self.file_mode)
     os.rename(tmp_info, to_info)
Example #3
0
def copyfile(src, dest, no_progress_bar=False, name=None):
    """Copy file with progress bar"""
    from dvc.exceptions import DvcException
    from dvc.progress import progress
    from dvc.system import System

    copied = 0
    name = name if name else os.path.basename(dest)
    total = os.stat(src).st_size

    if os.path.isdir(dest):
        dest = os.path.join(dest, os.path.basename(src))

    try:
        System.reflink(src, dest)
    except DvcException:
        with open(src, "rb") as fsrc, open(dest, "wb+") as fdest:
            while True:
                buf = fsrc.read(LOCAL_CHUNK_SIZE)
                if not buf:
                    break
                fdest.write(buf)
                copied += len(buf)
                if not no_progress_bar:
                    progress.update_target(name, copied, total)

    if not no_progress_bar:
        progress.finish_target(name)
Example #4
0
def copyfile(src, dest, callback=None, no_progress_bar=False, name=None):
    """Copy file with progress bar"""
    name = name if name else os.path.basename(dest)
    total = os.stat(src).st_size

    if os.path.isdir(dest):
        dest = os.path.join(dest, os.path.basename(src))

    if callback:
        callback.set_size(total)

    try:
        System.reflink(src, dest)
    except OSError:
        from dvc.fs._callback import tdqm_or_callback_wrapped

        with open(src, "rb") as fsrc, open(dest, "wb+") as fdest:
            with tdqm_or_callback_wrapped(
                fdest,
                "write",
                total,
                callback=callback,
                disable=no_progress_bar,
                desc=name,
            ) as wrapped:
                while True:
                    buf = fsrc.read(LOCAL_CHUNK_SIZE)
                    if not buf:
                        break
                    wrapped.write(buf)

    if callback:
        callback.absolute_update(total)
Example #5
0
File: fs.py Project: LuisFalva/dvc
def copyfile(src, dest, no_progress_bar=False, name=None):
    """Copy file with progress bar"""
    from dvc.progress import Tqdm

    name = name if name else os.path.basename(dest)
    total = os.stat(src).st_size

    if os.path.isdir(dest):
        dest = os.path.join(dest, os.path.basename(src))

    try:
        System.reflink(src, dest)
        # NOTE: reflink has a new inode, but has the same mode as the src,
        # so we need to chmod it to look like a normal copy.
        os.chmod(dest, 0o666 & ~umask)
    except DvcException:
        with open(src, "rb") as fsrc, open(dest, "wb+") as fdest:
            with Tqdm.wrapattr(
                    fdest,
                    "write",
                    desc=name,
                    disable=no_progress_bar,
                    total=total,
                    bytes=True,
            ) as fdest_wrapped:
                while True:
                    buf = fsrc.read(LOCAL_CHUNK_SIZE)
                    if not buf:
                        break
                    fdest_wrapped.write(buf)
Example #6
0
File: local.py Project: kcak11/dvc
 def reflink(self, from_info, to_info):
     System.reflink(from_info, to_info)
Example #7
0
 def reflink(self, path1, path2):
     return System.reflink(path1, path2)