aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2023-02-07 02:01:19 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2023-02-07 02:01:19 +0100
commit1cf5842c3ec4479b8789bc0061048dd4747d7bae (patch)
treeff32fc1a19198dafa463d1578616744f6af99012
parentc2109e5561299b2a120d1a669d58f6147ca40fb1 (diff)
downloadautomato-1cf5842c3ec4479b8789bc0061048dd4747d7bae.tar.gz
python module
-rw-r--r--README.md1
-rw-r--r--automato/__init__.py10
-rw-r--r--automato/action.py (renamed from action.py)4
-rw-r--r--automato/command.py (renamed from command.py)2
-rwxr-xr-xautomato/command_line.py71
-rw-r--r--automato/endpoint.py (renamed from endpoint.py)3
-rw-r--r--automato/misc.py (renamed from misc.py)0
-rw-r--r--automato/state.py (renamed from state.py)2
-rw-r--r--automato/transport.py (renamed from transport.py)0
-rw-r--r--automato/trigger.py (renamed from trigger.py)4
-rw-r--r--endpoints.yml6
-rwxr-xr-xmain.py76
-rw-r--r--setup.py26
-rw-r--r--triggers.yml2
14 files changed, 120 insertions, 87 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..548d523
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# automato
diff --git a/automato/__init__.py b/automato/__init__.py
new file mode 100644
index 0000000..195e88e
--- /dev/null
+++ b/automato/__init__.py
@@ -0,0 +1,10 @@
+''
+
+#from . import transport
+#from . import state
+#from . import command
+#from . import endpoint
+#from . import trigger
+#from . import misc
+#from . import action
+
diff --git a/action.py b/automato/action.py
index 8bb9bf2..7bb50ea 100644
--- a/action.py
+++ b/automato/action.py
@@ -1,8 +1,8 @@
from typing import Dict
import logging
-import endpoint
-import trigger
+from . import endpoint
+from . import trigger
class Action:
# TODO: Cooldown, wait fot state change, repeat, etc?
diff --git a/command.py b/automato/command.py
index db0d261..a9ba694 100644
--- a/command.py
+++ b/automato/command.py
@@ -1,4 +1,4 @@
-import transport
+from . import transport
class Command:
def __init__(self, transport: transport.Transport):
diff --git a/automato/command_line.py b/automato/command_line.py
new file mode 100755
index 0000000..0e18c4b
--- /dev/null
+++ b/automato/command_line.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+
+import yaml
+import json
+import logging
+import time
+
+from automato import transport, state, command, endpoint, trigger, misc, action
+
+def main():
+ logging.basicConfig(level=logging.DEBUG)
+ logging.getLogger('paramiko').setLevel(logging.WARNING)
+
+ # Use a TypeDict here
+ with open('endpoints.yml', 'r') as f:
+ endpoint_config = yaml.safe_load(f)
+
+ with open('triggers.yml', 'r') as f:
+ trigger_config = yaml.safe_load(f)
+
+ with open('actions.yml', 'r') as f:
+ action_config = yaml.safe_load(f)
+
+ endpoints = {}
+ for ep_key in endpoint_config:
+ endpoints[ep_key] = endpoint.Endpoint(ep_key, endpoint_config[ep_key])
+
+ triggers = {}
+ for trg_key in trigger_config:
+ cls = misc.import_class(trigger_config[trg_key]['class'])
+ del trigger_config[trg_key]['class']
+
+ if cls.NEEDS_CONTEXT:
+ triggers[trg_key] = cls(endpoints, **trigger_config[trg_key])
+ else:
+ triggers[trg_key] = cls(**trigger_config[trg_key])
+
+ actions = {}
+ for act_key in action_config:
+ actions[act_key] = action.Action(act_key, action_config[act_key], endpoints, triggers)
+
+
+ # TODO should we do that in Endpoint.__init__()?
+ for k in endpoints:
+ endpoints[k].connectTransport()
+
+ for act_key in action_config:
+ actions[act_key].execute()
+
+ 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/endpoint.py b/automato/endpoint.py
index 7458326..411b2e8 100644
--- a/endpoint.py
+++ b/automato/endpoint.py
@@ -1,5 +1,6 @@
import logging
-import transport
+
+from . import transport
def import_class(cl):
d = cl.rfind(".")
diff --git a/misc.py b/automato/misc.py
index 99fad74..99fad74 100644
--- a/misc.py
+++ b/automato/misc.py
diff --git a/state.py b/automato/state.py
index b17db99..d891aa5 100644
--- a/state.py
+++ b/automato/state.py
@@ -1,7 +1,7 @@
import time
import logging
-import transport
+from . import transport
'''
Implementations of State:
diff --git a/transport.py b/automato/transport.py
index 91c5029..91c5029 100644
--- a/transport.py
+++ b/automato/transport.py
diff --git a/trigger.py b/automato/trigger.py
index 7d2fdfd..5608f17 100644
--- a/trigger.py
+++ b/automato/trigger.py
@@ -3,8 +3,8 @@ from pyparsing import alphanums, alphas, printables, pyparsing_common, pyparsing
import logging
import time
-import endpoint
-import misc
+from . import endpoint
+from . import misc
'''
Implementations of Trigger:
diff --git a/endpoints.yml b/endpoints.yml
index fad2160..c4d35bc 100644
--- a/endpoints.yml
+++ b/endpoints.yml
@@ -1,15 +1,15 @@
host1:
transports:
ssh:
- class: transport.SshTransport
+ class: automato.transport.SshTransport
hostname: 'localhost'
username: 'jonas'
commands:
notify:
- class: command.NotifyCommand
+ class: automato.command.NotifyCommand
transport: ssh
states:
user:
- class: state.UserSessionState
+ class: automato.state.UserSessionState
transport: ssh
ttl: 30
diff --git a/main.py b/main.py
deleted file mode 100755
index b2ffe42..0000000
--- a/main.py
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env python3
-
-import yaml
-import json
-import logging
-import time
-
-import transport
-import state
-import command
-import endpoint
-import trigger
-import misc
-import action
-
-logging.basicConfig(level=logging.DEBUG)
-logging.getLogger('paramiko').setLevel(logging.WARNING)
-
-# Use a TypeDict here
-with open('endpoints.yml', 'r') as f:
- endpoint_config = yaml.safe_load(f)
-
-with open('triggers.yml', 'r') as f:
- trigger_config = yaml.safe_load(f)
-
-with open('actions.yml', 'r') as f:
- action_config = yaml.safe_load(f)
-
-endpoints = {}
-for ep_key in endpoint_config:
- endpoints[ep_key] = endpoint.Endpoint(ep_key, endpoint_config[ep_key])
-
-triggers = {}
-for trg_key in trigger_config:
- cls = misc.import_class(trigger_config[trg_key]['class'])
- del trigger_config[trg_key]['class']
-
- if cls.NEEDS_CONTEXT:
- triggers[trg_key] = cls(endpoints, **trigger_config[trg_key])
- else:
- triggers[trg_key] = cls(**trigger_config[trg_key])
-
-actions = {}
-for act_key in action_config:
- actions[act_key] = action.Action(act_key, action_config[act_key], endpoints, triggers)
-
-
-# TODO should we do that in Endpoint.__init__()?
-for k in endpoints:
- endpoints[k].connectTransport()
-
-for act_key in action_config:
- actions[act_key].execute()
-
-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/setup.py b/setup.py
new file mode 100644
index 0000000..2607263
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,26 @@
+from setuptools import setup, find_packages
+
+setup(
+ name='automato',
+ author="Jonas Gunz",
+ author_mail="himself@jonasgunz.de",
+ description="automato",
+ version='0.0.0',
+ packages=find_packages(),
+ entry_points = {
+ 'console_scripts': ['automato=automato.command_line:main'],
+ },
+ # TODO Check them
+ install_requires=[
+ "paramiko",
+ "pyparsing",
+ "PyYAML",
+ ],
+ long_description=open('README.md').read(),
+ long_description_content_type="text/markdown",
+ classifiers=[
+ "Programming Language :: Python :: 3",
+ "License :: OSI Approved :: MIT License",
+ "Operating System :: OS Independent",
+ ],
+)
diff --git a/triggers.yml b/triggers.yml
index 9595f7e..b1b38c7 100644
--- a/triggers.yml
+++ b/triggers.yml
@@ -1,5 +1,5 @@
conditional:
- class: trigger.ConditionalTrigger
+ class: automato.trigger.ConditionalTrigger
#mqtt:
# class: trigger.Mqtt