Fix startup checks
This commit is contained in:
parent
acc966b488
commit
26181d083f
1 changed files with 21 additions and 10 deletions
|
@ -4,6 +4,7 @@ import os.path
|
||||||
import sys
|
import sys
|
||||||
from argparse import Action, ArgumentParser
|
from argparse import Action, ArgumentParser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
from . import forge, maint, server
|
from . import forge, maint, server
|
||||||
from .config_manager import get_config
|
from .config_manager import get_config
|
||||||
|
@ -12,18 +13,27 @@ logging.basicConfig(stream=sys.stdout)
|
||||||
logger = logging.getLogger("cli")
|
logger = logging.getLogger("cli")
|
||||||
|
|
||||||
CWD = os.getcwd()
|
CWD = os.getcwd()
|
||||||
|
OK_CODES = [200, 301, 302]
|
||||||
|
|
||||||
|
|
||||||
|
def is_writable(d):
|
||||||
|
return os.access(d, os.W_OK)
|
||||||
|
|
||||||
|
|
||||||
def pre_check_permissions():
|
def pre_check_permissions():
|
||||||
def is_writable(d):
|
audio_input = get_config()["AUDIO_INPUT"]
|
||||||
return os.access(d, os.W_OK)
|
if audio_input.startswith("http://") or audio_input.startswith("https://"):
|
||||||
|
with urllib.request.urlopen(audio_input) as req:
|
||||||
if is_writable(get_config()["AUDIO_INPUT"]):
|
if req.code not in OK_CODES:
|
||||||
yield "Audio input '%s' writable" % get_config()["AUDIO_INPUT"]
|
yield f"Audio input {audio_input} not accessible"
|
||||||
if not os.access(get_config()["AUDIO_INPUT"], os.R_OK):
|
|
||||||
yield "Audio input '%s' unreadable" % get_config()["AUDIO_INPUT"]
|
|
||||||
sys.exit(10)
|
sys.exit(10)
|
||||||
if is_writable(os.getcwd()):
|
else:
|
||||||
|
if is_writable(audio_input):
|
||||||
|
yield "Audio input '%s' writable" % audio_input
|
||||||
|
if not os.access(audio_input, os.R_OK):
|
||||||
|
yield "Audio input '%s' unreadable" % audio_input
|
||||||
|
sys.exit(10)
|
||||||
|
if is_writable(CWD):
|
||||||
yield "Code writable"
|
yield "Code writable"
|
||||||
if not is_writable(get_config()["AUDIO_OUTPUT"]):
|
if not is_writable(get_config()["AUDIO_OUTPUT"]):
|
||||||
yield "Audio output '%s' not writable" % get_config()["AUDIO_OUTPUT"]
|
yield "Audio output '%s' not writable" % get_config()["AUDIO_OUTPUT"]
|
||||||
|
@ -72,7 +82,8 @@ def common_pre():
|
||||||
continue
|
continue
|
||||||
path = os.path.realpath(conf)
|
path = os.path.realpath(conf)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
logger.warn("Configuration file '%s' does not exist; skipping" % path)
|
logger.warn(
|
||||||
|
"Configuration file '%s' does not exist; skipping" % path)
|
||||||
continue
|
continue
|
||||||
configs.append(path)
|
configs.append(path)
|
||||||
if getattr(sys, "frozen", False):
|
if getattr(sys, "frozen", False):
|
||||||
|
|
Loading…
Reference in a new issue