From f1803f2ffd5507827be1a430d2b09996decfc098 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 29 Nov 2019 15:55:52 +0100 Subject: [PATCH] More commands done --- royalnet/backpack/events/exception.py | 2 +- royalnet/commands/command.py | 10 ++++++++++ royalnet/commands/commandinterface.py | 4 ++-- royalnet/constellation/constellation.py | 2 +- royalnet/serf/serf.py | 4 ++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/royalnet/backpack/events/exception.py b/royalnet/backpack/events/exception.py index b9cedc52..eb03b62a 100644 --- a/royalnet/backpack/events/exception.py +++ b/royalnet/backpack/events/exception.py @@ -5,6 +5,6 @@ class ExceptionEvent(Event): name = "exception" def run(self, **kwargs): - if not self.interface.cfg["exc_debug"]: + if not self.interface.config["exc_debug"]: raise UserError(f"{self.interface.prefix}{self.name} is not enabled.") raise Exception(f"{self.name} event was called") diff --git a/royalnet/commands/command.py b/royalnet/commands/command.py index 67d4098e..aaf7065e 100644 --- a/royalnet/commands/command.py +++ b/royalnet/commands/command.py @@ -27,6 +27,11 @@ class Command: def __init__(self, interface: CommandInterface): self.interface = interface + @property + def serf(self): + """A shortcut for :attr:`.interface.serf`.""" + return self.interface.serf + @property def alchemy(self): """A shortcut for :attr:`.interface.alchemy`.""" @@ -37,5 +42,10 @@ class Command: """A shortcut for :attr:`.interface.loop`.""" return self.interface.loop + @property + def config(self): + """A shortcut for :attr:`.interface.config`.""" + return self.interface.config + async def run(self, args: CommandArgs, data: CommandData) -> None: raise NotImplementedError() diff --git a/royalnet/commands/commandinterface.py b/royalnet/commands/commandinterface.py index 65b22e5e..dc8c5af7 100644 --- a/royalnet/commands/commandinterface.py +++ b/royalnet/commands/commandinterface.py @@ -48,8 +48,8 @@ class CommandInterface: # TODO raise Exception("TODO") - def __init__(self, cfg: Dict[str, Any]): - self.cfg: Dict[str, Any] = cfg + def __init__(self, config: Dict[str, Any]): + self.config: Dict[str, Any] = config """The config section for the pack of the command.""" # Will be bound after the command/event has been created diff --git a/royalnet/constellation/constellation.py b/royalnet/constellation/constellation.py index 809939dc..bb0c4de2 100644 --- a/royalnet/constellation/constellation.py +++ b/royalnet/constellation/constellation.py @@ -225,7 +225,7 @@ class Constellation: def register_events(self, events: List[Type[rc.Event]], pack_cfg: Dict[str, Any]): for SelectedEvent in events: # Create a new interface - interface = self.Interface(cfg=pack_cfg) + interface = self.Interface(config=pack_cfg) # Initialize the event try: event = SelectedEvent(interface) diff --git a/royalnet/serf/serf.py b/royalnet/serf/serf.py index bfb0f0ef..c5655512 100644 --- a/royalnet/serf/serf.py +++ b/royalnet/serf/serf.py @@ -203,7 +203,7 @@ class Serf: # Instantiate the Commands for SelectedCommand in commands: # Create a new interface - interface = self.Interface(cfg=pack_cfg) + interface = self.Interface(config=pack_cfg) # Try to instantiate the command try: command = SelectedCommand(interface) @@ -241,7 +241,7 @@ class Serf: def register_events(self, events: List[Type[Event]], pack_cfg: Dict[str, Any]): for SelectedEvent in events: # Create a new interface - interface = self.Interface(cfg=pack_cfg) + interface = self.Interface(config=pack_cfg) # Initialize the event try: event = SelectedEvent(interface)