Drop the config.spec/configobj configuration in favour of an AppSettings pydantic-settings model (settings.py) loaded from SMILEYFACE_-prefixed env vars or a .env file. Introduce AppContext (context.py) to carry settings plus logging, dispatch commands through a Click CLI (cli.py), and centralise log setup (logging_setup.py). Update hub_machine, datalayer, and scraping modules to consume the new context. Add .env.example and ignore .env. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
146 lines
3.5 KiB
Python
146 lines
3.5 KiB
Python
import click
|
|
|
|
from smileyface.context import AppContext
|
|
from smileyface.logging_setup import setup_logging
|
|
from smileyface.settings import AppSettings
|
|
|
|
|
|
def _make_ctx():
|
|
"""Build the application context, datalayer, and command instances."""
|
|
from smileyface import datalayer, hub_machine, scrape_latest
|
|
|
|
settings = AppSettings()
|
|
setup_logging()
|
|
ctx = AppContext(settings)
|
|
dal = datalayer.DataLayer(ctx)
|
|
db = datalayer.DbFuncs(ctx, dal)
|
|
machine = hub_machine.UT4ServerMachine(ctx, db)
|
|
scrape_pugs = scrape_latest.ScrapeUt4Pugs(ctx, db)
|
|
scrape_utcc = scrape_latest.ScrapeUtcc(ctx, db)
|
|
local_fs = scrape_latest.LocalFs(ctx, db)
|
|
return machine, scrape_pugs, scrape_utcc, local_fs
|
|
|
|
|
|
@click.group()
|
|
def cli():
|
|
"""SmileyFace UT4 Server Panel"""
|
|
pass
|
|
|
|
|
|
@cli.command("oneclickdeploy")
|
|
def oneclickdeploy():
|
|
"""Generate instance, upload redirects, and upload server."""
|
|
machine, *_ = _make_ctx()
|
|
machine.oneclickdeploy()
|
|
|
|
|
|
@cli.command("clean-instance")
|
|
def clean_instance():
|
|
"""Deletes the generated instance on the local machine."""
|
|
machine, *_ = _make_ctx()
|
|
machine.clean_instance()
|
|
|
|
|
|
@cli.command("create-directories")
|
|
def create_directories():
|
|
"""Create required directories for maps, mutators, and config."""
|
|
machine, *_ = _make_ctx()
|
|
machine.create_directories()
|
|
|
|
|
|
@cli.command("download-linux-server")
|
|
def download_linux_server():
|
|
"""Download the latest Linux UT4 Server from Epic."""
|
|
machine, *_ = _make_ctx()
|
|
machine.download_linux_server()
|
|
|
|
|
|
@cli.command("download-logs")
|
|
def download_logs():
|
|
"""Download the logs from the target hub."""
|
|
machine, *_ = _make_ctx()
|
|
machine.download_logs()
|
|
|
|
|
|
@cli.command("generate-instance")
|
|
def generate_instance():
|
|
"""Build local server instance from current configuration."""
|
|
machine, *_ = _make_ctx()
|
|
machine.generate_instance()
|
|
|
|
|
|
@cli.command("restart-server")
|
|
def restart_server():
|
|
"""Restart the UT4 server."""
|
|
machine, *_ = _make_ctx()
|
|
machine.restart_server()
|
|
|
|
|
|
@cli.command("start-server")
|
|
def start_server():
|
|
"""Start the UT4 server."""
|
|
machine, *_ = _make_ctx()
|
|
machine.start_server()
|
|
|
|
|
|
@cli.command("stop-server")
|
|
def stop_server():
|
|
"""Stop the UT4 server."""
|
|
machine, *_ = _make_ctx()
|
|
machine.stop_server()
|
|
|
|
|
|
@cli.command("upload-redirects")
|
|
def upload_redirects():
|
|
"""Upload paks to redirect server."""
|
|
machine, *_ = _make_ctx()
|
|
machine.upload_redirects()
|
|
|
|
|
|
@cli.command("upload-server")
|
|
def upload_server():
|
|
"""Upload game files to the hub server."""
|
|
machine, *_ = _make_ctx()
|
|
machine.upload_server()
|
|
|
|
|
|
@cli.group("scrape")
|
|
def scrape():
|
|
"""Web scraping subcommands."""
|
|
pass
|
|
|
|
|
|
@scrape.command("ut4pugs")
|
|
def scrape_ut4pugs():
|
|
"""Check ut4pugs.us for latest content."""
|
|
_, pugs, *_ = _make_ctx()
|
|
pugs.check_ut4pugs_for_latest()
|
|
|
|
|
|
@scrape.command("utcc")
|
|
def scrape_utcc_cmd():
|
|
"""Check utcc.unrealpugs.com for latest content."""
|
|
*_, utcc, _ = _make_ctx()
|
|
utcc.check_ut4cc_for_latest()
|
|
|
|
|
|
@scrape.command("create-db-table")
|
|
def create_db_table():
|
|
"""Create database tables."""
|
|
*_, local_fs = _make_ctx()
|
|
local_fs.create_db_table()
|
|
|
|
|
|
@scrape.command("load-md5s")
|
|
def load_md5s():
|
|
"""Load MD5 checksums from local pak files."""
|
|
*_, local_fs = _make_ctx()
|
|
local_fs.load_md5s()
|
|
|
|
|
|
@scrape.command("print-invalid")
|
|
def print_invalid():
|
|
"""Print pak files that failed validation."""
|
|
*_, local_fs = _make_ctx()
|
|
local_fs.print_invalid_filepaks()
|