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
|
||||
from argparse import Action, ArgumentParser
|
||||
from datetime import datetime
|
||||
import urllib.request
|
||||
|
||||
from . import forge, maint, server
|
||||
from .config_manager import get_config
|
||||
|
@ -12,18 +13,27 @@ logging.basicConfig(stream=sys.stdout)
|
|||
logger = logging.getLogger("cli")
|
||||
|
||||
CWD = os.getcwd()
|
||||
OK_CODES = [200, 301, 302]
|
||||
|
||||
|
||||
def is_writable(d):
|
||||
return os.access(d, os.W_OK)
|
||||
|
||||
|
||||
def pre_check_permissions():
|
||||
def is_writable(d):
|
||||
return os.access(d, os.W_OK)
|
||||
|
||||
if is_writable(get_config()["AUDIO_INPUT"]):
|
||||
yield "Audio input '%s' writable" % get_config()["AUDIO_INPUT"]
|
||||
if not os.access(get_config()["AUDIO_INPUT"], os.R_OK):
|
||||
yield "Audio input '%s' unreadable" % get_config()["AUDIO_INPUT"]
|
||||
audio_input = get_config()["AUDIO_INPUT"]
|
||||
if audio_input.startswith("http://") or audio_input.startswith("https://"):
|
||||
with urllib.request.urlopen(audio_input) as req:
|
||||
if req.code not in OK_CODES:
|
||||
yield f"Audio input {audio_input} not accessible"
|
||||
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"
|
||||
if not is_writable(get_config()["AUDIO_OUTPUT"]):
|
||||
yield "Audio output '%s' not writable" % get_config()["AUDIO_OUTPUT"]
|
||||
|
@ -72,7 +82,8 @@ def common_pre():
|
|||
continue
|
||||
path = os.path.realpath(conf)
|
||||
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
|
||||
configs.append(path)
|
||||
if getattr(sys, "frozen", False):
|
||||
|
|
Loading…
Reference in a new issue