aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2023-02-07 03:32:53 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2023-02-07 03:32:53 +0100
commit271a46d36d13dafe6224f93d8cfbf13c7ae96a4d (patch)
tree7ae613655e9e56a1bc324a232c6043c8feb79ce4
parentf78acaa4abbdcf1bad3c72576ad38ea9bb98ce2f (diff)
downloadautomato-271a46d36d13dafe6224f93d8cfbf13c7ae96a4d.tar.gz
documentation
-rw-r--r--automato/command.py16
-rwxr-xr-xautomato/command_line.py20
-rw-r--r--automato/transport.py35
3 files changed, 44 insertions, 27 deletions
diff --git a/automato/command.py b/automato/command.py
index a9ba694..49956a0 100644
--- a/automato/command.py
+++ b/automato/command.py
@@ -1,8 +1,20 @@
from . import transport
+'''
+Implementations of Command:
+
+MUST implement:
+ execute(self, **kwargs)
+
+CAN implement:
+ __init__(self, transport)
+
+SHOULDNT implement:
+ ./.
+'''
class Command:
def __init__(self, transport: transport.Transport):
- raise NotImplemented
+ self._transport = transport
def execute(self, **kwargs):
raise NotImplemented
@@ -11,5 +23,5 @@ class NotifyCommand(Command):
def __init__(self, transport: transport.SshTransport):
self._transport = transport
- def execute(self, msg: str, **kwargs):
+ def execute(self, msg: str):
self._transport.execHandleStderror(f'notify-send "{msg}"')
diff --git a/automato/command_line.py b/automato/command_line.py
index 0e18c4b..ef09078 100755
--- a/automato/command_line.py
+++ b/automato/command_line.py
@@ -49,23 +49,3 @@ def main():
for act_key in action_config:
actions[act_key].execute()
-
-
-#print(endpoints['host1'].getState('user.jonas'))
-#print(endpoints['host1'].getState('user.jonas'))
-#
-#time.sleep(31)
-#print(endpoints['host1'].getState('user.jonas'))
-
-#endpoints['host1'].executeCommand('notify', msg='moinsen')
-
-#tr = transport.SshTransport('localhost', username='jonas')
-#tr.connect()
-#
-#noti = command.NotifyCommand(tr)
-#noti.execute('OwO')
-#
-#sta = state.UserState(tr)
-#sta.collect()
-#
-#tr.disconnect()
diff --git a/automato/transport.py b/automato/transport.py
index 91c5029..ffee1d6 100644
--- a/automato/transport.py
+++ b/automato/transport.py
@@ -3,15 +3,41 @@ import paramiko
HOLD = 1
THROWAWAY = 2
-# Abstract classes to implement
+'''
+Implementations of Transport:
+
+CAN set:
+ CONNECTION
+ - THROWAWAY signals that every invocation creates a new connection and
+ and thus connection management is not needed
+ - HOLD indicates a connection is established and held for multiple commands,
+ requiring initial connection and final disconnection
+
+MUST implement:
+ connect(self), disconnect(self)
+ when CONNECTION is set to HOLD
+ make sure to set self._connected accordingly.
+ check(self)
+ when CONNECTION is set to THROWAWAY
+
+ Functions to use the Transport
+ it is advisable to specify the used Transport as a type hint in
+ the command/state using it to trigger errors on startup,
+ rather than at runtime in case of misconfiguration.
+
+CAN implement:
+ __init__(self, <other settings you might need>)
+ isConnected(self) -> bool
+
+SHOULDNT implement:
+ ./.
+'''
class Transport:
- NAME = 'BASE'
CONNECTION = HOLD
#CONNECTION = THROWAWAY
def __init__(self):
self._connected = False
- raise NotImplemented
# Connects to the transport, if CONNECTION == HOLD
def connect(self):
@@ -29,17 +55,16 @@ class Transport:
return self._connected
class SshTransport(Transport):
- NAME='SSH'
CONNECTION=HOLD
def __init__(self, hostname: str, port=22, username='root', password = None, id_file = None):
+ super().__init__()
self._hostname = hostname
self._port = port
self._username = username
self._password = password
self._id_file = id_file
- self._connected = False
self._client = None
def connect(self):