From 7877e977abfab9944038819e4ca5bb6b9ff6bda4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 13 Apr 2018 10:01:45 +0200 Subject: [PATCH] Extract magic dict building to method in TerminalCommands --- lib/tfw/components/terminal_commands.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tfw/components/terminal_commands.py b/lib/tfw/components/terminal_commands.py index b07f652..8b252f3 100644 --- a/lib/tfw/components/terminal_commands.py +++ b/lib/tfw/components/terminal_commands.py @@ -9,11 +9,14 @@ LOG = logging.getLogger(__name__) class TerminalCommands(ABC): def __init__(self, bashrc=None): self._command_method_regex = r'^command_(.+)$' - self.command_implemetations = {self._parse_command_name(fun): getattr(self, fun) for fun in dir(self) - if callable(getattr(self, fun)) and self._is_command_implementation(fun)} + self.command_implemetations = self._build_command_to_implementation_dict() if bashrc is not None: self._setup_bashrc_aliases(bashrc) + def _build_command_to_implementation_dict(self): + return {self._parse_command_name(fun): getattr(self, fun) for fun in dir(self) + if callable(getattr(self, fun)) and self._is_command_implementation(fun)} + def _setup_bashrc_aliases(self, bashrc): with open(bashrc, 'a') as ofile: alias_template = 'alias {0}="{0} > /dev/null 2>&1"\n'