From 4bd40bd2573f7494d40df69ecd02b0663889d915 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 17 Feb 2018 15:30:39 +0545 Subject: [PATCH] ansible: remove old action subdirectory. --- ansible_mitogen/action/__init__.py | 0 ansible_mitogen/helpers.py | 23 ++++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) delete mode 100644 ansible_mitogen/action/__init__.py diff --git a/ansible_mitogen/action/__init__.py b/ansible_mitogen/action/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/ansible_mitogen/helpers.py b/ansible_mitogen/helpers.py index 9190a4f8..3da41ef0 100644 --- a/ansible_mitogen/helpers.py +++ b/ansible_mitogen/helpers.py @@ -51,7 +51,7 @@ class ModuleError(Exception): self.dct = dct -def wtf_exit_json(self, **kwargs): +def monkey_exit_json(self, **kwargs): """ Replace AnsibleModule.exit_json() with something that doesn't try to kill the process or JSON-encode the result dictionary. Instead, cause Exit to be @@ -67,7 +67,7 @@ def wtf_exit_json(self, **kwargs): raise Exit(kwargs) -def wtf_fail_json(self, **kwargs): +def monkey_fail_json(self, **kwargs): """ Replace AnsibleModule.fail_json() with something that raises ModuleError, which includes a `dct` attribute. @@ -94,8 +94,8 @@ def run_module(module, raw_params=None, args=None): if raw_params is not None: args['_raw_params'] = raw_params - ansible.module_utils.basic.AnsibleModule.exit_json = wtf_exit_json - ansible.module_utils.basic.AnsibleModule.fail_json = wtf_fail_json + ansible.module_utils.basic.AnsibleModule.exit_json = monkey_exit_json + ansible.module_utils.basic.AnsibleModule.fail_json = monkey_fail_json ansible.module_utils.basic._ANSIBLE_ARGS = json.dumps({ 'ANSIBLE_MODULE_ARGS': args }) @@ -112,7 +112,14 @@ def run_module(module, raw_params=None, args=None): return json.dumps(e.dct) -def exec_command(cmd, in_data=None): +def exec_command(cmd, in_data=''): + """ + Run a command in subprocess, arranging for `in_data` to be supplied on its + standard input. + + :return: + (return code, stdout bytes, stderr bytes) + """ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -123,8 +130,14 @@ def exec_command(cmd, in_data=None): def read_path(path): + """ + Fetch the contents of a filesystem `path` as bytes. + """ return open(path, 'rb').read() def write_path(path, s): + """ + Writes bytes `s` to a filesystem `path`. + """ open(path, 'wb').write(s)