From ace9c625908b459d87f94f02e96ef9bc7a28e352 Mon Sep 17 00:00:00 2001 From: shinedday <shinedday@gmail.com> Date: Mon, 9 May 2022 16:58:36 +0200 Subject: [PATCH] Fix intent and typo --- ihm.py | 20 ++++++++------------ tool/confi_reader.py | 3 +-- tool/mqtt_client.py | 5 ++++- tool/schedulable.py | 5 ++--- tool/ssh_client.py | 8 +++----- tool/update.py | 8 ++++---- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/ihm.py b/ihm.py index 1331b0d..ba0a1c7 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 da0b904..66ae9e9 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 0384587..b5901b9 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 5ff162b..dac1734 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 29f45cf..1fed649 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 03b7fde..f261e89 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: -- GitLab