From 97f3cfe4f44ddff56966a01f52170242bc69242e Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 27 Jan 2019 03:00:46 +0000 Subject: [PATCH] issue #477: target.file_exists() wrapper. os.path.exists physical module name varies across major Python versions. --- ansible_mitogen/mixins.py | 2 +- ansible_mitogen/target.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ansible_mitogen/mixins.py b/ansible_mitogen/mixins.py index e91e592e..7a180952 100644 --- a/ansible_mitogen/mixins.py +++ b/ansible_mitogen/mixins.py @@ -155,7 +155,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase): """ LOG.debug('_remote_file_exists(%r)', path) return self._connection.get_chain().call( - os.path.exists, + ansible_mitogen.target.file_exists, mitogen.utils.cast(path) ) diff --git a/ansible_mitogen/target.py b/ansible_mitogen/target.py index 2e91ee22..0db9af75 100644 --- a/ansible_mitogen/target.py +++ b/ansible_mitogen/target.py @@ -752,3 +752,12 @@ def set_file_mode(path, spec, fd=None): os.fchmod(fd, new_mode) else: os.chmod(path, new_mode) + + +def file_exists(path): + """ + Return :data:`True` if `path` exists. This is a wrapper function over + :func:`os.path.exists`, since its implementation module varies across + Python versions. + """ + return os.path.exists(path)