diff --git a/README.md b/README.md index 943652f..755b6f2 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,9 @@ intake { "action": { "fetch": { - "exe": "", - "args": ["list", "of", "program", "arguments"] + "args": ["program name", "and", "list", "of", "arguments"] }, "": { - "exe": "...", "args": "..." } }, @@ -46,9 +44,9 @@ intake } ``` -Each key under `action` defines an action that can be taken for the source. An action must contain `exe` and may contain `args`. A source must have a `fetch` action. If an action named `on_create` is defined for the source, it is executed once for an item when that item is created. +Each key under `action` defines an action that can be taken for the source. A source must at least have a `fetch` action. If an action named `on_create` is defined for the source, it is executed once for an item when that item is created, that is, the first time the item is returned from the source. -Each key under `env` defines an environment variable that will be set when actions are executed. +Each key under `env` defines an environment variable that will be set when `fetch` or other actions are executed. If `cron` is present, it must define a crontab schedule. Intake will automatically create crontab entries to update each source according to its cron schedule. @@ -56,7 +54,7 @@ If `cron` is present, it must define a crontab schedule. Intake will automatical Intake interacts with sources by executing the actions defined in the source's `intake.json`. The `fetch` action is required and used to check for new feed items when `intake update` is executed. -To execute an action, intake executes the `exe` program for the action with the corresponding `args` (if present) as arguments. The process's working directory is set to the source's folder, i.e. the folder containing `intake.json`. The process's environment is as follows: +To execute an action, intake executes the command given by `args`. The process's working directory is set to the source's folder, i.e. the folder containing `intake.json`. The process's environment is as follows: * intake's environment is inherited. * `STATE_PATH` is set to the absolute path of `state`. diff --git a/intake/app.py b/intake/app.py index a37f961..6ec7f18 100644 --- a/intake/app.py +++ b/intake/app.py @@ -326,7 +326,7 @@ def _parse_source_config(config_str: str): if "fetch" not in action: return ("No fetch action defined", {}) fetch = action["fetch"] - if "exe" not in fetch: + if "exe" not in fetch and not fetch.get("args"): return ("No fetch exe", {}) config = {"action": parsed["action"]} if "env" in parsed: @@ -399,7 +399,7 @@ def fetch(source_name: str): update_items(source, items) titles = "\n".join(f"
  • {item.display_title}
  • " for item in items) source_url = url_for("source_feed", name=source_name) - return f"Update returned {len(items)} items:

    {source_name}

    " + return f'Update returned {len(items)} items:

    {source_name}

    ' except InvalidConfigException as ex: abort(500, f"Could not fetch {source_name}:\n{ex}") except SourceUpdateException as ex: @@ -417,7 +417,7 @@ def add_item(): config_path = source_path / "intake.json" if not config_path.exists(): config_path.write_text( - json.dumps({"action": {"fetch": {"exe": "true"}}}, indent=2) + json.dumps({"action": {"fetch": {"args": ["true"]}}}, indent=2) ) source = LocalSource(source_path.parent, source_path.name) diff --git a/intake/cli.py b/intake/cli.py index a1a6d8b..c83c758 100644 --- a/intake/cli.py +++ b/intake/cli.py @@ -52,7 +52,6 @@ def cmd_edit(cmd_args): { "action": { "fetch": { - "exe": "", "args": [], }, }, diff --git a/intake/source.py b/intake/source.py index 69ff033..eec6590 100644 --- a/intake/source.py +++ b/intake/source.py @@ -229,10 +229,13 @@ def _execute_source_action( if not action_cfg: raise InvalidConfigException(f"No such action {action}") - if "exe" not in action_cfg: + + exe = [action_cfg["exe"]] if "exe" in action_cfg else [] + command = exe + action_cfg.get("args", []) + + if not command: raise InvalidConfigException(f"No exe for action {action}") - command = [action_cfg["exe"], *action_cfg.get("args", [])] config_env = {key: str(value) for key, value in config.get("env", {}).items()} env = { **os.environ.copy(), diff --git a/tests/default/intake.json b/tests/default/intake.json index 8feca31..c880a12 100644 --- a/tests/default/intake.json +++ b/tests/default/intake.json @@ -1,7 +1,9 @@ { "action": { "fetch": { - "exe": "true" + "args": [ + "true" + ] } } } \ No newline at end of file diff --git a/tests/demo_basic_callback/intake.json b/tests/demo_basic_callback/intake.json index d1dd617..85c7830 100644 --- a/tests/demo_basic_callback/intake.json +++ b/tests/demo_basic_callback/intake.json @@ -1,20 +1,20 @@ { "action": { "fetch": { - "exe": "./increment.py", "args": [ + "./increment.py", "fetch" ] }, "increment": { - "exe": "./increment.py", "args": [ + "./increment.py", "increment" ] }, "decrement": { - "exe": "./increment.py", "args": [ + "./increment.py", "decrement" ] } diff --git a/tests/demo_logging/intake.json b/tests/demo_logging/intake.json index 20675ed..28ec14d 100644 --- a/tests/demo_logging/intake.json +++ b/tests/demo_logging/intake.json @@ -1,8 +1,8 @@ { "action": { "fetch": { - "exe": "python3", "args": [ + "python3", "update.py" ] } diff --git a/tests/demo_oncreate/intake.json b/tests/demo_oncreate/intake.json index 6bfbaa1..4d66043 100644 --- a/tests/demo_oncreate/intake.json +++ b/tests/demo_oncreate/intake.json @@ -1,20 +1,20 @@ { "action": { "fetch": { - "exe": "./update.py", "args": [ + "./update.py", "fetch" ] }, "update": { - "exe": "./update.py", "args": [ + "./update.py", "update" ] }, "on_create": { - "exe": "./update.py", "args": [ + "./update.py", "update" ] } diff --git a/tests/demo_raw_sh/intake.json b/tests/demo_raw_sh/intake.json index c93b584..1fd535d 100644 --- a/tests/demo_raw_sh/intake.json +++ b/tests/demo_raw_sh/intake.json @@ -1,11 +1,11 @@ { "action": { "fetch": { - "exe": "sh", "args": [ + "sh", "-c", "echo {\\\"id\\\": \\\"$(date +%Y-%m-%d-%H-%M)\\\"}" ] } } -} +} \ No newline at end of file diff --git a/tests/test_inbox/intake.json b/tests/test_inbox/intake.json index a8c70a3..2254224 100644 --- a/tests/test_inbox/intake.json +++ b/tests/test_inbox/intake.json @@ -1,8 +1,10 @@ { "action": { "fetch": { - "exe": "./update.py", - "args": ["fetch"] + "args": [ + "./update.py", + "fetch" + ] } } } \ No newline at end of file