From da1a13ef8b44f362094047174f6259a1af5e9913 Mon Sep 17 00:00:00 2001 From: blag Date: Tue, 16 Feb 2021 14:21:32 -0700 Subject: [PATCH 1/5] Add a debug contrib pack --- contrib/debug/actions/pythonpath.py | 15 +++++++++++++++ contrib/debug/actions/pythonpath.yaml | 7 +++++++ contrib/debug/pack.yaml | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 contrib/debug/actions/pythonpath.py create mode 100644 contrib/debug/actions/pythonpath.yaml create mode 100644 contrib/debug/pack.yaml diff --git a/contrib/debug/actions/pythonpath.py b/contrib/debug/actions/pythonpath.py new file mode 100644 index 0000000000..d8e1f6a92f --- /dev/null +++ b/contrib/debug/actions/pythonpath.py @@ -0,0 +1,15 @@ +import os +import sys + +from st2common.runners.base_action import Action + + +class PythonPathAction(Action): + def run(self, *args, **kwargs): + pythonpath = os.environ.get('PYTHONPATH') + if pythonpath: + pythonpath = pythonpath.split(':') + return { + "PYTHONPATH": pythonpath, + 'sys.path': sys.path, + } diff --git a/contrib/debug/actions/pythonpath.yaml b/contrib/debug/actions/pythonpath.yaml new file mode 100644 index 0000000000..c685f3b2bf --- /dev/null +++ b/contrib/debug/actions/pythonpath.yaml @@ -0,0 +1,7 @@ +--- +name: pythonpath +description: Prints out the PYTHONPATH +pack: debug +runner_type: python-script +entry_point: pythonpath.py +enabled: true diff --git a/contrib/debug/pack.yaml b/contrib/debug/pack.yaml new file mode 100644 index 0000000000..41dd36b3d6 --- /dev/null +++ b/contrib/debug/pack.yaml @@ -0,0 +1,8 @@ +name: debug +description: Debug utilities for StackStorm +ref: debug +author: StackStorm Authors +email: info@stackstorm.com +version: "0.0.1" +python_versions: + - "3" From 5e3d37baadedf3d2c25b98455f1cbbc6359a8abe Mon Sep 17 00:00:00 2001 From: blag Date: Tue, 27 Jul 2021 13:39:22 -0700 Subject: [PATCH 2/5] Format pythonpath.py with black --- contrib/debug/actions/pythonpath.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/debug/actions/pythonpath.py b/contrib/debug/actions/pythonpath.py index d8e1f6a92f..ceec2bed14 100644 --- a/contrib/debug/actions/pythonpath.py +++ b/contrib/debug/actions/pythonpath.py @@ -6,10 +6,10 @@ class PythonPathAction(Action): def run(self, *args, **kwargs): - pythonpath = os.environ.get('PYTHONPATH') + pythonpath = os.environ.get("PYTHONPATH") if pythonpath: - pythonpath = pythonpath.split(':') + pythonpath = pythonpath.split(":") return { "PYTHONPATH": pythonpath, - 'sys.path': sys.path, + "sys.path": sys.path, } From 5cb9481ba66bd60a738f1db10533028bd41586c0 Mon Sep 17 00:00:00 2001 From: blag Date: Fri, 30 Jul 2021 10:58:58 -0700 Subject: [PATCH 3/5] Add license header to pythonpath.py --- contrib/debug/actions/pythonpath.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/contrib/debug/actions/pythonpath.py b/contrib/debug/actions/pythonpath.py index ceec2bed14..1af41a558a 100644 --- a/contrib/debug/actions/pythonpath.py +++ b/contrib/debug/actions/pythonpath.py @@ -1,3 +1,19 @@ +#!/usr/bin/python + +# Copyright 2020 The StackStorm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import sys From 9cb20aee457db83e62de34d57101669493660567 Mon Sep 17 00:00:00 2001 From: blag Date: Fri, 30 Jul 2021 11:04:08 -0700 Subject: [PATCH 4/5] Add the python_version action --- contrib/debug/actions/python_version.py | 44 +++++++++++++++++++++++ contrib/debug/actions/python_version.yaml | 7 ++++ 2 files changed, 51 insertions(+) create mode 100644 contrib/debug/actions/python_version.py create mode 100644 contrib/debug/actions/python_version.yaml diff --git a/contrib/debug/actions/python_version.py b/contrib/debug/actions/python_version.py new file mode 100644 index 0000000000..f27120cded --- /dev/null +++ b/contrib/debug/actions/python_version.py @@ -0,0 +1,44 @@ +#!/usr/bin/python + +# Copyright 2020 The StackStorm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys + +try: + from st2common.runners.base_action import Action +except ImportError: + Action = object + + +class PythonVersionAction(Action): + def run(self, *args, **kwargs): + return { + "version": sys.version_info, + "details": { + "major": sys.version_info.major, + "minor": sys.version_info.minor, + "micro": sys.version_info.micro, + "releaselevel": sys.version_info.releaselevel, + "serial": sys.version_info.serial, + }, + } + + +if __name__ == "__main__": + import json + + pva = PythonVersionAction() + print(json.dumps(pva.run())) diff --git a/contrib/debug/actions/python_version.yaml b/contrib/debug/actions/python_version.yaml new file mode 100644 index 0000000000..bf4b72b298 --- /dev/null +++ b/contrib/debug/actions/python_version.yaml @@ -0,0 +1,7 @@ +--- +name: python_version +description: Returns the version of Python +pack: debug +runner_type: python-script +entry_point: python_version.py +enabled: true From 7044758b771885a998ff98bb3434e607bdbe730b Mon Sep 17 00:00:00 2001 From: blag Date: Fri, 30 Jul 2021 11:13:17 -0700 Subject: [PATCH 5/5] Add print_ctx action --- contrib/debug/actions/print_ctx.py | 33 ++++++++++++++++++++++++++++ contrib/debug/actions/print_ctx.yaml | 20 +++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 contrib/debug/actions/print_ctx.py create mode 100644 contrib/debug/actions/print_ctx.yaml diff --git a/contrib/debug/actions/print_ctx.py b/contrib/debug/actions/print_ctx.py new file mode 100644 index 0000000000..6d39ad6c99 --- /dev/null +++ b/contrib/debug/actions/print_ctx.py @@ -0,0 +1,33 @@ +#!/usr/bin/python + +# Copyright 2020 The StackStorm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys + +try: + from st2common.runners.base_action import Action +except ImportError: + Action = object + + +class PrintCtxAction(Action): + def run(self, ctx=None, *args, **kwargs): + print(ctx) + + +if __name__ == "__main__": + pca = PrintCtxAction() + pca.run({"Hello": "World", "Foo": "Bar"}) diff --git a/contrib/debug/actions/print_ctx.yaml b/contrib/debug/actions/print_ctx.yaml new file mode 100644 index 0000000000..30610fddbe --- /dev/null +++ b/contrib/debug/actions/print_ctx.yaml @@ -0,0 +1,20 @@ +--- +name: print_ctx +description: | + Prints the entire ctx() of a workflow task to stdout. Use like this: + + tasks: + ... + print_context: + action: debug.print_ctx + input: + ctx: <% ctx() %> # or {{ ctx() }} + +pack: debug +runner_type: python-script +entry_point: print_ctx.py +enabled: true +parameters: + ctx: + required: true + type: object