From 4cb581b368e5813932d22e9dc0905b6e47ad1c32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Fri, 4 Jun 2021 17:37:30 +0200 Subject: [PATCH] fix for OSErrors --- satella/os/misc.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/satella/os/misc.py b/satella/os/misc.py index 4f37be17..ec4c8b81 100644 --- a/satella/os/misc.py +++ b/satella/os/misc.py @@ -4,6 +4,8 @@ import os import sys import warnings +from satella.coding import silence_excs + def whereis(name: str) -> tp.Iterator[str]: """ @@ -25,17 +27,18 @@ def whereis(name: str) -> tp.Iterator[str]: available_extensions = '', for directory in paths_to_look_in: - for file in os.listdir(directory): - path = os.path.join(directory, file) - if 'x' not in stat.filemode(os.stat(path).st_mode): - continue - - if sys.platform.startswith('win'): # a POSIX-specific check - file = file.upper() # paths are not case-sensitive on Windows - - for extension in available_extensions: - if file == '%s%s' % (name, extension): - yield path + with silence_excs(FileNotFoundError): + for file in os.listdir(directory): + path = os.path.join(directory, file) + if 'x' not in stat.filemode(os.stat(path).st_mode): + continue + + if sys.platform.startswith('win'): # a POSIX-specific check + file = file.upper() # paths are not case-sensitive on Windows + + for extension in available_extensions: + if file == '%s%s' % (name, extension): + yield path def is_running_as_root() -> bool: -- GitLab