From e2655a483b00296cd0c9e91d198dd2c8539e1f46 Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Thu, 19 Sep 2024 14:25:46 +0200 Subject: [PATCH] Removed `syng-client`, `syng-server` and `syng-gui` in favor of `syng ` --- pyproject.toml | 3 --- syng/client.py | 72 +++++++------------------------------------------- syng/main.py | 21 +++++++++++++-- syng/server.py | 52 ++++++------------------------------ 4 files changed, 36 insertions(+), 112 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c5d1b1d..5727e81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,9 +8,6 @@ readme = "README.md" include = ["syng/static"] [tool.poetry.scripts] -syng-client = "syng.client:main" -syng-server = "syng.server:main" -syng-gui = "syng.gui:main" syng = "syng.main:main" [tool.poetry.dependencies] diff --git a/syng/client.py b/syng/client.py index 119def4..5cf871c 100644 --- a/syng/client.py +++ b/syng/client.py @@ -1,53 +1,29 @@ """ Module for the playback client. -Excerp from the help:: - - usage: client.py [-h] [--room ROOM] [--secret SECRET] \ - [--config-file CONFIG_FILE] [--server server] - - options: - -h, --help show this help message and exit - --room ROOM, -r ROOM - --secret SECRET, -s SECRET - --config-file CONFIG_FILE, -C CONFIG_FILE - --key KEY, -k KEY - --server - -The config file should be a yaml file in the following style:: - - sources: - SOURCE1: - configuration for SOURCE - SOURCE2: - configuration for SOURCE - ... - config: - server: ... - room: ... - preview_duration: ... - secret: ... - last_song: ... - waiting_room_policy: .. - key: .. +The client connects to the server via the socket.io protocol, and plays the +songs, that are sent by the server. +Playback is done by the :py:class:`syng.sources.source.Source` objects, that +are configured in the `sources` section of the configuration file and can currently +be one of: + - `youtube` + - `s3` + - `files` """ import asyncio import datetime import logging -import os import secrets import string -from sys import argv, stderr import tempfile import signal -from argparse import ArgumentParser, Namespace +from argparse import Namespace from dataclasses import dataclass from dataclasses import field from traceback import print_exc from typing import Any, Optional -import platformdirs from qrcode.main import QRCode @@ -510,7 +486,6 @@ def run_client(args: Namespace) -> None: if "config" not in config: config["config"] = {} - config["config"] |= {"key": args.key} if args.room: config["config"] |= {"room": args.room} if args.secret: @@ -519,32 +494,3 @@ def run_client(args: Namespace) -> None: config["config"] |= {"server": args.server} create_async_and_start_client(config) - - -def main() -> None: - """Entry point for the syng-client script.""" - - print( - f"Starting the client with {argv[0]} is deprecated. " - "Please use `syng client` to start the client", - file=stderr, - ) - parser: ArgumentParser = ArgumentParser() - - parser.add_argument("--room", "-r") - parser.add_argument("--secret", "-s") - parser.add_argument( - "--config-file", - "-C", - default=f"{os.path.join(platformdirs.user_config_dir('syng'), 'config.yaml')}", - ) - parser.add_argument("--key", "-k", default=None) - parser.add_argument("--server", "-S") - - args = parser.parse_args() - - run_client(args) - - -if __name__ == "__main__": - main() diff --git a/syng/main.py b/syng/main.py index 482ee52..c90b738 100644 --- a/syng/main.py +++ b/syng/main.py @@ -9,10 +9,27 @@ imports them if they are. If they are not available, the application will not run the client or server functions. Client usage: syng client [-h] [--room ROOM] [--secret SECRET] \ - [--config-file CONFIG_FILE] [--key KEY] [--server SERVER] + [--config-file CONFIG_FILE] [--server SERVER] Server usage: syng server [-h] [--host HOST] [--port PORT] [--root-folder ROOT_FOLDER] \ [--registration-keyfile REGISTRATION_KEYFILE] [--private] [--restricted] GUI usage: syng gui + +The config file for the client should be a yaml file in the following style:: + + sources: + SOURCE1: + configuration for SOURCE + SOURCE2: + configuration for SOURCE + ... + config: + server: ... + room: ... + preview_duration: ... + secret: ... + last_song: ... + waiting_room_policy: .. + key: .. """ from typing import TYPE_CHECKING @@ -66,7 +83,7 @@ def main() -> None: "-C", default=f"{os.path.join(platformdirs.user_config_dir('syng'), 'config.yaml')}", ) - client_parser.add_argument("--key", "-k", default=None) + # client_parser.add_argument("--key", "-k", default=None) client_parser.add_argument("--server", "-S") sub_parsers.add_parser("gui") diff --git a/syng/server.py b/syng/server.py index c2e1529..defef3e 100644 --- a/syng/server.py +++ b/syng/server.py @@ -1,16 +1,14 @@ """ Module for the Server. -Starts a async socketio server, and serves the web client:: - - usage: server.py [-h] [--host HOST] [--port PORT] [--root-folder PATH] - - options: - -h, --help show this help message and exit - --host HOST, -H HOST - --port PORT, -p PORT - --root-folder PATH, -r PATH +The server listens for incoming connections from playback clients and web +clients via the socket.io protocol. +It manages multiple independent rooms, each with its own queue and configuration. +If configured, the server can be in private mode, where only playback clients with +a valid registration key can connect. It can also be in restricted mode, where only +search is forwarded to the playback client, unless the client has a valid registration +key. """ from __future__ import annotations @@ -23,10 +21,9 @@ import os import random import string from json.decoder import JSONDecodeError -from argparse import ArgumentParser, Namespace +from argparse import Namespace from dataclasses import dataclass from dataclasses import field -from sys import argv, stderr from typing import Any from typing import AsyncGenerator from typing import Optional @@ -1240,36 +1237,3 @@ def run_server(args: Namespace) -> None: app.cleanup_ctx.append(background_tasks) web.run_app(app, host=args.host, port=args.port) - - -def main() -> None: - """ - Configure and start the server. - - Parse the command line arguments, register static routes to serve the web - client and start the server. - - :rtype: None - """ - - print( - f"Starting the server with {argv[0]} is deprecated. " - "Please use `syng server` to start the server", - file=stderr, - ) - - root_path = os.path.join(os.path.dirname(__file__), "static") - parser = ArgumentParser() - parser.add_argument("--host", "-H", default="localhost") - parser.add_argument("--port", "-p", type=int, default=8080) - parser.add_argument("--root-folder", "-r", default=root_path) - parser.add_argument("--registration-keyfile", "-k", default=None) - parser.add_argument("--private", "-P", action="store_true", default=False) - parser.add_argument("--restricted", "-R", action="store_true", default=False) - args = parser.parse_args() - - run_server(args) - - -if __name__ == "__main__": - main()