Hosts#
Execution hosts: this machine, or a remote server behind an SSH session.
- exception remote_compression.host.BootstrapError[source]#
A prerequisite is missing (ffmpeg, workspace…); the batch cannot start.
- remote_compression.host.GRACE = 30.0#
Seconds granted to a remote output to appear after a reconnection.
- class remote_compression.host.HostResult(ok: bool, exit_status: int | None = None, stderr_tail: str = '', reason: str = '')[source]#
Outcome of one compression attempt on a host.
- class remote_compression.host.LocalHost(encoder=None)[source]#
Compression on this very machine.
- Parameters:
encoder (
str, optional) – Encoder whose availability is verified at bootstrap.
- bootstrap()[source]#
- Raises:
BootstrapError – If ffmpeg is not in the local PATH, or lacks the requested encoder.
- compress_file(source, target, plan, on_progress=None)[source]#
Run ffmpeg locally.
- Parameters:
source (
Path) – Input video.target (
Path) – Output video (the temporarycomp_*file).plan (
FfmpegPlan) – Command to run.on_progress (callable, optional) – Receives decoded chunks of the ffmpeg
-progressstream.
- Return type:
- remote_compression.host.POLL = 10.0#
Orphan polling interval.
- class remote_compression.host.PurgeReport(removed: list, failed: list, dry_run: bool)[source]#
Outcome of a workspace purge.
- remote_compression.host.RECONNECT_WINDOW = 300.0#
Seconds granted to get the connection back mid-batch.
- class remote_compression.host.RemoteHost(hostname, config_path=None, auto_purge_days=7.0, encoder=None, remote_ffmpeg=None, workdir=None, workdir_sftp=None, session=None)[source]#
Compression on a remote server, over a single SSH session.
All file operations go through SFTP (platform-agnostic: Linux and Windows servers behave the same); only
ffmpeg -versionand the ffmpeg command itself are executed remotely, with a syntax common to sh and cmd.exe.- Parameters:
hostname (
str) – SSH alias of the server.config_path (
str, optional) – Alternative openSSH config file.auto_purge_days (
float, optional) – Age threshold of the opportunistic purge run at connection time (None disables it).encoder (
str, optional) – Encoder whose availability is verified at bootstrap.remote_ffmpeg (
str, optional) – Explicit path of the ffmpeg binary on the server (space-free ASCII; for hosts whose non-interactive PATH misses ffmpeg).workdir (
str, optional) – Workspace directory as seen by the shell running ffmpeg (default:.rcomp, relative to the login home).workdir_sftp (
str, optional) – The same directory as seen by the SFTP channel, when the two views differ (Synology chroots SFTP: its/homeis the login home, so/home/.rcomppairs with the default workdir). Defaults to workdir.session (
SSHSession, optional) – Injected session (tests).
- check_ffmpeg()[source]#
- Raises:
BootstrapError – If ffmpeg fails on the server, or lacks the requested encoder.
- compress_file(source, target, plan, on_progress=None)[source]#
Upload, encode remotely, download.
On a connection loss, reconnects patiently then tries to re-attach to the orphan encode (ffmpeg may well survive the disconnection on the server) instead of blindly relaunching. At most one relaunch, always with fresh temporary names — a zombie may still be writing to the old target.
- Parameters:
source (
Path) – Local input video.target (
Path) – Local output (the temporarycomp_*file).plan (
FfmpegPlan) – Command to run.on_progress (callable, optional) – Receives decoded chunks of the ffmpeg
-progressstream.
- Return type:
- Raises:
SSHConnectionError – When the connection cannot be recovered, or is lost twice on the same file: the batch cannot reasonably continue.
- ensure_workspace()[source]#
Create the remote workspace when missing (pure SFTP).
- Raises:
BootstrapError – If it can neither be accessed nor created.
- purge_workspace(older_than=datetime.timedelta(0), dry_run=False)[source]#
Remove workspace files older than a threshold.
- Parameters:
older_than (
datetime.timedelta) – Minimal age (local clock vs remote mtimes; skew is negligible at the thresholds in use). Zero purges everything.dry_run (
bool) – List without removing.
- Returns:
Individual removal failures are collected, never raised.
- Return type:
- workspace_status()[source]#
- Returns:
Regular files of the workspace (sub-directories and symlinks are ignored), sorted by mtime; None when the workspace does not exist.
- Return type:
WorkspaceStatusor None
- remote_compression.host.SETTLE_TIME = 60.0#
A remote output whose size stalls this long is finished (or dead).
- remote_compression.host.WORKDIR = '.rcomp'#
Remote working directory, relative to the SFTP home (never absolutized: OpenSSH on Windows reports homes as
/C:/..., invalid in a cmd argv).
- class remote_compression.host.WorkspaceEntry(name: str, size: int, mtime: float)[source]#
A regular file in the remote workspace.
- age(now=None)[source]#
datetime.timedelta: age of the file (relative to local now).
- class remote_compression.host.WorkspaceStatus(entries: list)[source]#
Content of the remote workspace.