more conditions in automations

This commit is contained in:
Mateusz Gruszczyński
2026-05-06 21:58:49 +02:00
parent 21cbd5baa6
commit e2017b8344
5 changed files with 111 additions and 59 deletions

View File

@@ -137,8 +137,11 @@ def _apply_effects(c: Any, profile: dict[str, Any], torrent: dict[str, Any], eff
for eff in effects:
typ = str(eff.get('type') or '')
if typ == 'move':
# Note: Automation move-to-path now uses the same move implementation as the main app action.
path = str(eff.get('path') or '').strip() or rtorrent.default_download_path(profile)
if path: c.call('d.directory.set', h, path); applied.append({'type': 'move', 'path': path})
move_payload = {'path': path, 'move_data': bool(eff.get('move_data')), 'recheck': bool(eff.get('recheck', eff.get('move_data'))), 'keep_seeding': bool(eff.get('keep_seeding'))}
result = rtorrent.move_torrents(profile, [h], move_payload) if path else None
if path: applied.append({'type': 'move', 'path': path, 'move_data': bool(eff.get('move_data')), 'recheck': bool(move_payload['recheck']), 'keep_seeding': bool(eff.get('keep_seeding')), 'result': result})
elif typ == 'add_label':
label = str(eff.get('label') or '').strip()
if label and label not in labels: labels.append(label); c.call('d.custom1.set', h, _label_value(labels))

View File

@@ -1274,36 +1274,23 @@ def start_or_resume_hash(c: ScgiRtorrentClient, torrent_hash: str) -> dict:
result['ok'] = result.get('ok', True)
return result
def action(profile: dict, torrent_hashes: list[str], name: str, payload: dict | None = None) -> dict:
def move_torrents(profile: dict, torrent_hashes: list[str], payload: dict | None = None) -> dict:
# Note: Shared move implementation keeps API move and automation move-to-path identical.
payload = payload or {}
c = client_for(profile)
methods = {
"stop": "d.stop",
"recheck": "d.check_hash",
"reannounce": "d.tracker_announce",
"remove": "d.erase",
}
if name == "set_label":
label = str(payload.get("label") or "").strip()
for h in torrent_hashes:
c.call("d.custom1.set", h, label)
return {"ok": True, "count": len(torrent_hashes), "label": label}
if name == "set_ratio_group":
group = str(payload.get("ratio_group") or "").strip()
for h in torrent_hashes:
c.call("d.custom.set", h, "py_ratio_group", group)
return {"ok": True, "count": len(torrent_hashes), "ratio_group": group}
if name == "move":
path = _remote_clean_path(payload.get("path") or "")
move_data = bool(payload.get("move_data"))
recheck = bool(payload.get("recheck", move_data))
keep_seeding = bool(payload.get("keep_seeding"))
# Note: keep_seeding lets automation move completed data to another path and force the torrent back into seeding.
if not path:
raise ValueError("Missing path")
results = []
if move_data:
_rt_execute_allow_timeout(c, "execute.throw", "mkdir", "-p", path)
for h in torrent_hashes:
item = {"hash": h, "path": path, "move_data": move_data}
item = {"hash": h, "path": path, "move_data": move_data, "keep_seeding": keep_seeding}
try:
was_state = int(c.call("d.state", h) or 0)
except Exception:
@@ -1337,15 +1324,45 @@ def action(profile: dict, torrent_hashes: list[str], name: str, payload: dict |
c.call("d.check_hash", h)
except Exception as exc:
item["recheck_error"] = str(exc)
if was_state or was_active:
if keep_seeding or was_state or was_active:
try:
c.call("d.start", h)
except Exception:
pass
item["started_after_move"] = True
except Exception as exc:
item["start_error"] = str(exc)
else:
c.call("d.directory.set", h, path)
if keep_seeding:
try:
c.call("d.start", h)
item["started_after_path_change"] = True
except Exception as exc:
item["start_error"] = str(exc)
results.append(item)
return {"ok": True, "count": len(torrent_hashes), "move_data": move_data, "results": results}
return {"ok": True, "count": len(torrent_hashes), "move_data": move_data, "keep_seeding": keep_seeding, "results": results}
def action(profile: dict, torrent_hashes: list[str], name: str, payload: dict | None = None) -> dict:
payload = payload or {}
c = client_for(profile)
methods = {
"stop": "d.stop",
"recheck": "d.check_hash",
"reannounce": "d.tracker_announce",
"remove": "d.erase",
}
if name == "set_label":
label = str(payload.get("label") or "").strip()
for h in torrent_hashes:
c.call("d.custom1.set", h, label)
return {"ok": True, "count": len(torrent_hashes), "label": label}
if name == "set_ratio_group":
group = str(payload.get("ratio_group") or "").strip()
for h in torrent_hashes:
c.call("d.custom.set", h, "py_ratio_group", group)
return {"ok": True, "count": len(torrent_hashes), "ratio_group": group}
if name == "move":
# Note: Main move delegates to the shared helper used by automations.
return move_torrents(profile, torrent_hashes, payload)
if name == "pause":
# Note: The app pause action is now a pure d.pause so later resume works without stop/start.
results = [pause_hash(c, h) for h in torrent_hashes]

File diff suppressed because one or more lines are too long

View File

@@ -1244,6 +1244,30 @@ body.mobile-mode .mobile-card {
gap: 0.5rem;
align-items: center;
}
.auto-move-option {
gap: 0.45rem;
margin: 0;
}
.automation-builder-list {
display: grid;
grid-column: 1 / -1;
gap: 0.4rem;
}
.automation-chip {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
padding: 0.4rem 0.55rem;
border: 1px solid var(--bs-border-color);
border-radius: 0.55rem;
background: var(--bs-secondary-bg);
}
.automation-row {
display: flex;
justify-content: space-between;

File diff suppressed because one or more lines are too long