summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-07-29 13:37:58 +0300
committerLars Wirzenius <liw@liw.fi>2018-07-29 13:37:58 +0300
commit15afd4c27dce6c31fa362ef3b259fee2370ffcd1 (patch)
treef9d3eed27deb3e295091bb54ac6607d8bb6d392f
parent45d99ad7836ab873a93bf5166421c34044b05515 (diff)
downloadick2-15afd4c27dce6c31fa362ef3b259fee2370ffcd1.tar.gz
Add: python actions define a RUN() function
-rw-r--r--NEWS4
-rw-r--r--ick2/actions.py7
2 files changed, 10 insertions, 1 deletions
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