Python distutils.errors.DistutilsFileError() Examples
The following are 30
code examples of distutils.errors.DistutilsFileError().
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.errors
, or try the search function
.
Example #1
Source File: file_util.py From ironpython2 with Apache License 2.0 | 7 votes |
def _copy_file_contents(src, dst, buffer_size=16*1024): """Copy the file 'src' to 'dst'. Both must be filenames. Any error opening either file, reading from 'src', or writing to 'dst', raises DistutilsFileError. Data is read/written in chunks of 'buffer_size' bytes (default 16k). No attempt is made to handle anything apart from regular files. """ # Stolen from shutil module in the standard library, but with # custom error-handling added. fsrc = None fdst = None try: try: fsrc = open(src, 'rb') except os.error, (errno, errstr): raise DistutilsFileError("could not open '%s': %s" % (src, errstr)) if os.path.exists(dst): try: os.unlink(dst) except os.error, (errno, errstr): raise DistutilsFileError( "could not delete '%s': %s" % (dst, errstr))
Example #2
Source File: test_build_py.py From Imogen with MIT License | 6 votes |
def test_empty_package_dir(self): # See bugs #1668596/#1720897 sources = self.mkdtemp() open(os.path.join(sources, "__init__.py"), "w").close() testdir = os.path.join(sources, "doc") os.mkdir(testdir) open(os.path.join(testdir, "testfile"), "w").close() os.chdir(sources) dist = Distribution({"packages": ["pkg"], "package_dir": {"pkg": ""}, "package_data": {"pkg": ["doc/*"]}}) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''")
Example #3
Source File: dep_util.py From meddle with MIT License | 6 votes |
def newer(source, target): """Tells if the target is newer than the source. Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. Note that this test is not very accurate: files created in the same second will have the same "age". """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return True return os.stat(source).st_mtime > os.stat(target).st_mtime
Example #4
Source File: file_util.py From meddle with MIT License | 6 votes |
def _copy_file_contents(src, dst, buffer_size=16*1024): """Copy the file 'src' to 'dst'. Both must be filenames. Any error opening either file, reading from 'src', or writing to 'dst', raises DistutilsFileError. Data is read/written in chunks of 'buffer_size' bytes (default 16k). No attempt is made to handle anything apart from regular files. """ # Stolen from shutil module in the standard library, but with # custom error-handling added. fsrc = None fdst = None try: try: fsrc = open(src, 'rb') except os.error, (errno, errstr): raise DistutilsFileError("could not open '%s': %s" % (src, errstr)) if os.path.exists(dst): try: os.unlink(dst) except os.error, (errno, errstr): raise DistutilsFileError( "could not delete '%s': %s" % (dst, errstr))
Example #5
Source File: dep_util.py From datafari with Apache License 2.0 | 6 votes |
def newer(source, target): """Tells if the target is newer than the source. Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. Note that this test is not very accurate: files created in the same second will have the same "age". """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return True return os.stat(source)[ST_MTIME] > os.stat(target)[ST_MTIME]
Example #6
Source File: dep_util.py From ironpython2 with Apache License 2.0 | 6 votes |
def newer(source, target): """Tells if the target is newer than the source. Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. Note that this test is not very accurate: files created in the same second will have the same "age". """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return True return os.stat(source)[ST_MTIME] > os.stat(target)[ST_MTIME]
Example #7
Source File: test_dep_util.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_newer(self): tmpdir = self.mkdtemp() new_file = os.path.join(tmpdir, 'new') old_file = os.path.abspath(__file__) # Raise DistutilsFileError if 'new_file' does not exist. self.assertRaises(DistutilsFileError, newer, new_file, old_file) # Return true if 'new_file' exists and is more recently modified than # 'old_file', or if 'new_file' exists and 'old_file' doesn't. self.write_file(new_file) self.assertTrue(newer(new_file, 'I_dont_exist')) self.assertTrue(newer(new_file, old_file)) # Return false if both exist and 'old_file' is the same age or younger # than 'new_file'. self.assertFalse(newer(old_file, new_file))
Example #8
Source File: dep_util.py From BinderFilter with MIT License | 6 votes |
def newer(source, target): """Tells if the target is newer than the source. Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. Note that this test is not very accurate: files created in the same second will have the same "age". """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return True return os.stat(source)[ST_MTIME] > os.stat(target)[ST_MTIME]
Example #9
Source File: file_util.py From BinderFilter with MIT License | 6 votes |
def _copy_file_contents(src, dst, buffer_size=16*1024): """Copy the file 'src' to 'dst'. Both must be filenames. Any error opening either file, reading from 'src', or writing to 'dst', raises DistutilsFileError. Data is read/written in chunks of 'buffer_size' bytes (default 16k). No attempt is made to handle anything apart from regular files. """ # Stolen from shutil module in the standard library, but with # custom error-handling added. fsrc = None fdst = None try: try: fsrc = open(src, 'rb') except os.error, (errno, errstr): raise DistutilsFileError("could not open '%s': %s" % (src, errstr)) if os.path.exists(dst): try: os.unlink(dst) except os.error, (errno, errstr): raise DistutilsFileError( "could not delete '%s': %s" % (dst, errstr))
Example #10
Source File: dep_util.py From Computable with MIT License | 6 votes |
def newer(source, target): """Tells if the target is newer than the source. Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. Note that this test is not very accurate: files created in the same second will have the same "age". """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return True return os.stat(source).st_mtime > os.stat(target).st_mtime
Example #11
Source File: test_dep_util.py From Computable with MIT License | 6 votes |
def test_newer(self): tmpdir = self.mkdtemp() new_file = os.path.join(tmpdir, 'new') old_file = os.path.abspath(__file__) # Raise DistutilsFileError if 'new_file' does not exist. self.assertRaises(DistutilsFileError, newer, new_file, old_file) # Return true if 'new_file' exists and is more recently modified than # 'old_file', or if 'new_file' exists and 'old_file' doesn't. self.write_file(new_file) self.assertTrue(newer(new_file, 'I_dont_exist')) self.assertTrue(newer(new_file, old_file)) # Return false if both exist and 'old_file' is the same age or younger # than 'new_file'. self.assertFalse(newer(old_file, new_file))
Example #12
Source File: package_manager.py From mock with GNU General Public License v2.0 | 6 votes |
def copy_certs(self): cert_path = "/etc/pki/ca-trust" pki_dir = self.buildroot.make_chroot_path(cert_path) try: copy_tree(cert_path, pki_dir) except DistutilsFileError: warning = "Couldn't copy certs from host, %s doesn't exist or is not readable" self.buildroot.root_log.debug(warning, cert_path) bundle_path = self.config['ssl_ca_bundle_path'] if bundle_path: self.buildroot.root_log.debug('copying CA bundle into chroot') host_bundle = os.path.realpath('/etc/pki/tls/certs/ca-bundle.crt') chroot_bundle_path = self.buildroot.make_chroot_path(bundle_path) chroot_bundle_dir = os.path.dirname(chroot_bundle_path) try: os.makedirs(chroot_bundle_dir) except FileExistsError: pass # for repeated attempts try: shutil.copy(host_bundle, chroot_bundle_path) except FileNotFoundError: # when mock is not run on Fedora or EL self.buildroot.root_log.debug("ca bundle not found on host")
Example #13
Source File: dep_util.py From oss-ftp with MIT License | 6 votes |
def newer(source, target): """Tells if the target is newer than the source. Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. Note that this test is not very accurate: files created in the same second will have the same "age". """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return True return os.stat(source)[ST_MTIME] > os.stat(target)[ST_MTIME]
Example #14
Source File: file_util.py From oss-ftp with MIT License | 6 votes |
def _copy_file_contents(src, dst, buffer_size=16*1024): """Copy the file 'src' to 'dst'. Both must be filenames. Any error opening either file, reading from 'src', or writing to 'dst', raises DistutilsFileError. Data is read/written in chunks of 'buffer_size' bytes (default 16k). No attempt is made to handle anything apart from regular files. """ # Stolen from shutil module in the standard library, but with # custom error-handling added. fsrc = None fdst = None try: try: fsrc = open(src, 'rb') except os.error, (errno, errstr): raise DistutilsFileError("could not open '%s': %s" % (src, errstr)) if os.path.exists(dst): try: os.unlink(dst) except os.error, (errno, errstr): raise DistutilsFileError( "could not delete '%s': %s" % (dst, errstr))
Example #15
Source File: test_dep_util.py From datafari with Apache License 2.0 | 6 votes |
def test_newer(self): tmpdir = self.mkdtemp() new_file = os.path.join(tmpdir, 'new') old_file = os.path.abspath(__file__) # Raise DistutilsFileError if 'new_file' does not exist. self.assertRaises(DistutilsFileError, newer, new_file, old_file) # Return true if 'new_file' exists and is more recently modified than # 'old_file', or if 'new_file' exists and 'old_file' doesn't. self.write_file(new_file) self.assertTrue(newer(new_file, 'I_dont_exist')) self.assertTrue(newer(new_file, old_file)) # Return false if both exist and 'old_file' is the same age or younger # than 'new_file'. self.assertFalse(newer(old_file, new_file))
Example #16
Source File: test_dep_util.py From Imogen with MIT License | 6 votes |
def test_newer(self): tmpdir = self.mkdtemp() new_file = os.path.join(tmpdir, 'new') old_file = os.path.abspath(__file__) # Raise DistutilsFileError if 'new_file' does not exist. self.assertRaises(DistutilsFileError, newer, new_file, old_file) # Return true if 'new_file' exists and is more recently modified than # 'old_file', or if 'new_file' exists and 'old_file' doesn't. self.write_file(new_file) self.assertTrue(newer(new_file, 'I_dont_exist')) self.assertTrue(newer(new_file, old_file)) # Return false if both exist and 'old_file' is the same age or younger # than 'new_file'. self.assertFalse(newer(old_file, new_file))
Example #17
Source File: dep_util.py From Imogen with MIT License | 6 votes |
def newer (source, target): """Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return 1 from stat import ST_MTIME mtime1 = os.stat(source)[ST_MTIME] mtime2 = os.stat(target)[ST_MTIME] return mtime1 > mtime2 # newer ()
Example #18
Source File: test_build_py.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_empty_package_dir(self): # See bugs #1668596/#1720897 sources = self.mkdtemp() open(os.path.join(sources, "__init__.py"), "w").close() testdir = os.path.join(sources, "doc") os.mkdir(testdir) open(os.path.join(testdir, "testfile"), "w").close() os.chdir(sources) dist = Distribution({"packages": ["pkg"], "package_dir": {"pkg": ""}, "package_data": {"pkg": ["doc/*"]}}) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''")
Example #19
Source File: test_dep_util.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_newer(self): tmpdir = self.mkdtemp() new_file = os.path.join(tmpdir, 'new') old_file = os.path.abspath(__file__) # Raise DistutilsFileError if 'new_file' does not exist. self.assertRaises(DistutilsFileError, newer, new_file, old_file) # Return true if 'new_file' exists and is more recently modified than # 'old_file', or if 'new_file' exists and 'old_file' doesn't. self.write_file(new_file) self.assertTrue(newer(new_file, 'I_dont_exist')) self.assertTrue(newer(new_file, old_file)) # Return false if both exist and 'old_file' is the same age or younger # than 'new_file'. self.assertFalse(newer(old_file, new_file))
Example #20
Source File: dep_util.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def newer (source, target): """Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return 1 from stat import ST_MTIME mtime1 = os.stat(source)[ST_MTIME] mtime2 = os.stat(target)[ST_MTIME] return mtime1 > mtime2 # newer ()
Example #21
Source File: dep_util.py From ironpython3 with Apache License 2.0 | 6 votes |
def newer (source, target): """Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return 1 from stat import ST_MTIME mtime1 = os.stat(source)[ST_MTIME] mtime2 = os.stat(target)[ST_MTIME] return mtime1 > mtime2 # newer ()
Example #22
Source File: dep_util.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def newer (source, target): """Return true if 'source' exists and is more recently modified than 'target', or if 'source' exists and 'target' doesn't. Return false if both exist and 'target' is the same age or younger than 'source'. Raise DistutilsFileError if 'source' does not exist. """ if not os.path.exists(source): raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) if not os.path.exists(target): return 1 from stat import ST_MTIME mtime1 = os.stat(source)[ST_MTIME] mtime2 = os.stat(target)[ST_MTIME] return mtime1 > mtime2 # newer ()
Example #23
Source File: test_dep_util.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_newer(self): tmpdir = self.mkdtemp() new_file = os.path.join(tmpdir, 'new') old_file = os.path.abspath(__file__) # Raise DistutilsFileError if 'new_file' does not exist. self.assertRaises(DistutilsFileError, newer, new_file, old_file) # Return true if 'new_file' exists and is more recently modified than # 'old_file', or if 'new_file' exists and 'old_file' doesn't. self.write_file(new_file) self.assertTrue(newer(new_file, 'I_dont_exist')) self.assertTrue(newer(new_file, old_file)) # Return false if both exist and 'old_file' is the same age or younger # than 'new_file'. self.assertFalse(newer(old_file, new_file))
Example #24
Source File: test_build_py.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_empty_package_dir(self): # See bugs #1668596/#1720897 sources = self.mkdtemp() open(os.path.join(sources, "__init__.py"), "w").close() testdir = os.path.join(sources, "doc") os.mkdir(testdir) open(os.path.join(testdir, "testfile"), "w").close() os.chdir(sources) dist = Distribution({"packages": ["pkg"], "package_dir": {"pkg": ""}, "package_data": {"pkg": ["doc/*"]}}) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data test when package_dir is ''")
Example #25
Source File: test_dep_util.py From oss-ftp with MIT License | 6 votes |
def test_newer(self): tmpdir = self.mkdtemp() new_file = os.path.join(tmpdir, 'new') old_file = os.path.abspath(__file__) # Raise DistutilsFileError if 'new_file' does not exist. self.assertRaises(DistutilsFileError, newer, new_file, old_file) # Return true if 'new_file' exists and is more recently modified than # 'old_file', or if 'new_file' exists and 'old_file' doesn't. self.write_file(new_file) self.assertTrue(newer(new_file, 'I_dont_exist')) self.assertTrue(newer(new_file, old_file)) # Return false if both exist and 'old_file' is the same age or younger # than 'new_file'. self.assertFalse(newer(old_file, new_file))
Example #26
Source File: test_file_util.py From Imogen with MIT License | 5 votes |
def test_move_file_exception_unpacking_unlink(self): # see issue 22182 with patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")), \ patch("os.unlink", side_effect=OSError("wrong", 1)), \ self.assertRaises(DistutilsFileError): with open(self.source, 'w') as fobj: fobj.write('spam eggs') move_file(self.source, self.target, verbose=0)
Example #27
Source File: test_build_py.py From Imogen with MIT License | 5 votes |
def test_dir_in_package_data(self): """ A directory in package_data should not be added to the filelist. """ # See bug 19286 sources = self.mkdtemp() pkg_dir = os.path.join(sources, "pkg") os.mkdir(pkg_dir) open(os.path.join(pkg_dir, "__init__.py"), "w").close() docdir = os.path.join(pkg_dir, "doc") os.mkdir(docdir) open(os.path.join(docdir, "testfile"), "w").close() # create the directory that could be incorrectly detected as a file os.mkdir(os.path.join(docdir, 'otherdir')) os.chdir(sources) dist = Distribution({"packages": ["pkg"], "package_data": {"pkg": ["doc/*"]}}) # script_name need not exist, it just need to be initialized dist.script_name = os.path.join(sources, "setup.py") dist.script_args = ["build"] dist.parse_command_line() try: dist.run_commands() except DistutilsFileError: self.fail("failed package_data when data dir includes a dir")
Example #28
Source File: dir_util.py From datafari with Apache License 2.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 #29
Source File: dir_util.py From ironpython2 with Apache License 2.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 #30
Source File: test_dir_util.py From Imogen with MIT License | 5 votes |
def test_copy_tree_exception_in_listdir(self): """ An exception in listdir should raise a DistutilsFileError """ with patch("os.listdir", side_effect=OSError()), \ self.assertRaises(errors.DistutilsFileError): src = self.tempdirs[-1] dir_util.copy_tree(src, None)