当前位置: 首页>>代码示例>>Python>>正文


Python file_util.copy_file方法代码示例

本文整理汇总了Python中distutils.file_util.copy_file方法的典型用法代码示例。如果您正苦于以下问题:Python file_util.copy_file方法的具体用法?Python file_util.copy_file怎么用?Python file_util.copy_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在distutils.file_util的用法示例。


在下文中一共展示了file_util.copy_file方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_copy_file_hard_link_failure

# 需要导入模块: from distutils import file_util [as 别名]
# 或者: from distutils.file_util import copy_file [as 别名]
def test_copy_file_hard_link_failure(self):
        # If hard linking fails, copy_file() falls back on copying file
        # (some special filesystems don't support hard linking even under
        #  Unix, see issue #8876).
        with open(self.source, 'w') as f:
            f.write('some content')
        st = os.stat(self.source)
        with patch("os.link", side_effect=OSError(0, "linking unsupported")):
            copy_file(self.source, self.target, link='hard')
        st2 = os.stat(self.source)
        st3 = os.stat(self.target)
        self.assertTrue(os.path.samestat(st, st2), (st, st2))
        self.assertFalse(os.path.samestat(st2, st3), (st2, st3))
        for fn in (self.source, self.target):
            with open(fn, 'r') as f:
                self.assertEqual(f.read(), 'some content') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_file_util.py

示例2: test_copy_file_hard_link

# 需要导入模块: from distutils import file_util [as 别名]
# 或者: from distutils.file_util import copy_file [as 别名]
def test_copy_file_hard_link(self):
        with open(self.source, 'w') as f:
            f.write('some content')
        # Check first that copy_file() will not fall back on copying the file
        # instead of creating the hard link.
        try:
            os.link(self.source, self.target)
        except OSError as e:
            self.skipTest('os.link: %s' % e)
        else:
            unlink(self.target)
        st = os.stat(self.source)
        copy_file(self.source, self.target, link='hard')
        st2 = os.stat(self.source)
        st3 = os.stat(self.target)
        self.assertTrue(os.path.samestat(st, st2), (st, st2))
        self.assertTrue(os.path.samestat(st2, st3), (st2, st3))
        with open(self.source, 'r') as f:
            self.assertEqual(f.read(), 'some content') 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:21,代码来源:test_file_util.py

示例3: copy_file

# 需要导入模块: from distutils import file_util [as 别名]
# 或者: from distutils.file_util import copy_file [as 别名]
def copy_file(self, infile, outfile,
                   preserve_mode=1, preserve_times=1, link=None, level=1):
        """Copy a file respecting verbose, dry-run and force flags.  (The
        former two default to whatever is in the Distribution object, and
        the latter defaults to false for commands that don't define it.)"""

        return file_util.copy_file(
            infile, outfile,
            preserve_mode, preserve_times,
            not self.force,
            link,
            dry_run=self.dry_run) 
开发者ID:glmcdona,项目名称:meddle,代码行数:14,代码来源:cmd.py

示例4: _copy_files

# 需要导入模块: from distutils import file_util [as 别名]
# 或者: from distutils.file_util import copy_file [as 别名]
def _copy_files(self, filelist):
        self.outfiles = []
        if not filelist:
            return
        self.mkpath(self.install_dir)
        for f in filelist:
            self.copy_file(f, self.install_dir)
            self.outfiles.append(os.path.join(self.install_dir, f)) 
开发者ID:glmcdona,项目名称:meddle,代码行数:10,代码来源:cmd.py

示例5: copy_tree

# 需要导入模块: from distutils import file_util [as 别名]
# 或者: from distutils.file_util import copy_file [as 别名]
def copy_tree(src, dst, preserve_mode=1, preserve_times=1,
              preserve_symlinks=0, update=0, verbose=1, dry_run=0):
    """Copy an entire directory tree 'src' to a new location 'dst'.

    Both 'src' and 'dst' must be directory names.  If 'src' is not a
    directory, raise DistutilsFileError.  If 'dst' does not exist, it is
    created with 'mkpath()'.  The end result of the copy is that every
    file in 'src' is copied to 'dst', and directories under 'src' are
    recursively copied to 'dst'.  Return the list of files that were
    copied or might have been copied, using their output name.  The
    return value is unaffected by 'update' or 'dry_run': it is simply
    the list of all files under 'src', with the names changed to be
    under 'dst'.

    'preserve_mode' and 'preserve_times' are the same as for
    'copy_file'; note that they only apply to regular files, not to
    directories.  If 'preserve_symlinks' is true, symlinks will be
    copied as symlinks (on platforms that support them!); otherwise
    (the default), the destination of the symlink will be copied.
    'update' and 'verbose' are the same as for 'copy_file'.
    """
    from distutils.file_util import copy_file

    if not dry_run and not os.path.isdir(src):
        raise DistutilsFileError, \
              "cannot copy tree '%s': not a directory" % src
    try:
        names = os.listdir(src)
    except os.error, (errno, errstr):
        if dry_run:
            names = []
        else:
            raise DistutilsFileError, \
                  "error listing files in '%s': %s" % (src, errstr) 
开发者ID:glmcdona,项目名称:meddle,代码行数:36,代码来源:dir_util.py

示例6: test_copy_file

# 需要导入模块: from distutils import file_util [as 别名]
# 或者: from distutils.file_util import copy_file [as 别名]
def test_copy_file(self):
        src_dir = self.mkdtemp()
        foo = os.path.join(src_dir, 'foo')
        write_file(foo, 'content')
        dst_dir = self.mkdtemp()
        copy_file(foo, dst_dir)
        self.assertTrue(os.path.exists(os.path.join(dst_dir, 'foo'))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_file_util.py

示例7: test_copy_file_hard_link

# 需要导入模块: from distutils import file_util [as 别名]
# 或者: from distutils.file_util import copy_file [as 别名]
def test_copy_file_hard_link(self):
        with open(self.source, 'w') as f:
            f.write('some content')
        st = os.stat(self.source)
        copy_file(self.source, self.target, link='hard')
        st2 = os.stat(self.source)
        st3 = os.stat(self.target)
        self.assertTrue(os.path.samestat(st, st2), (st, st2))
        self.assertTrue(os.path.samestat(st2, st3), (st2, st3))
        with open(self.source, 'r') as f:
            self.assertEqual(f.read(), 'some content') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_file_util.py

示例8: copy_file

# 需要导入模块: from distutils import file_util [as 别名]
# 或者: from distutils.file_util import copy_file [as 别名]
def copy_file(self, infile, outfile, preserve_mode=1, preserve_times=1,
                  link=None, level=1):
        """Copy a file respecting verbose, dry-run and force flags.  (The
        former two default to whatever is in the Distribution object, and
        the latter defaults to false for commands that don't define it.)"""
        return file_util.copy_file(infile, outfile, preserve_mode,
                                   preserve_times, not self.force, link,
                                   dry_run=self.dry_run) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:cmd.py


注:本文中的distutils.file_util.copy_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。