feat(instances): done -L active since

v3
Romain J 2 years ago
parent cc5df29e71
commit 179c84b45a
  1. 2
      tuxbot/__run__.py
  2. 27
      tuxbot/core/bot.py
  3. 11
      tuxbot/core/config.py
  4. 22
      tuxbot/setup.py

@ -47,7 +47,7 @@ def list_instances() -> NoReturn:
console.print()
columns = Columns(expand=True, padding=2, align="center")
for instance, details in app_config.instances.items():
for instance, details in app_config.Instances.items():
active = details["active"]
last_run = (
humanize.naturaltime(

@ -15,8 +15,14 @@ from rich.traceback import install
from tuxbot import version_info
from .config import Config, ConfigFile, search_for
from .data_manager import logs_data_path, data_path
from .config import (
Config,
ConfigFile,
search_for,
AppConfig,
set_for_key,
)
from .data_manager import logs_data_path, data_path, config_dir
from . import __version__, ExitCodes
from . import exceptions
@ -105,6 +111,15 @@ class Tux(commands.AutoShardedBot):
async def on_ready(self):
self.uptime = datetime.datetime.now()
app_config = ConfigFile(config_dir / "config.yaml", AppConfig).config
set_for_key(
app_config.Instances,
self.instance_name,
AppConfig.Instance,
active=True,
last_run=datetime.datetime.timestamp(self.uptime),
)
self._progress.get("main").stop_task(
self._progress.get("tasks")["connecting"]
)
@ -234,6 +249,14 @@ class Tux(commands.AutoShardedBot):
Todo: add postgresql logout here
"""
app_config = ConfigFile(config_dir / "config.yaml", AppConfig).config
set_for_key(
app_config.Instances,
self.instance_name,
AppConfig.Instance,
active=False,
)
for task in self._progress.get("tasks").keys():
self._progress.get("main").log("Shutting down", task)

@ -9,7 +9,14 @@ from structured_config import (
)
__all__ = ["Config", "ConfigFile", "search_for", "set_for_key", "set_for_key"]
__all__ = [
"Config",
"ConfigFile",
"AppConfig",
"search_for",
"set_for_key",
"set_for",
]
log = logging.getLogger("tuxbot.core.config")
@ -59,7 +66,7 @@ class AppConfig(Structure):
active: bool = BoolField(False)
last_run: int = IntField(0)
instances: Dict[str, Instance] = {}
Instances: Dict[str, Instance] = {}
# =============================================================================

@ -13,7 +13,7 @@ from rich.rule import Rule
from rich.style import Style
from rich.traceback import install
from tuxbot.core.config import set_for
from tuxbot.core.config import set_for, set_for_key
from tuxbot.logging import formatter
from tuxbot.core.data_manager import config_dir, app_dir, cogs_data_path
from tuxbot.core import config
@ -29,12 +29,14 @@ except PermissionError:
)
sys.exit(1)
app_config = config.ConfigFile(config_dir / "config.yaml", config.AppConfig)
app_config = config.ConfigFile(
config_dir / "config.yaml", config.AppConfig
).config
if not app_config.config.instances:
if not app_config.Instances:
instances_list = []
else:
instances_list = list(app_config.config.instances.keys())
instances_list = list(app_config.Instances.keys())
def get_name() -> str:
@ -339,11 +341,13 @@ def basic_setup() -> NoReturn:
console.print("Abandon...")
sys.exit(0)
instance = config.AppConfig.Instance()
instance.path = str(data_dir.resolve())
instance.active = False
app_config.config.instances[name] = instance
set_for_key(
app_config.Instances,
name,
config.AppConfig.Instance,
path=str(data_dir.resolve()),
active=False,
)
console.print("\n" * 4)

Loading…
Cancel
Save