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": {
|
"action": {
|
||||||
"fetch": {
|
"fetch": {
|
||||||
"exe": "<absolute path to program or name on intake's PATH>",
|
"args": ["program name", "and", "list", "of", "arguments"]
|
||||||
"args": ["list", "of", "program", "arguments"]
|
|
||||||
},
|
},
|
||||||
"<action name>": {
|
"<action name>": {
|
||||||
"exe": "...",
|
|
||||||
"args": "..."
|
"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.
|
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.
|
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.
|
* intake's environment is inherited.
|
||||||
* `STATE_PATH` is set to the absolute path of `state`.
|
* `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:
|
if "fetch" not in action:
|
||||||
return ("No fetch action defined", {})
|
return ("No fetch action defined", {})
|
||||||
fetch = action["fetch"]
|
fetch = action["fetch"]
|
||||||
if "exe" not in fetch:
|
if "exe" not in fetch and not fetch.get("args"):
|
||||||
return ("No fetch exe", {})
|
return ("No fetch exe", {})
|
||||||
config = {"action": parsed["action"]}
|
config = {"action": parsed["action"]}
|
||||||
if "env" in parsed:
|
if "env" in parsed:
|
||||||
|
@ -399,7 +399,7 @@ def fetch(source_name: str):
|
||||||
update_items(source, items)
|
update_items(source, items)
|
||||||
titles = "\n".join(f"<li>{item.display_title}</li>" for item in items)
|
titles = "\n".join(f"<li>{item.display_title}</li>" for item in items)
|
||||||
source_url = url_for("source_feed", name=source_name)
|
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:
|
except InvalidConfigException as ex:
|
||||||
abort(500, f"Could not fetch {source_name}:\n{ex}")
|
abort(500, f"Could not fetch {source_name}:\n{ex}")
|
||||||
except SourceUpdateException as ex:
|
except SourceUpdateException as ex:
|
||||||
|
@ -417,7 +417,7 @@ def add_item():
|
||||||
config_path = source_path / "intake.json"
|
config_path = source_path / "intake.json"
|
||||||
if not config_path.exists():
|
if not config_path.exists():
|
||||||
config_path.write_text(
|
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)
|
source = LocalSource(source_path.parent, source_path.name)
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@ def cmd_edit(cmd_args):
|
||||||
{
|
{
|
||||||
"action": {
|
"action": {
|
||||||
"fetch": {
|
"fetch": {
|
||||||
"exe": "",
|
|
||||||
"args": [],
|
"args": [],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -229,10 +229,13 @@ def _execute_source_action(
|
||||||
|
|
||||||
if not action_cfg:
|
if not action_cfg:
|
||||||
raise InvalidConfigException(f"No such action {action}")
|
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}")
|
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()}
|
config_env = {key: str(value) for key, value in config.get("env", {}).items()}
|
||||||
env = {
|
env = {
|
||||||
**os.environ.copy(),
|
**os.environ.copy(),
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
{
|
{
|
||||||
"action": {
|
"action": {
|
||||||
"fetch": {
|
"fetch": {
|
||||||
"exe": "true"
|
"args": [
|
||||||
|
"true"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,20 +1,20 @@
|
||||||
{
|
{
|
||||||
"action": {
|
"action": {
|
||||||
"fetch": {
|
"fetch": {
|
||||||
"exe": "./increment.py",
|
|
||||||
"args": [
|
"args": [
|
||||||
|
"./increment.py",
|
||||||
"fetch"
|
"fetch"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"increment": {
|
"increment": {
|
||||||
"exe": "./increment.py",
|
|
||||||
"args": [
|
"args": [
|
||||||
|
"./increment.py",
|
||||||
"increment"
|
"increment"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"decrement": {
|
"decrement": {
|
||||||
"exe": "./increment.py",
|
|
||||||
"args": [
|
"args": [
|
||||||
|
"./increment.py",
|
||||||
"decrement"
|
"decrement"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"action": {
|
"action": {
|
||||||
"fetch": {
|
"fetch": {
|
||||||
"exe": "python3",
|
|
||||||
"args": [
|
"args": [
|
||||||
|
"python3",
|
||||||
"update.py"
|
"update.py"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
{
|
{
|
||||||
"action": {
|
"action": {
|
||||||
"fetch": {
|
"fetch": {
|
||||||
"exe": "./update.py",
|
|
||||||
"args": [
|
"args": [
|
||||||
|
"./update.py",
|
||||||
"fetch"
|
"fetch"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"update": {
|
"update": {
|
||||||
"exe": "./update.py",
|
|
||||||
"args": [
|
"args": [
|
||||||
|
"./update.py",
|
||||||
"update"
|
"update"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"on_create": {
|
"on_create": {
|
||||||
"exe": "./update.py",
|
|
||||||
"args": [
|
"args": [
|
||||||
|
"./update.py",
|
||||||
"update"
|
"update"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"action": {
|
"action": {
|
||||||
"fetch": {
|
"fetch": {
|
||||||
"exe": "sh",
|
|
||||||
"args": [
|
"args": [
|
||||||
|
"sh",
|
||||||
"-c",
|
"-c",
|
||||||
"echo {\\\"id\\\": \\\"$(date +%Y-%m-%d-%H-%M)\\\"}"
|
"echo {\\\"id\\\": \\\"$(date +%Y-%m-%d-%H-%M)\\\"}"
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
{
|
{
|
||||||
"action": {
|
"action": {
|
||||||
"fetch": {
|
"fetch": {
|
||||||
"exe": "./update.py",
|
"args": [
|
||||||
"args": ["fetch"]
|
"./update.py",
|
||||||
|
"fetch"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue