From 70ee60bb655b71ae596cd43799980d6085f9f7c2 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 2 Jun 2023 17:09:51 -0700 Subject: [PATCH] Fix config editing --- intake/app.py | 13 ++++++------- tests/demo_basic_callback/increment.py | 12 ++++++++++-- tests/demo_basic_callback/intake.json | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/intake/app.py b/intake/app.py index 2ab7b82..95899c8 100644 --- a/intake/app.py +++ b/intake/app.py @@ -198,13 +198,12 @@ def try_parse_config(config_str: str): fetch = action["fetch"] if "exe" not in fetch: return ("No fetch exe", {}) - return ( - None, - { - "action": parsed["action"], - "env": parsed["env"], - }, - ) + config = { + "action": parsed["action"] + } + if "env" in parsed: + config["env"] = parsed["env"] + return (None, config) def wsgi(): diff --git a/tests/demo_basic_callback/increment.py b/tests/demo_basic_callback/increment.py index b82a1ba..6a062c6 100755 --- a/tests/demo_basic_callback/increment.py +++ b/tests/demo_basic_callback/increment.py @@ -13,7 +13,8 @@ if args.action == "fetch": "id": "updateme", "title": "The count is at 1", "action": { - "increment": 1 + "increment": 1, + "decrement": "", } })) @@ -24,4 +25,11 @@ if args.action == "increment": item["body"] = f"

{item['action']['increment']}

" item["title"] = f"The count is at {item['action']['increment']}" print(json.dumps(item)) - pass + +if args.action == "decrement": + item = sys.stdin.readline() + item = json.loads(item) + item["action"]["increment"] -= 1 + item["body"] = f"

{item['action']['increment']}

" + item["title"] = f"The count is at {item['action']['increment']}" + print(json.dumps(item)) diff --git a/tests/demo_basic_callback/intake.json b/tests/demo_basic_callback/intake.json index 4f5074b..d1dd617 100644 --- a/tests/demo_basic_callback/intake.json +++ b/tests/demo_basic_callback/intake.json @@ -2,11 +2,21 @@ "action": { "fetch": { "exe": "./increment.py", - "args": ["fetch"] + "args": [ + "fetch" + ] }, "increment": { "exe": "./increment.py", - "args": ["increment"] + "args": [ + "increment" + ] + }, + "decrement": { + "exe": "./increment.py", + "args": [ + "decrement" + ] } } } \ No newline at end of file