mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 18:01:33 +00:00
Extract magic dict building to method in TerminalCommands
This commit is contained in:
parent
5d8d541394
commit
7877e977ab
@ -9,11 +9,14 @@ LOG = logging.getLogger(__name__)
|
|||||||
class TerminalCommands(ABC):
|
class TerminalCommands(ABC):
|
||||||
def __init__(self, bashrc=None):
|
def __init__(self, bashrc=None):
|
||||||
self._command_method_regex = r'^command_(.+)$'
|
self._command_method_regex = r'^command_(.+)$'
|
||||||
self.command_implemetations = {self._parse_command_name(fun): getattr(self, fun) for fun in dir(self)
|
self.command_implemetations = self._build_command_to_implementation_dict()
|
||||||
if callable(getattr(self, fun)) and self._is_command_implementation(fun)}
|
|
||||||
if bashrc is not None:
|
if bashrc is not None:
|
||||||
self._setup_bashrc_aliases(bashrc)
|
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):
|
def _setup_bashrc_aliases(self, bashrc):
|
||||||
with open(bashrc, 'a') as ofile:
|
with open(bashrc, 'a') as ofile:
|
||||||
alias_template = 'alias {0}="{0} > /dev/null 2>&1"\n'
|
alias_template = 'alias {0}="{0} > /dev/null 2>&1"\n'
|
||||||
|
Loading…
Reference in New Issue
Block a user