diff --git a/ihm.py b/ihm.py index 1331b0d01be4087059507507d8e9e36ea7220c78..ba0a1c70bf993f0e2aa17b33eb9e9c96bc91ab30 100644 --- a/ihm.py +++ b/ihm.py @@ -1,18 +1,17 @@ +import pathlib +import platform # For getting the operating system name +import subprocess # For executing a shell command import sys -from subprocess import Popen from os import path +from subprocess import Popen from time import sleep -import platform # For getting the operating system name -import subprocess # For executing a shell command - -import pathlib - from tool.confi_reader import read_ssh from tool.mqtt_client import MqttClient from tool.ssh_client import SSHClient, Cmd from tool.update import VersionManager + class Ihm(MqttClient, SSHClient): def __init__(self): @@ -111,9 +110,9 @@ class Ihm(MqttClient, SSHClient): p1 = Popen([sys.executable, 'scheduler.py', cmd]) sleep(1) # start subprocess amas - p2 = Popen([sys.executable, experiment_folder+'/amas.py']) + p2 = Popen([sys.executable, experiment_folder + '/amas.py']) # start subprocess env - p3 = Popen([sys.executable, experiment_folder+'/env.py']) + p3 = Popen([sys.executable, experiment_folder + '/env.py']) if cmd.lower() == "pause": self.client.publish("ihm/pause") @@ -126,8 +125,7 @@ class Ihm(MqttClient, SSHClient): if cmd.lower() == "ping": - for client in read_ssh(str(pathlib.Path(__file__).parent.resolve())+"/tool/config.json") : - + for client in read_ssh(str(pathlib.Path(__file__).parent.resolve()) + "/tool/config.json"): param = '-n' if platform.system().lower() == 'windows' else '-c' command = ['ping', param, '1', client.hostname] @@ -138,12 +136,10 @@ class Ihm(MqttClient, SSHClient): if cmd.lower() == "mode": self.client.publish("ihm/mode") - self.client.publish("ihm/step") sleep(2) - if __name__ == '__main__': a = Ihm() a.run() diff --git a/tool/confi_reader.py b/tool/confi_reader.py index da0b9046f354f6536799c3827bb5d15072bd9a8c..66ae9e92f7234850d8292637f0d64b456ecd5e7f 100644 --- a/tool/confi_reader.py +++ b/tool/confi_reader.py @@ -1,7 +1,6 @@ import json - -import sys import pathlib +import sys sys.path.insert(0, str(pathlib.Path(__file__).parent.parent)) from tool.remote_client import RemoteClient diff --git a/tool/mqtt_client.py b/tool/mqtt_client.py index 0384587d96240ee1d895eae9361fde7353452249..b5901b904f2f1a89b99fdb8b07f2af400465edaf 100644 --- a/tool/mqtt_client.py +++ b/tool/mqtt_client.py @@ -1,5 +1,5 @@ -import sys import pathlib +import sys sys.path.insert(0, str(pathlib.Path(__file__).parent.parent)) @@ -19,3 +19,6 @@ class MqttClient: def subscribe(self, topic, fun): self.client.subscribe(topic) self.client.message_callback_add(topic, fun) + + def publish(self, topic, message): + self.client.publish(topic, message) diff --git a/tool/schedulable.py b/tool/schedulable.py index 5ff162b1a1111f3dbe4b6a51d64408e344fd3b4e..dac17347fac079e32dfd0dc5bb3ef19b97a55151 100644 --- a/tool/schedulable.py +++ b/tool/schedulable.py @@ -1,10 +1,9 @@ """ Tool class that implement basic interaction that help to finish processes """ -from time import sleep - -import sys import pathlib +import sys +from time import sleep sys.path.insert(0, str(pathlib.Path(__file__).parent.parent)) diff --git a/tool/ssh_client.py b/tool/ssh_client.py index 29f45cfe365add3c77928c088e33bdd8fb0d4cf7..1fed649833766fb6b8677e61b7c6545209fac0d4 100644 --- a/tool/ssh_client.py +++ b/tool/ssh_client.py @@ -1,10 +1,8 @@ -import os +import pathlib +import sys from pexpect import pxssh -import sys -import pathlib - sys.path.insert(0, str(pathlib.Path(__file__).parent.parent)) from tool.confi_reader import read_ssh @@ -20,7 +18,7 @@ class Cmd: class SSHClient: def __init__(self): - self.clients = read_ssh(str(pathlib.Path(__file__).parent.resolve())+"/config.json") + self.clients = read_ssh(str(pathlib.Path(__file__).parent.resolve()) + "/config.json") def run_cmd(self, client: int, cmd: list): try: diff --git a/tool/update.py b/tool/update.py index 03b7fde21659827dc95ad2b2b9a7eefa3ef2b680..f261e89d57da13234d307cdabad6a6c1401c25ee 100644 --- a/tool/update.py +++ b/tool/update.py @@ -1,8 +1,8 @@ -import paramiko import os - -import sys import pathlib +import sys + +import paramiko sys.path.insert(0, str(pathlib.Path(__file__).parent.parent)) from tool.confi_reader import read_ssh @@ -11,7 +11,7 @@ from tool.confi_reader import read_ssh class VersionManager: def __init__(self): - self.clients = read_ssh(str(pathlib.Path(__file__).parent.resolve())+"/config.json") + self.clients = read_ssh(str(pathlib.Path(__file__).parent.resolve()) + "/config.json") def update(self): for client in self.clients: