feat(pyvtt): add CI pipeline and restructure project
All checks were successful
Build and Publish / build-and-publish (push) Successful in 21s
All checks were successful
Build and Publish / build-and-publish (push) Successful in 21s
- Add GitHub Actions workflow for building and publishing packages. - Introduce `pyproject.toml` for project metadata and dependency management. - Remove `requirements.txt` in favor of Poetry for dependency handling. - Restructure source files under `src/pyvtt` for better organization. - Enhance `notify.py` with sound playback and improve error handling. - Update `voice_to_text_tray.py` to support dynamic configuration reload. - Add `.vscode/settings.json` for improved IDE configuration. - Update `.gitignore` to exclude build artifacts. Signed-off-by: Max P. <Mail@MPassarello.de>
This commit is contained in:
52
src/pyvtt/send_cmd.py
Executable file
52
src/pyvtt/send_cmd.py
Executable file
@@ -0,0 +1,52 @@
|
||||
import socket
|
||||
import sys
|
||||
import argparse
|
||||
from src.pyvtt.configuration import read_configurations
|
||||
|
||||
CONFIGURATION = read_configurations()
|
||||
|
||||
def send_cmd(cmd: str, socket_path: str):
|
||||
"""
|
||||
Sends a command to a Unix domain socket server.
|
||||
|
||||
This function creates a Unix domain socket, connects to the server
|
||||
specified by the socket_path, and sends the provided command as a
|
||||
UTF-8 encoded string.
|
||||
|
||||
Args:
|
||||
cmd (str): The command to send to the server.
|
||||
socket_path (str): The path to the Unix domain socket.
|
||||
|
||||
Raises:
|
||||
FileNotFoundError: If the socket file specified by socket_path does not exist.
|
||||
ConnectionRefusedError: If the connection to the server is refused.
|
||||
OSError: For other socket-related errors.
|
||||
"""
|
||||
try:
|
||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as client:
|
||||
client.settimeout(3)
|
||||
client.connect(socket_path)
|
||||
client.sendall(cmd.encode())
|
||||
except FileNotFoundError:
|
||||
print(f"Error: The socket file '{socket_path}' does not exist.", file=sys.stderr, flush=True)
|
||||
except ConnectionRefusedError:
|
||||
print(f"Error: Connection to the server at '{socket_path}' was refused.", file=sys.stderr, flush=True)
|
||||
except socket.timeout:
|
||||
print("Error: Socket operation timed out.", file=sys.stderr, flush=True)
|
||||
except OSError as e:
|
||||
print(f"Socket error: {e}", file=sys.stderr, flush=True)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Send a command to a Unix domain socket server."
|
||||
)
|
||||
parser.add_argument(
|
||||
"command",
|
||||
choices=["start", "stop", "toggle"],
|
||||
nargs="?",
|
||||
default="toggle",
|
||||
help="The command to send to the server (default: toggle).",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
send_cmd(args.command, CONFIGURATION["socket_path"])
|
Reference in New Issue
Block a user