本文整理汇总了Python中errno.ENOENT属性的典型用法代码示例。如果您正苦于以下问题:Python errno.ENOENT属性的具体用法?Python errno.ENOENT怎么用?Python errno.ENOENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.ENOENT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: safe_remove
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def safe_remove(path):
"""
Remove a file or silently pass if the file does not exist.
This function has the same effect as os.remove but suppresses the error if
the file did not exist. Notably, it must not be used to remove directories.
Returns True if a file was removed or False if no file was removed.
"""
try:
os.remove(path)
return True
except OSError as err:
# Suppress the exception if it is a file not found error.
# Otherwise, re-raise the exception.
if err.errno != errno.ENOENT:
raise
return False
示例2: _get_exec_binary
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def _get_exec_binary(binary, kw):
"""
On win32, the subprocess module can only reliably resolve the
target binary if it's actually a binary; as for a Node.js script
it seems to only work iff shell=True was specified, presenting
a security risk. Resolve the target manually through which will
account for that.
The kw argument is the keyword arguments that will be passed into
whatever respective subprocess.Popen family of methods. The PATH
environment variable will be used if available.
"""
binary = which(binary, path=kw.get('env', {}).get('PATH'))
if binary is None:
raise_os_error(errno.ENOENT)
return binary
示例3: verify_environment
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def verify_environment(pids_to_show):
if os.geteuid() != 0 and not pids_to_show:
sys.stderr.write("Sorry, root permission required, or specify pids with -p\n")
sys.stderr.close()
sys.exit(1)
try:
kernel_ver()
except (IOError, OSError):
val = sys.exc_info()[1]
if val.errno == errno.ENOENT:
sys.stderr.write(
"Couldn't access " + proc.path('') + "\n"
"Only GNU/Linux and FreeBSD (with linprocfs) are supported\n")
sys.exit(2)
else:
raise
示例4: _store_new_measures
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def _store_new_measures(self, metric_id, data):
tmpfile = tempfile.NamedTemporaryFile(
prefix='gnocchi', dir=self.basepath_tmp,
delete=False)
tmpfile.write(data)
tmpfile.close()
path = self._build_measure_path(metric_id, True)
while True:
try:
os.rename(tmpfile.name, path)
break
except OSError as e:
if e.errno != errno.ENOENT:
raise
try:
os.mkdir(self._build_measure_path(metric_id))
except OSError as e:
# NOTE(jd) It's possible that another process created the
# path just before us! In this case, good for us, let's do
# nothing then! (see bug #1475684)
if e.errno != errno.EEXIST:
raise
示例5: _delete_measures_files_for_metric
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def _delete_measures_files_for_metric(self, metric_id, files):
for f in files:
try:
os.unlink(self._build_measure_path(metric_id, f))
except OSError as e:
# Another process deleted it in the meantime, no prob'
if e.errno != errno.ENOENT:
raise
try:
os.rmdir(self._build_measure_path(metric_id))
except OSError as e:
# ENOENT: ok, it has been removed at almost the same time
# by another process
# ENOTEMPTY: ok, someone pushed measure in the meantime,
# we'll delete the measures and directory later
# EEXIST: some systems use this instead of ENOTEMPTY
if e.errno not in (errno.ENOENT, errno.ENOTEMPTY, errno.EEXIST):
raise
示例6: fetch_logs_from_host
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def fetch_logs_from_host(hostname, install_path, prefix, logs, directory, pattern):
""" Static method Copies logs from specified host on the specified install path
:Parameter hostname the remote host from where we need to fetch the logs
:Parameter install_path path where the app is installed
:Parameter prefix prefix used to copy logs. Generall the unique_id of process
:Parameter logs a list of logs given by absolute path from the remote host
:Parameter directory the local directory to store the copied logs
:Parameter pattern a pattern to apply to files to restrict the set of logs copied
"""
if hostname is not None:
with get_sftp_client(hostname, username=runtime.get_username(), password=runtime.get_password()) as ftp:
for f in logs:
try:
mode = ftp.stat(f).st_mode
except IOError, e:
if e.errno == errno.ENOENT:
logger.error("Log file " + f + " does not exist on " + hostname)
pass
else:
copy_dir(ftp, f, directory, prefix)
if install_path is not None:
copy_dir(ftp, install_path, directory, prefix, pattern)
示例7: copy_dir
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def copy_dir(ftp, filename, outputdir, prefix, pattern=''):
"""
Recursively copy a directory flattens the output into a single directory but
prefixes the files with the path from the original input directory
:param ftp:
:param filename:
:param outputdir:
:param prefix:
:param pattern: a regex pattern for files to match (by default matches everything)
:return:
"""
try:
mode = ftp.stat(filename).st_mode
except IOError, e:
if e.errno == errno.ENOENT:
logger.error("Log file " + filename + " does not exist")
pass
示例8: _check_digest
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def _check_digest(proto_package, dgst):
"""Checks protos installed in `{proto_package_path}/PB`.
Args:
* proto_package_base (str) - The absolute path to the folder where we will
look for '.../PB/csum
* dgst (str) - The digest of the proto files which we believe need to be
built.
Returns True iff csum matches dgst.
"""
try:
csum_path = os.path.join(proto_package, 'PB', 'csum')
with open(csum_path, 'rb') as cur_dgst_f:
return cur_dgst_f.read() == dgst
except (OSError, IOError) as exc:
if exc.errno != errno.ENOENT:
raise
示例9: run_command
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
env=None):
"""Call the given command(s)."""
assert isinstance(commands, list)
p = None
for c in commands:
try:
dispcmd = str([c] + args)
# remember shell=False, so use git.cmd on windows, not just git
p = subprocess.Popen([c] + args, cwd=cwd, env=env,
stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr
else None))
break
except EnvironmentError:
e = sys.exc_info()[1]
if e.errno == errno.ENOENT:
continue
if verbose:
print("unable to run %s" % dispcmd)
print(e)
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
return None, None
stdout = p.communicate()[0].strip()
if sys.version_info[0] >= 3:
stdout = stdout.decode()
if p.returncode != 0:
if verbose:
print("unable to run %s (error)" % dispcmd)
print("stdout was %s" % stdout)
return None, p.returncode
return stdout, p.returncode
示例10: run_command
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
assert isinstance(commands, list)
p = None
for c in commands:
try:
# remember shell=False, so use git.cmd on windows, not just git
p = subprocess.Popen([c] + args, cwd=cwd, stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr
else None))
break
except EnvironmentError:
e = sys.exc_info()[1]
if e.errno == errno.ENOENT:
continue
if verbose:
print("unable to run %s" % args[0])
print(e)
return None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
return None
stdout = p.communicate()[0].strip()
if sys.version >= '3':
stdout = stdout.decode()
if p.returncode != 0:
if verbose:
print("unable to run %s (error)" % args[0])
return None
return stdout
示例11: makedirs
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def makedirs(path, exist_ok=False, **kwargs):
"""
Recursive directory creation function. Like mkdir(), but makes all intermediate-level directories needed to contain
the leaf directory.
If exist_ok is False (the default), an OSError is raised if the target directory already exists.
:param path: The path to the directory to create.
:param exist_ok: Set to True to not fail if the target directory already exists.
:param kwargs: Common SMB Session arguments for smbclient.
"""
create_queue = [ntpath.normpath(path)]
present_parent = None
while create_queue:
mkdir_path = create_queue[-1]
try:
mkdir(mkdir_path, **kwargs)
except OSError as err:
if err.errno == errno.EEXIST:
present_parent = mkdir_path
create_queue.pop(-1)
if not create_queue and not exist_ok:
raise
elif err.errno == errno.ENOENT:
# Check if the parent path has already been created to avoid getting in an endless loop.
parent_path = ntpath.dirname(mkdir_path)
if present_parent == parent_path:
raise
else:
create_queue.append(parent_path)
else:
raise
else:
create_queue.pop(-1)
示例12: _link_target_type_check
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def _link_target_type_check(self, check):
try:
return check(self.stat(follow_symlinks=True).st_mode)
except OSError as err:
if err.errno == errno.ENOENT: # Missing target, broken symlink just return False
return False
raise
示例13: _exists
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def _exists(path, symlink_default, follow_symlinks, **kwargs):
try:
stat(path, follow_symlinks=follow_symlinks, **kwargs)
return True
except OSError as err:
if err.errno == errno.ENOENT:
return False
raise
except SMBLinkRedirectionError:
# Link points to another server or local drive, return false
return symlink_default
示例14: _stat_ismode
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def _stat_ismode(path, check, follow, **kwargs):
try:
return check(stat(path, follow_symlinks=follow, **kwargs).st_mode)
except SMBOSError as err:
if err.errno == errno.ENOENT:
return False
raise
示例15: __init__
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOENT [as 别名]
def __init__(self, ntstatus, filename, filename2=None):
self.ntstatus = ntstatus
self.filename2 = to_native(filename2) if filename2 else None
ntstatus_name = 'STATUS_UNKNOWN'
for name, val in vars(NtStatus).items():
if ntstatus == val:
ntstatus_name = name
break
error_details = {
NtStatus.STATUS_OBJECT_NAME_NOT_FOUND: errno.ENOENT,
NtStatus.STATUS_OBJECT_PATH_NOT_FOUND: errno.ENOENT,
NtStatus.STATUS_OBJECT_NAME_COLLISION: errno.EEXIST,
NtStatus.STATUS_PRIVILEGE_NOT_HELD: (errno.EACCES, "Required privilege not held"),
NtStatus.STATUS_SHARING_VIOLATION: (errno.EPERM, "The process cannot access the file because it is being "
"used by another process"),
NtStatus.STATUS_NOT_A_REPARSE_POINT: (errno.EINVAL, "The file or directory is not a reparse point"),
NtStatus.STATUS_FILE_IS_A_DIRECTORY: errno.EISDIR,
NtStatus.STATUS_NOT_A_DIRECTORY: errno.ENOTDIR,
NtStatus.STATUS_DIRECTORY_NOT_EMPTY: errno.ENOTEMPTY,
NtStatus.STATUS_END_OF_FILE: getattr(errno, 'ENODATA', 120), # Not present on py2 for Windows.
}.get(ntstatus, (0, "Unknown NtStatus error returned '%s'" % ntstatus_name))
if not isinstance(error_details, tuple):
error_details = (error_details, os.strerror(error_details))
super(SMBOSError, self).__init__(error_details[0], error_details[1], to_native(filename))