Пример #1
0
def test_copyfile(path, tmp_dir):
    tmp_dir.gen(
        {
            "foo": "foo content",
            "bar": "bar content",
            "file": "file content",
            "dir": {},
        }
    )
    src = "foo"
    dest = path
    src_info = PathInfo("bar")
    dest_info = PathInfo(path)

    copyfile(src, dest)
    if os.path.isdir(dest):
        assert filecmp.cmp(
            src, os.path.join(dest, os.path.basename(src)), shallow=False
        )
    else:
        assert filecmp.cmp(src, dest, shallow=False)

    copyfile(src_info, dest_info)
    if os.path.isdir(dest_info):
        assert filecmp.cmp(
            src_info,
            os.path.join(dest_info, os.path.basename(src_info)),
            shallow=False,
        )
    else:
        assert filecmp.cmp(src_info, dest_info, shallow=False)
Пример #2
0
 def copy(self, from_info, to_info):
     tmp_info = to_info.parent / tmp_fname("")
     try:
         copyfile(from_info, tmp_info)
         os.rename(tmp_info, to_info)
     except Exception:
         self.remove(tmp_info)
         raise
Пример #3
0
 def copy(self, path1, path2, recursive=False, on_error=None, **kwargs):
     tmp_info = os.path.join(self._parent(path2), tmp_fname(""))
     try:
         copyfile(path1, tmp_info)
         os.rename(tmp_info, path2)
     except Exception:
         self.rm_file(tmp_info)
         raise
Пример #4
0
 def copy(self, from_info, to_info):
     tmp_info = self.path.join(self.path.parent(to_info), tmp_fname(""))
     try:
         copyfile(from_info, tmp_info)
         os.rename(tmp_info, to_info)
     except Exception:
         self.remove(tmp_info)
         raise
Пример #5
0
 def put_file(self,
              from_file,
              to_info,
              callback=DEFAULT_CALLBACK,
              **kwargs):
     makedirs(to_info.parent, exist_ok=True)
     tmp_file = tmp_fname(to_info)
     copyfile(from_file, tmp_file, callback=callback)
     os.replace(tmp_file, to_info)
Пример #6
0
 def _download(from_info,
               to_file,
               name=None,
               no_progress_bar=False,
               **_kwargs):
     copyfile(from_info,
              to_file,
              no_progress_bar=no_progress_bar,
              name=name)
Пример #7
0
 def put_file(self,
              from_file,
              to_info,
              callback=DEFAULT_CALLBACK,
              **kwargs):
     parent = self.path.parent(to_info)
     makedirs(parent, exist_ok=True)
     tmp_file = self.path.join(parent, tmp_fname())
     copyfile(from_file, tmp_file, callback=callback)
     os.replace(tmp_file, to_info)
Пример #8
0
    def _upload(
        self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs
    ):
        makedirs(to_info.parent, exist_ok=True)

        tmp_file = tmp_fname(to_info)
        copyfile(
            from_file, tmp_file, name=name, no_progress_bar=no_progress_bar
        )
        os.rename(tmp_file, fspath_py35(to_info))
Пример #9
0
def test_copyfile(tmp_dir):
    src = "file1"
    dest = "file2"
    dest_dir = "testdir"

    tmp_dir.gen(src, "file1contents")

    os.mkdir(dest_dir)

    copyfile(src, dest)
    assert (tmp_dir / dest).read_text() == "file1contents"

    copyfile(src, dest_dir)
    assert (tmp_dir / dest_dir / src).read_text() == "file1contents"
Пример #10
0
def test_copyfile(path, tmp_dir):
    tmp_dir.gen({
        "foo": "foo content",
        "file": "file content",
        "dir": {},
    })
    src = "foo"
    dest = path

    copyfile(src, dest)
    if os.path.isdir(dest):
        assert filecmp.cmp(src,
                           os.path.join(dest, os.path.basename(src)),
                           shallow=False)
    else:
        assert filecmp.cmp(src, dest, shallow=False)
Пример #11
0
    def _upload(
        self,
        from_file,
        to_info,
        name=None,
        no_progress_bar=False,
        file_mode=None,
        **_kwargs,
    ):
        makedirs(to_info.parent, exist_ok=True)

        tmp_file = tmp_fname(to_info)
        copyfile(
            from_file, tmp_file, name=name, no_progress_bar=no_progress_bar
        )

        if file_mode is not None:
            self.chmod(tmp_file, file_mode)
        os.replace(tmp_file, to_info)
Пример #12
0
    def _unprotect_file(path):
        if System.is_symlink(path) or System.is_hardlink(path):
            logger.debug("Unprotecting '{}'".format(path))
            tmp = os.path.join(os.path.dirname(path), "." + uuid())

            # The operations order is important here - if some application
            # would access the file during the process of copyfile then it
            # would get only the part of file. So, at first, the file should be
            # copied with the temporary name, and then original file should be
            # replaced by new.
            copyfile(path, tmp, name="Unprotecting '{}'".format(relpath(path)))
            remove(path)
            os.rename(tmp, path)

        else:
            logger.debug("Skipping copying for '{}', since it is not "
                         "a symlink or a hardlink.".format(path))

        os.chmod(path, os.stat(path).st_mode | stat.S_IWRITE)
Пример #13
0
    def _unprotect_file(self, path):
        if self.fs.is_symlink(path) or self.fs.is_hardlink(path):
            logger.debug("Unprotecting '%s'", path)
            tmp = os.path.join(os.path.dirname(path), "." + uuid())

            # The operations order is important here - if some application
            # would access the file during the process of copyfile then it
            # would get only the part of file. So, at first, the file should be
            # copied with the temporary name, and then original file should be
            # replaced by new.
            copyfile(path, tmp, name=f"Unprotecting '{relpath(path)}'")
            remove(path)
            os.rename(tmp, path)

        else:
            logger.debug(
                "Skipping copying for '%s', since it is not "
                "a symlink or a hardlink.",
                path,
            )

        os.chmod(path, self._file_mode)
Пример #14
0
 def _collect_output(self, rev: str, executor: ExperimentExecutor):
     logger.debug("copying tmp output from '%s'", executor.tmp_dir)
     tree = self.scm.get_tree(rev)
     for fname in tree.walk_files(tree.tree_root):
         src = executor.path_info / relpath(fname, tree.tree_root)
         copyfile(src, fname)
Пример #15
0
 def get_file(self, rpath, lpath, callback=None, **kwargs):
     copyfile(rpath, lpath, callback=callback)
Пример #16
0
 def put_file(self, lpath, rpath, callback=None, **kwargs):
     parent = self._parent(rpath)
     makedirs(parent, exist_ok=True)
     tmp_file = os.path.join(parent, tmp_fname())
     copyfile(lpath, tmp_file, callback=callback)
     os.replace(tmp_file, rpath)
Пример #17
0
 def get_file(self,
              from_info,
              to_file,
              callback=DEFAULT_CALLBACK,
              **kwargs):
     copyfile(from_info, to_file, callback=callback)