mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
refactor Paths and update build workflow
+ rename app_dir -> config_dir and config_dir to config_parent + bundle web client as zip + bundle and extract client zip when running pyinstaller builds + installer pyinstaller as main dependency + remove fallback client flag + handle already used port + add assethandler class + remove some startup logs + ignore wheels and client.zip files
This commit is contained in:
+47
-56
@@ -1,67 +1,45 @@
|
||||
import argparse
|
||||
import sys
|
||||
import pathlib
|
||||
import argparse
|
||||
import multiprocessing
|
||||
from importlib.metadata import version
|
||||
|
||||
import multiprocessing
|
||||
|
||||
from swingmusic import settings
|
||||
from swingmusic.logger import setup_logger
|
||||
from swingmusic.settings import default_base_path
|
||||
from swingmusic.start_swingmusic import start_swingmusic
|
||||
from swingmusic import tools as swing_tools
|
||||
from swingmusic.settings import AssetHandler
|
||||
from swingmusic.start_swingmusic import start_swingmusic
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='swingmusic',
|
||||
description='Awesome Music',
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter
|
||||
prog="swingmusic",
|
||||
description="Awesome Music",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-v', '--version',
|
||||
action='version',
|
||||
version=f"swingmusic v{version('swingmusic')}")
|
||||
parser.add_argument(
|
||||
"--host",
|
||||
default="0.0.0.0",
|
||||
help="Host to run the app on."
|
||||
"-v", "--version", action="version", version=f"swingmusic v{version('swingmusic')}"
|
||||
)
|
||||
parser.add_argument("--host", default="0.0.0.0", help="Host to run the app on.")
|
||||
parser.add_argument(
|
||||
"--port",
|
||||
default=1970,
|
||||
help="HTTP port to run the app on.",
|
||||
type=int
|
||||
"--port", default=1970, help="HTTP port to run the app on.", type=int
|
||||
)
|
||||
parser.add_argument(
|
||||
"--debug",
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="If swingmusic should start in debug mode"
|
||||
help="If swingmusic should start in debug mode",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--config",
|
||||
default=default_base_path(),
|
||||
help="Path to the config file.",
|
||||
type=pathlib.Path
|
||||
)
|
||||
parser.add_argument(
|
||||
"--client",
|
||||
help="Path to the Web UI folder.",
|
||||
type=pathlib.Path
|
||||
default=settings.Paths.get_default_config_parent_dir(),
|
||||
help="The directory to setup the config folder.",
|
||||
type=pathlib.Path,
|
||||
)
|
||||
parser.add_argument("--client", help="Path to the Web UI folder.", type=pathlib.Path)
|
||||
|
||||
parser.add_argument(
|
||||
"--fallback-client",
|
||||
help="Path to the Web UI folder if no valid client is found. Used in pyinstaller and appimage.",
|
||||
type=pathlib.Path
|
||||
)
|
||||
tools = parser.add_argument_group(title="Tools")
|
||||
tools.add_argument("--password-reset", help="Reset the password.", action="store_true")
|
||||
|
||||
tools = parser.add_argument_group(
|
||||
title="Tools"
|
||||
)
|
||||
tools.add_argument(
|
||||
"--password-reset",
|
||||
help="Reset the password.",
|
||||
action='store_true'
|
||||
)
|
||||
|
||||
def run(*args, **kwargs):
|
||||
"""
|
||||
@@ -70,26 +48,39 @@ def run(*args, **kwargs):
|
||||
args = parser.parse_args()
|
||||
args = vars(args)
|
||||
|
||||
path = {
|
||||
"config": args["config"],
|
||||
"client": args["client"],
|
||||
"fallback": args["fallback_client"]
|
||||
}
|
||||
config_parent = args["config"]
|
||||
client_path = args["client"]
|
||||
|
||||
setup_logger(debug=args["debug"], app_dir=path["config"])
|
||||
# INFO: Validate client path
|
||||
if client_path is not None:
|
||||
client_path = pathlib.Path(client_path).resolve()
|
||||
|
||||
if not client_path.exists():
|
||||
print(
|
||||
f"Client path {client_path} does not exist. Please provide a valid path"
|
||||
)
|
||||
sys.exit(1)
|
||||
else:
|
||||
# INFO: check if client path has index.html
|
||||
if not (client_path / "index.html").exists():
|
||||
print(
|
||||
f"Client path {client_path} does not contain an index.html file. Please provide a valid path"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
# check tools
|
||||
settings.Paths(config_parent=config_parent, client_dir=client_path)
|
||||
AssetHandler.copy_assets_dir()
|
||||
AssetHandler.setup_default_client()
|
||||
|
||||
setup_logger(debug=args["debug"], app_dir=settings.Paths().config_dir)
|
||||
|
||||
# handle tools
|
||||
if args["password_reset"]:
|
||||
swing_tools.handle_password_reset(path)
|
||||
swing_tools.handle_password_reset(config_parent)
|
||||
sys.exit(0)
|
||||
|
||||
# else start swingmusic
|
||||
else:
|
||||
start_swingmusic(
|
||||
host=args["host"],
|
||||
port=args["port"],
|
||||
path=path
|
||||
)
|
||||
# start swingmusic
|
||||
start_swingmusic(host=args["host"], port=args["port"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user