|
@@ -2,34 +2,37 @@
|
|
|
This module is for the main application logic
|
|
|
"""
|
|
|
from __future__ import print_function
|
|
|
-from gevent import monkey
|
|
|
-
|
|
|
-monkey.patch_all(subprocess=True)
|
|
|
|
|
|
-import sys
|
|
|
-import os
|
|
|
-import tempfile
|
|
|
-import signal
|
|
|
-from time import sleep
|
|
|
import logging
|
|
|
import logging.config
|
|
|
+import os
|
|
|
+import signal
|
|
|
import subprocess
|
|
|
+import sys
|
|
|
+import tempfile
|
|
|
+from time import sleep
|
|
|
|
|
|
import gevent
|
|
|
+from gevent import monkey
|
|
|
from gevent.pywsgi import WSGIServer
|
|
|
|
|
|
-from .mpc import Controller, get_mpd_client
|
|
|
from .config import get_conf
|
|
|
+from .mpc import Controller, get_mpd_client
|
|
|
from .rpc import create_app
|
|
|
|
|
|
+monkey.patch_all(subprocess=True)
|
|
|
+
|
|
|
|
|
|
def on_main_crash(*args, **kwargs):
|
|
|
print('A crash occurred in "main" greenlet. Aborting...')
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
class Larigira(object):
|
|
|
def __init__(self):
|
|
|
+
|
|
|
self.log = logging.getLogger("larigira")
|
|
|
self.conf = get_conf()
|
|
|
self.controller = Controller(self.conf)
|
|
@@ -62,6 +65,7 @@ def main():
|
|
|
)
|
|
|
if not os.path.isdir(os.environ["TMPDIR"]):
|
|
|
os.makedirs(os.environ["TMPDIR"])
|
|
|
+
|
|
|
if get_conf()["LOG_CONFIG"]:
|
|
|
logging.config.fileConfig(
|
|
|
get_conf()["LOG_CONFIG"], disable_existing_loggers=True
|
|
@@ -73,12 +77,26 @@ def main():
|
|
|
format=log_format,
|
|
|
datefmt="%H:%M:%S",
|
|
|
)
|
|
|
+ logging.addLevelName(9, "DEBUGV")
|
|
|
+
|
|
|
+ def debugv(self, message, *args, **kws):
|
|
|
+ if self.isEnabledFor(9):
|
|
|
+ self._log(9, message, args, **kws)
|
|
|
+
|
|
|
+ logging.Logger.debugv = debugv
|
|
|
+
|
|
|
if get_conf()["MPD_WAIT_START"]:
|
|
|
+
|
|
|
while True:
|
|
|
try:
|
|
|
get_mpd_client(get_conf())
|
|
|
- except Exception:
|
|
|
- logging.debug("Could not connect to MPD, waiting")
|
|
|
+ except Exception as exc:
|
|
|
+ print("exc", exc, file=sys.stderr)
|
|
|
+ logging.debug(
|
|
|
+ "Could not connect to MPD at (%s,%s), waiting",
|
|
|
+ get_conf()["MPD_HOST"],
|
|
|
+ get_conf()["MPD_PORT"],
|
|
|
+ )
|
|
|
sd_notify(status="Waiting MPD connection")
|
|
|
sleep(int(get_conf()["MPD_WAIT_START_RETRYSECS"]))
|
|
|
else:
|