From 15afd4c27dce6c31fa362ef3b259fee2370ffcd1 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 29 Jul 2018 13:37:58 +0300 Subject: Add: python actions define a RUN() function --- NEWS | 4 ++++ ick2/actions.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index c1caa5c..188c00b 100644 --- a/NEWS +++ b/NEWS @@ -41,6 +41,10 @@ Version 0.53.2+git, not yet released uses. This doesn't catch when a parameters is used by a pipeline, but not declared by it. +* The worker-manager now defines a RUN() function for Python actions, + to make it easier to run commands from Python code. It's a small + wrapper around `subporocess.run()`. + Version 0.53.2, released 2018-07-18 ------------------------------------ diff --git a/ick2/actions.py b/ick2/actions.py index a424c95..932c1e0 100644 --- a/ick2/actions.py +++ b/ick2/actions.py @@ -220,9 +220,14 @@ class PythonAction(Action): def encode_parameters(self, params): # pragma: no cover encoded = self.encode64(params) prefix = ( - 'import base64, json\n' + 'import base64, json, subprocess\n' 'params = json.loads(base64.b64decode(\n' ' "{}").decode("utf8"))\n' + 'def RUN(*args, **kwargs):\n' + ' print("Executing:", args, kwargs)\n' + ' if "check" not in kwargs:\n' + ' kwargs["check"] = True\n' + ' return subprocess.run(args, **kwargs)\n' ).format(encoded) return prefix -- cgit v1.2.1