From 8fadd6904590e0844bfc6b4dbeea0d1c5309eb2f Mon Sep 17 00:00:00 2001
From: shinedday <shinedday@gmail.com>
Date: Fri, 6 May 2022 16:12:49 +0200
Subject: [PATCH] Reformat framework

---
 agent.py                              |  2 +-
 amas.py                               |  5 ++---
 environment.py                        |  2 +-
 ihm.py                                |  6 +++---
 philosophers/amas.py                  |  4 ++--
 philosophers/env.py                   |  2 +-
 scheduler.py                          |  2 +-
 tool/__init__.py                      |  0
 tool/confi_reader.py                  | 24 ++++++++++++++++++++++++
 tool/config.json                      | 25 +++++++++++++++++++++++++
 mqtt_client.py => tool/mqtt_client.py |  0
 schedulable.py => tool/schedulable.py |  2 +-
 ssh_client.py => tool/ssh_client.py   |  0
 update.py => tool/update.py           |  2 +-
 14 files changed, 62 insertions(+), 14 deletions(-)
 create mode 100644 tool/__init__.py
 create mode 100644 tool/confi_reader.py
 create mode 100644 tool/config.json
 rename mqtt_client.py => tool/mqtt_client.py (100%)
 rename schedulable.py => tool/schedulable.py (95%)
 rename ssh_client.py => tool/ssh_client.py (100%)
 rename update.py => tool/update.py (97%)

diff --git a/agent.py b/agent.py
index 3d79a4a..9d13624 100644
--- a/agent.py
+++ b/agent.py
@@ -2,7 +2,7 @@ import sys
 from ast import literal_eval
 from typing import Dict
 
-from schedulable import Schedulable
+from tool.schedulable import Schedulable
 
 
 class Agent(Schedulable):
diff --git a/amas.py b/amas.py
index 35e947d..1ff3e9d 100644
--- a/amas.py
+++ b/amas.py
@@ -2,10 +2,9 @@
 Amas class
 """
 from ast import literal_eval
-from pexpect import pxssh
 
-from schedulable import Schedulable
-from ssh_client import SSHClient, Cmd
+from tool.schedulable import Schedulable
+from tool.ssh_client import SSHClient, Cmd
 
 
 class Amas(Schedulable, SSHClient):
diff --git a/environment.py b/environment.py
index 562a268..1d5b90c 100644
--- a/environment.py
+++ b/environment.py
@@ -2,7 +2,7 @@
 Environment class
 """
 
-from schedulable import Schedulable
+from tool.schedulable import Schedulable
 
 
 class Environment(Schedulable):
diff --git a/ihm.py b/ihm.py
index 9236072..83f601a 100644
--- a/ihm.py
+++ b/ihm.py
@@ -3,9 +3,9 @@ from subprocess import Popen
 from os import path
 from time import sleep
 
-from mqtt_client import MqttClient
-from ssh_client import SSHClient, Cmd, RemoteClient
-from update import VersionManager
+from tool.mqtt_client import MqttClient
+from tool.ssh_client import SSHClient, Cmd, RemoteClient
+from tool.update import VersionManager
 
 class Ihm(MqttClient, SSHClient):
 
diff --git a/philosophers/amas.py b/philosophers/amas.py
index e5bc0ed..2e2049a 100644
--- a/philosophers/amas.py
+++ b/philosophers/amas.py
@@ -4,7 +4,7 @@ import pathlib
 sys.path.insert(0, str(pathlib.Path(__file__).parent.parent))
 
 from amas import Amas
-from ssh_client import Cmd
+from tool.ssh_client import Cmd
 
 class PhiAmas(Amas):
 
@@ -33,5 +33,5 @@ class PhiAmas(Amas):
         # self.run_cmd(1, agents[2:])
 
 if __name__ == '__main__':
-    s = PhiAmas(3)
+    s = PhiAmas(100)
     s.run()
\ No newline at end of file
diff --git a/philosophers/env.py b/philosophers/env.py
index 179ba88..9f043ce 100644
--- a/philosophers/env.py
+++ b/philosophers/env.py
@@ -65,5 +65,5 @@ class PhiEnv(Environment):
 
 
 if __name__ == '__main__':
-    s = PhiEnv(3)
+    s = PhiEnv(100)
     s.run()
\ No newline at end of file
diff --git a/scheduler.py b/scheduler.py
index 652345f..5355e4f 100644
--- a/scheduler.py
+++ b/scheduler.py
@@ -1,7 +1,7 @@
 import sys
 from time import sleep
 
-from schedulable import Schedulable
+from tool.schedulable import Schedulable
 
 
 class Scheduler(Schedulable):
diff --git a/tool/__init__.py b/tool/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tool/confi_reader.py b/tool/confi_reader.py
new file mode 100644
index 0000000..cef7a36
--- /dev/null
+++ b/tool/confi_reader.py
@@ -0,0 +1,24 @@
+import json
+
+from tool.ssh_client import RemoteClient
+
+
+def read_ssh(path):
+
+    with open(path, 'r', encoding='utf-8') as f:
+        dict = json.load(f)
+
+    res = []
+    for client in dict.get("clients_ssh"):
+        res.append(RemoteClient(
+            hostname=client.get("hostname"),
+            user=client.get("user"),
+            password=client.get("password")
+        ))
+    return res
+
+def read_broker(path):
+    with open(path, 'r', encoding='utf-8') as f:
+        dict = json.load(f)
+
+    return dict.get("broker")
\ No newline at end of file
diff --git a/tool/config.json b/tool/config.json
new file mode 100644
index 0000000..274c074
--- /dev/null
+++ b/tool/config.json
@@ -0,0 +1,25 @@
+{
+  "broker" : "192.168.1.1",
+  "clients_ssh" : [
+    {
+      "hostname" : "192.168.1.1",
+      "user" : "pi",
+      "password" : "raspberry"
+    },
+    {
+      "hostname" : "192.168.1.1",
+      "user" : "pi",
+      "password" : "raspberry"
+    },
+    {
+      "hostname" : "192.168.1.1",
+      "user" : "pi",
+      "password" : "raspberry"
+    },
+    {
+      "hostname" : "192.168.1.1",
+      "user" : "pi",
+      "password" : "raspberry"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/mqtt_client.py b/tool/mqtt_client.py
similarity index 100%
rename from mqtt_client.py
rename to tool/mqtt_client.py
diff --git a/schedulable.py b/tool/schedulable.py
similarity index 95%
rename from schedulable.py
rename to tool/schedulable.py
index 16a2150..293f35f 100644
--- a/schedulable.py
+++ b/tool/schedulable.py
@@ -3,7 +3,7 @@ Tool class that implement basic interaction that help to finish processes
 """
 from time import sleep
 
-from mqtt_client import MqttClient
+from tool.mqtt_client import MqttClient
 
 
 class Schedulable(MqttClient):
diff --git a/ssh_client.py b/tool/ssh_client.py
similarity index 100%
rename from ssh_client.py
rename to tool/ssh_client.py
diff --git a/update.py b/tool/update.py
similarity index 97%
rename from update.py
rename to tool/update.py
index 43d43e2..8d923f7 100644
--- a/update.py
+++ b/tool/update.py
@@ -1,7 +1,7 @@
 import paramiko
 import os
 
-from ssh_client import RemoteClient
+from tool.ssh_client import RemoteClient
 
 
 class VersionManager:
-- 
GitLab