Fold action.exe into action.args
This commit is contained in:
parent
9bb331941f
commit
381de535f7
10
README.md
10
README.md
|
@ -31,11 +31,9 @@ intake
|
|||
{
|
||||
"action": {
|
||||
"fetch": {
|
||||
"exe": "<absolute path to program or name on intake's PATH>",
|
||||
"args": ["list", "of", "program", "arguments"]
|
||||
"args": ["program name", "and", "list", "of", "arguments"]
|
||||
},
|
||||
"<action name>": {
|
||||
"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`.
|
||||
|
|
|
@ -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"<li>{item.display_title}</li>" for item in items)
|
||||
source_url = url_for("source_feed", name=source_name)
|
||||
return f"Update returned {len(items)} items:<ul>{titles}</ul><p><a href=\"{source_url}\">{source_name}</a></p>"
|
||||
return f'Update returned {len(items)} items:<ul>{titles}</ul><p><a href="{source_url}">{source_name}</a></p>'
|
||||
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)
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@ def cmd_edit(cmd_args):
|
|||
{
|
||||
"action": {
|
||||
"fetch": {
|
||||
"exe": "",
|
||||
"args": [],
|
||||
},
|
||||
},
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
{
|
||||
"action": {
|
||||
"fetch": {
|
||||
"exe": "true"
|
||||
"args": [
|
||||
"true"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"action": {
|
||||
"fetch": {
|
||||
"exe": "python3",
|
||||
"args": [
|
||||
"python3",
|
||||
"update.py"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
"action": {
|
||||
"fetch": {
|
||||
"exe": "sh",
|
||||
"args": [
|
||||
"sh",
|
||||
"-c",
|
||||
"echo {\\\"id\\\": \\\"$(date +%Y-%m-%d-%H-%M)\\\"}"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
{
|
||||
"action": {
|
||||
"fetch": {
|
||||
"exe": "./update.py",
|
||||
"args": ["fetch"]
|
||||
"args": [
|
||||
"./update.py",
|
||||
"fetch"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue