2022-11-19 15:14:12 -08:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import typer
|
|
|
|
|
|
|
|
from dotenv import load_dotenv
|
2022-11-20 01:00:54 -08:00
|
|
|
from sqlalchemy import create_engine
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
2022-11-19 15:14:12 -08:00
|
|
|
from groove import ondemand
|
2022-11-20 01:00:54 -08:00
|
|
|
from groove.db import metadata
|
2022-11-19 15:14:12 -08:00
|
|
|
|
|
|
|
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
|
|
|
2022-11-20 01:00:54 -08:00
|
|
|
@app.command()
|
|
|
|
def initialize():
|
|
|
|
load_dotenv()
|
|
|
|
|
|
|
|
# todo: abstract this and replace in_memory_db fixture
|
|
|
|
engine = create_engine(f"sqlite:///{os.environ.get('DATABASE_PATH')}", future=True)
|
|
|
|
Session = sessionmaker(bind=engine, future=True)
|
|
|
|
session = Session()
|
|
|
|
metadata.create_all(bind=engine)
|
|
|
|
session.close()
|
|
|
|
|
|
|
|
|
2022-11-19 15:14:12 -08:00
|
|
|
@app.command()
|
|
|
|
def server(
|
|
|
|
host: str = typer.Argument(
|
|
|
|
'0.0.0.0',
|
|
|
|
help="bind address",
|
|
|
|
),
|
|
|
|
port: int = typer.Argument(
|
|
|
|
2323,
|
|
|
|
help="bind port",
|
|
|
|
),
|
|
|
|
debug: bool = typer.Option(
|
|
|
|
False,
|
|
|
|
help='Enable debugging output'
|
|
|
|
),
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
Start the Groove on Demand playlsit server.
|
|
|
|
"""
|
|
|
|
load_dotenv()
|
|
|
|
|
2022-11-20 01:00:54 -08:00
|
|
|
ondemand.initialize()
|
|
|
|
|
2022-11-19 15:14:12 -08:00
|
|
|
print("Starting Groove On Demand...")
|
|
|
|
|
|
|
|
debug = os.getenv('DEBUG', None)
|
|
|
|
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.DEBUG if debug else logging.INFO)
|
|
|
|
ondemand.server.run(
|
|
|
|
host=os.getenv('HOST', host),
|
|
|
|
port=os.getenv('PORT', port),
|
|
|
|
debug=debug,
|
|
|
|
server='paste',
|
|
|
|
quiet=True
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app()
|