本文整理汇总了Python中distutils.errors.DistutilsFileError方法的典型用法代码示例。如果您正苦于以下问题:Python errors.DistutilsFileError方法的具体用法?Python errors.DistutilsFileError怎么用?Python errors.DistutilsFileError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类distutils.errors
的用法示例。
在下文中一共展示了errors.DistutilsFileError方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: newer
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [as 别名]
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
示例2: _copy_file_contents
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [as 别名]
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))
示例3: newer
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [as 别名]
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]
示例4: test_newer
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [as 别名]
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))
示例5: newer
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [as 别名]
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 ()
示例6: test_empty_package_dir
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [as 别名]
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 ''")
示例7: copy_certs
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [as 别名]
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")
示例8: copy_tree
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [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)
示例9: check_package
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [as 别名]
def check_package(self, package, package_dir):
# Empty dir name means current directory, which we can probably
# assume exists. Also, os.path.exists and isdir don't know about
# my "empty string means current dir" convention, so we have to
# circumvent them.
if package_dir != "":
if not os.path.exists(package_dir):
raise DistutilsFileError(
"package directory '%s' does not exist" % package_dir)
if not os.path.isdir(package_dir):
raise DistutilsFileError(
"supposed package directory '%s' exists, "
"but is not a directory" % package_dir)
# Require __init__.py for all but the "root package"
if package:
init_py = os.path.join(package_dir, "__init__.py")
if os.path.isfile(init_py):
return init_py
else:
log.warn(("package init file '%s' not found " +
"(or not a regular file)"), init_py)
# Either not in a package at all (__init__.py not expected), or
# __init__.py doesn't exist -- so don't return the filename.
return None
示例10: test_empty_package_dir
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [as 别名]
def test_empty_package_dir(self):
# See SF 1668596/1720897.
cwd = os.getcwd()
# create the distribution files.
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)
old_stdout = sys.stdout
sys.stdout = StringIO.StringIO()
try:
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 ''")
finally:
# Restore state.
os.chdir(cwd)
sys.stdout = old_stdout
示例11: test_dir_in_package_data
# 需要导入模块: from distutils import errors [as 别名]
# 或者: from distutils.errors import DistutilsFileError [as 别名]
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")