1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Further separate the modules from each other

This commit is contained in:
Steffo 2020-05-06 19:48:59 +02:00
parent 0f7f623ff8
commit 355514cb6a
2 changed files with 49 additions and 26 deletions

View file

@ -2,12 +2,32 @@ import click
import multiprocessing import multiprocessing
import toml import toml
import logging import logging
import royalnet.constellation as rc
import royalnet.serf.telegram as rst
import royalnet.serf.discord as rsd
import royalnet.serf.matrix as rsm
import royalnet.utils as ru import royalnet.utils as ru
import royalnet.herald as rh
try:
import royalnet.serf.telegram as rst
except ImportError:
rst = None
try:
import royalnet.serf.discord as rsd
except ImportError:
rsd = None
try:
import royalnet.serf.matrix as rsm
except ImportError:
rsm = None
try:
import royalnet.constellation as rc
except ImportError:
rc = None
try:
import royalnet.herald as rh
except ImportError:
rh = None
try: try:
import coloredlogs import coloredlogs
@ -39,7 +59,8 @@ def run(config_filename: str):
# Herald Server # Herald Server
herald_cfg = None herald_cfg = None
herald_process = None herald_process = None
if config["Herald"]["Local"]["enabled"]: if rh is not None and "Herald" in config:
if "Local" in config["Herald"] and config["Herald"]["Local"]["enabled"]:
# Create a Herald server # Create a Herald server
herald_server = rh.Server(rh.Config.from_config(name="<server>", **config["Herald"]["Local"])) herald_server = rh.Server(rh.Config.from_config(name="<server>", **config["Herald"]["Local"]))
# Run the Herald server on a new process # Run the Herald server on a new process
@ -52,15 +73,17 @@ def run(config_filename: str):
herald_process.start() herald_process.start()
herald_cfg = config["Herald"]["Local"] herald_cfg = config["Herald"]["Local"]
log.info("Herald: Enabled (Local)") log.info("Herald: Enabled (Local)")
elif config["Herald"]["Remote"]["enabled"]: elif "Remote" in config["Herald"] and config["Herald"]["Remote"]["enabled"]:
log.info("Herald: Enabled (Remote)") log.info("Herald: Enabled (Remote)")
herald_cfg = config["Herald"]["Remote"] herald_cfg = config["Herald"]["Remote"]
else: else:
log.info("Herald: Disabled") log.info("Herald: Disabled")
else:
log.info("Herald: Disabled")
# Serfs # Serfs
telegram_process = None telegram_process = None
if "Telegram" in config["Serfs"] and config["Serfs"]["Telegram"]["enabled"]: if rst is not None and "Telegram" in config["Serfs"] and config["Serfs"]["Telegram"]["enabled"]:
telegram_process = multiprocessing.Process(name="Serf.Telegram", telegram_process = multiprocessing.Process(name="Serf.Telegram",
target=rst.TelegramSerf.run_process, target=rst.TelegramSerf.run_process,
daemon=True, daemon=True,
@ -78,7 +101,7 @@ def run(config_filename: str):
log.info("Serf.Telegram: Disabled") log.info("Serf.Telegram: Disabled")
discord_process = None discord_process = None
if "Discord" in config["Serfs"] and config["Serfs"]["Discord"]["enabled"]: if rsd is not None and "Discord" in config["Serfs"] and config["Serfs"]["Discord"]["enabled"]:
discord_process = multiprocessing.Process(name="Serf.Discord", discord_process = multiprocessing.Process(name="Serf.Discord",
target=rsd.DiscordSerf.run_process, target=rsd.DiscordSerf.run_process,
daemon=True, daemon=True,
@ -96,7 +119,7 @@ def run(config_filename: str):
log.info("Serf.Discord: Disabled") log.info("Serf.Discord: Disabled")
matrix_process = None matrix_process = None
if "Matrix" in config["Serfs"] and config["Serfs"]["Matrix"]["enabled"]: if rsm is not None and "Matrix" in config["Serfs"] and config["Serfs"]["Matrix"]["enabled"]:
matrix_process = multiprocessing.Process(name="Serf.Matrix", matrix_process = multiprocessing.Process(name="Serf.Matrix",
target=rsm.MatrixSerf.run_process, target=rsm.MatrixSerf.run_process,
daemon=True, daemon=True,
@ -115,7 +138,7 @@ def run(config_filename: str):
# Constellation # Constellation
constellation_process = None constellation_process = None
if config["Constellation"]["enabled"]: if rc is not None and "Constellation" in config and config["Constellation"]["enabled"]:
constellation_process = multiprocessing.Process(name="Constellation", constellation_process = multiprocessing.Process(name="Constellation",
target=rc.Constellation.run_process, target=rc.Constellation.run_process,
daemon=True, daemon=True,

View file

@ -56,7 +56,7 @@ class Constellation:
"""The :class:`~ra.Alchemy` of this Constellation.""" """The :class:`~ra.Alchemy` of this Constellation."""
# Alchemy # Alchemy
if ra.Alchemy is None: if ra.Alchemy is None or alchemy_cfg is None:
log.info("Alchemy: not installed") log.info("Alchemy: not installed")
elif not alchemy_cfg["enabled"]: elif not alchemy_cfg["enabled"]:
log.info("Alchemy: disabled") log.info("Alchemy: disabled")