當前位置: 首頁>>代碼示例>>Python>>正文


Python errno.ENOENT屬性代碼示例

本文整理匯總了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 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:21,代碼來源:pdosq.py

示例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 
開發者ID:calmjs,項目名稱:calmjs,代碼行數:19,代碼來源:base.py

示例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 
開發者ID:pywren,項目名稱:pywren-ibm-cloud,代碼行數:19,代碼來源:ps_mem.py

示例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 
開發者ID:gnocchixyz,項目名稱:gnocchi,代碼行數:24,代碼來源:file.py

示例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 
開發者ID:gnocchixyz,項目名稱:gnocchi,代碼行數:20,代碼來源:file.py

示例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) 
開發者ID:linkedin,項目名稱:Zopkio,代碼行數:25,代碼來源:deployer.py

示例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 
開發者ID:linkedin,項目名稱:Zopkio,代碼行數:19,代碼來源:remote_host_helper.py

示例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 
開發者ID:luci,項目名稱:recipes-py,代碼行數:20,代碼來源:proto_support.py

示例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 
開發者ID:spencerahill,項目名稱:aospy,代碼行數:37,代碼來源:versioneer.py

示例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 
開發者ID:matthew-brett,項目名稱:delocate,代碼行數:32,代碼來源:versioneer.py

示例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) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:36,代碼來源:_os.py

示例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 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:9,代碼來源:_os.py

示例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 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:13,代碼來源:path.py

示例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 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:9,代碼來源:path.py

示例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)) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:30,代碼來源:exceptions.py


注:本文中的errno.ENOENT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。