Removed syng-client, syng-server and syng-gui in favor of syng <subcommand>

This commit is contained in:
Christoph Stahl 2024-09-19 14:25:46 +02:00
parent 6a84567545
commit e2655a483b
4 changed files with 36 additions and 112 deletions

View file

@ -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]

View file

@ -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()

View file

@ -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")

View file

@ -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()