footer imrpove
This commit is contained in:
@@ -435,6 +435,28 @@ def disk_usage_for_default_path(profile: dict) -> dict:
|
||||
return usage
|
||||
|
||||
|
||||
|
||||
def _safe_rtorrent_int(callable_obj, default=None):
|
||||
"""Return an integer rTorrent metric without failing the whole status poll."""
|
||||
try:
|
||||
value = callable_obj()
|
||||
return int(value)
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
def _safe_rtorrent_time(c):
|
||||
"""Read rTorrent server time when supported; otherwise let the browser clock remain authoritative."""
|
||||
candidates = (
|
||||
lambda: c.system.time_seconds(),
|
||||
lambda: c.system.time(),
|
||||
)
|
||||
for candidate in candidates:
|
||||
value = _safe_rtorrent_int(candidate)
|
||||
if value:
|
||||
return value
|
||||
return None
|
||||
|
||||
def system_status(profile: dict) -> dict:
|
||||
c = client_for(profile)
|
||||
version = str(c.system.client_version())
|
||||
@@ -447,13 +469,19 @@ def system_status(profile: dict) -> dict:
|
||||
except Exception:
|
||||
up_limit = 0
|
||||
rows = list_torrents(profile)
|
||||
# Note: ruTorrent-style footer metrics. Missing XMLRPC methods are shown as unavailable instead of breaking polling.
|
||||
open_sockets = _safe_rtorrent_int(lambda: c.network.open_sockets())
|
||||
max_open_sockets = _safe_rtorrent_int(lambda: c.network.max_open_sockets())
|
||||
rtorrent_time = _safe_rtorrent_time(c)
|
||||
checking_count = sum(1 for t in rows if t.get("status") == "Checking" or int(t.get("hashing") or 0) > 0)
|
||||
return {
|
||||
"ok": True,
|
||||
"version": version,
|
||||
"total": len(rows),
|
||||
"active": sum(1 for t in rows if t["state"]),
|
||||
"seeding": sum(1 for t in rows if t["complete"] and t["state"] and not t.get("paused")),
|
||||
"leeching": sum(1 for t in rows if not t["complete"] and t["state"] and not t.get("paused")),
|
||||
"leeching": sum(1 for t in rows if not t["complete"] and t["state"] and not t.get("paused") and t.get("status") != "Checking"),
|
||||
"checking": checking_count,
|
||||
"paused": sum(1 for t in rows if t.get("paused")),
|
||||
"stopped": sum(1 for t in rows if not t["state"]),
|
||||
"down_rate": sum(t["down_rate"] for t in rows),
|
||||
@@ -468,6 +496,9 @@ def system_status(profile: dict) -> dict:
|
||||
"total_up": sum(t["up_total"] for t in rows),
|
||||
"total_down_h": human_size(sum(t["down_total"] for t in rows)),
|
||||
"total_up_h": human_size(sum(t["up_total"] for t in rows)),
|
||||
"open_sockets": open_sockets,
|
||||
"max_open_sockets": max_open_sockets,
|
||||
"rtorrent_time": rtorrent_time,
|
||||
"disk": disk_usage_for_default_path(profile),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user