本文整理汇总了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')
示例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')
示例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)
示例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))
示例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)
示例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')))
示例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')
示例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)