Use a try/except import approach similar to lock

This commit is contained in:
Adrien Ferrand 2019-05-15 17:45:29 +02:00
parent 0b6c5d6003
commit 7e1f284d36

View file

@ -6,12 +6,11 @@ import stat
try:
import ntsecuritycon # pylint: disable=import-error
except ImportError: # pragma: no cover
ntsecuritycon = None # type: ignore
try:
import win32security # pylint: disable=import-error
except ImportError: # pragma: no cover
win32security = None # type: ignore
except ImportError:
POSIX_MODE = True
else:
POSIX_MODE = False
def chmod(file_path, mode):
@ -24,7 +23,7 @@ def chmod(file_path, mode):
:param str file_path: Path of the file
:param int mode: POSIX mode to apply
"""
if not win32security:
if POSIX_MODE:
os.chmod(file_path, mode)
else:
_apply_win_mode(file_path, mode)