feat(instances): done -L active since
This commit is contained in:
parent
cc5df29e71
commit
179c84b45a
4 changed files with 48 additions and 14 deletions
|
@ -47,7 +47,7 @@ def list_instances() -> NoReturn:
|
||||||
console.print()
|
console.print()
|
||||||
|
|
||||||
columns = Columns(expand=True, padding=2, align="center")
|
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"]
|
active = details["active"]
|
||||||
last_run = (
|
last_run = (
|
||||||
humanize.naturaltime(
|
humanize.naturaltime(
|
||||||
|
|
|
@ -15,8 +15,14 @@ from rich.traceback import install
|
||||||
|
|
||||||
from tuxbot import version_info
|
from tuxbot import version_info
|
||||||
|
|
||||||
from .config import Config, ConfigFile, search_for
|
from .config import (
|
||||||
from .data_manager import logs_data_path, data_path
|
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 __version__, ExitCodes
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
|
@ -105,6 +111,15 @@ class Tux(commands.AutoShardedBot):
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
self.uptime = datetime.datetime.now()
|
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("main").stop_task(
|
||||||
self._progress.get("tasks")["connecting"]
|
self._progress.get("tasks")["connecting"]
|
||||||
)
|
)
|
||||||
|
@ -234,6 +249,14 @@ class Tux(commands.AutoShardedBot):
|
||||||
|
|
||||||
Todo: add postgresql logout here
|
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():
|
for task in self._progress.get("tasks").keys():
|
||||||
self._progress.get("main").log("Shutting down", task)
|
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")
|
log = logging.getLogger("tuxbot.core.config")
|
||||||
|
|
||||||
|
@ -59,7 +66,7 @@ class AppConfig(Structure):
|
||||||
active: bool = BoolField(False)
|
active: bool = BoolField(False)
|
||||||
last_run: int = IntField(0)
|
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.style import Style
|
||||||
from rich.traceback import install
|
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.logging import formatter
|
||||||
from tuxbot.core.data_manager import config_dir, app_dir, cogs_data_path
|
from tuxbot.core.data_manager import config_dir, app_dir, cogs_data_path
|
||||||
from tuxbot.core import config
|
from tuxbot.core import config
|
||||||
|
@ -29,12 +29,14 @@ except PermissionError:
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
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 = []
|
instances_list = []
|
||||||
else:
|
else:
|
||||||
instances_list = list(app_config.config.instances.keys())
|
instances_list = list(app_config.Instances.keys())
|
||||||
|
|
||||||
|
|
||||||
def get_name() -> str:
|
def get_name() -> str:
|
||||||
|
@ -339,11 +341,13 @@ def basic_setup() -> NoReturn:
|
||||||
console.print("Abandon...")
|
console.print("Abandon...")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
instance = config.AppConfig.Instance()
|
set_for_key(
|
||||||
instance.path = str(data_dir.resolve())
|
app_config.Instances,
|
||||||
instance.active = False
|
name,
|
||||||
|
config.AppConfig.Instance,
|
||||||
app_config.config.instances[name] = instance
|
path=str(data_dir.resolve()),
|
||||||
|
active=False,
|
||||||
|
)
|
||||||
|
|
||||||
console.print("\n" * 4)
|
console.print("\n" * 4)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue