Python distutils.file_util.copy_file() Examples
The following are 30
code examples of distutils.file_util.copy_file().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
distutils.file_util
, or try the search function
.
Example #1
Source File: test_file_util.py From android_universal with MIT License | 6 votes |
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')
Example #2
Source File: test_file_util.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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')
Example #3
Source File: test_file_util.py From Imogen with MIT License | 6 votes |
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')
Example #4
Source File: test_file_util.py From Imogen with MIT License | 6 votes |
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')
Example #5
Source File: test_file_util.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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')
Example #6
Source File: test_file_util.py From ironpython3 with Apache License 2.0 | 6 votes |
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')
Example #7
Source File: test_file_util.py From android_universal with MIT License | 6 votes |
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')
Example #8
Source File: test_file_util.py From setuptools with MIT License | 6 votes |
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')
Example #9
Source File: test_file_util.py From setuptools with MIT License | 6 votes |
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')
Example #10
Source File: cmd.py From canape with GNU General Public License v3.0 | 5 votes |
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)
Example #11
Source File: util.py From android_universal with MIT License | 5 votes |
def copydir_run_2to3(src, dest, template=None, fixer_names=None, options=None, explicit=None): """Recursively copy a directory, only copying new and changed files, running run_2to3 over all newly copied Python modules afterward. If you give a template string, it's parsed like a MANIFEST.in. """ from distutils.dir_util import mkpath from distutils.file_util import copy_file from distutils.filelist import FileList filelist = FileList() curdir = os.getcwd() os.chdir(src) try: filelist.findall() finally: os.chdir(curdir) filelist.files[:] = filelist.allfiles if template: for line in template.splitlines(): line = line.strip() if not line: continue filelist.process_template_line(line) copied = [] for filename in filelist.files: outname = os.path.join(dest, filename) mkpath(os.path.dirname(outname)) res = copy_file(os.path.join(src, filename), outname, update=1) if res[1]: copied.append(outname) run_2to3([fn for fn in copied if fn.lower().endswith('.py')], fixer_names=fixer_names, options=options, explicit=explicit) return copied
Example #12
Source File: dir_util.py From medicare-demo with Apache License 2.0 | 5 votes |
def copy_tree (src, dst, preserve_mode=1, preserve_times=1, preserve_symlinks=0, update=0, verbose=0, 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)
Example #13
Source File: cmd.py From canape with GNU General Public License v3.0 | 5 votes |
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))
Example #14
Source File: dir_util.py From canape with GNU General Public License v3.0 | 5 votes |
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)
Example #15
Source File: dir_util.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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)
Example #16
Source File: cmd.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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)
Example #17
Source File: cmd.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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)
Example #18
Source File: dir_util.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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)
Example #19
Source File: cmd.py From meddle with MIT License | 5 votes |
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)
Example #20
Source File: cmd.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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))
Example #21
Source File: cmd.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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)
Example #22
Source File: cmd.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
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)
Example #23
Source File: cmd.py From medicare-demo with Apache License 2.0 | 5 votes |
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))
Example #24
Source File: cmd.py From medicare-demo with Apache License 2.0 | 5 votes |
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)
Example #25
Source File: test_file_util.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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')
Example #26
Source File: util.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def copydir_run_2to3(src, dest, template=None, fixer_names=None, options=None, explicit=None): """Recursively copy a directory, only copying new and changed files, running run_2to3 over all newly copied Python modules afterward. If you give a template string, it's parsed like a MANIFEST.in. """ from distutils.dir_util import mkpath from distutils.file_util import copy_file from distutils.filelist import FileList filelist = FileList() curdir = os.getcwd() os.chdir(src) try: filelist.findall() finally: os.chdir(curdir) filelist.files[:] = filelist.allfiles if template: for line in template.splitlines(): line = line.strip() if not line: continue filelist.process_template_line(line) copied = [] for filename in filelist.files: outname = os.path.join(dest, filename) mkpath(os.path.dirname(outname)) res = copy_file(os.path.join(src, filename), outname, update=1) if res[1]: copied.append(outname) run_2to3([fn for fn in copied if fn.lower().endswith('.py')], fixer_names=fixer_names, options=options, explicit=explicit) return copied
Example #27
Source File: cmd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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))
Example #28
Source File: cmd.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #29
Source File: config_file_updater.py From stdm with GNU General Public License v2.0 | 5 votes |
def _rename_new_config_file(self, path): """ Renames old configuration file """ config_file = "configuration" dt = unicode(datetime.datetime.now()) timestamp = time.strftime('%Y_%m_%d_%H_%M') new_file = '{}/{}_{}.stc'.format( self.file_handler.localPath(), config_file, timestamp ) file_util.copy_file(path, new_file)
Example #30
Source File: dir_util.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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)