From 7dce87f8f4424ceaae481c4d769ab75247e98f62 Mon Sep 17 00:00:00 2001
From: shinedday <shinedday@gmail.com>
Date: Wed, 11 May 2022 15:09:42 +0200
Subject: [PATCH] fix the update

---
 iotAmak/ihm.py             | 23 ++++++++++++++++++++---
 iotAmak/tool/ssh_client.py |  6 +++---
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/iotAmak/ihm.py b/iotAmak/ihm.py
index 1347488..5c3db31 100644
--- a/iotAmak/ihm.py
+++ b/iotAmak/ihm.py
@@ -16,7 +16,9 @@ from iotAmak.tool.ssh_client import SSHClient, Cmd
 
 class Ihm(MqttClient, SSHClient):
 
-    def __init__(self, config_path):
+    def __init__(self, config_path, experiment_name, version="0.0.1"):
+        self.version = version
+        self.experiment_name = experiment_name
         self.broker_ip = read_broker(config_path)
         MqttClient.__init__(self, self.broker_ip, "Ihm")
         SSHClient.__init__(self, read_ssh(config_path))
@@ -117,7 +119,22 @@ class Ihm(MqttClient, SSHClient):
             if cmd.lower() == "update":
                 commands = [
                     Cmd(
-                        cmd="rm -r Desktop/mqtt_goyon/iotamak-core"
+                        cmd="cd Desktop/mqtt_goyon/iotamak-core"
+                    ),
+                    Cmd(
+                        cmd="git pull"
+                    ),
+                    Cmd(
+                        cmd="git checkout core_to_module"
+                    ),
+                    Cmd(
+                        cmd="python3 -m pip install --force-reinstall dist/iotAmak-"+self.version+"-py3-none-any.whl"
+                    ),
+                    Cmd(
+                        cmd="cd ../../../"
+                    ),
+                    Cmd(
+                        cmd="rm -r Desktop/mqtt_goyon/example/" + self.experiment_name
                     )
 
                 ]
@@ -125,7 +142,7 @@ class Ihm(MqttClient, SSHClient):
                     print("Hostname :", self.clients[i_client].hostname, " User :", self.clients[i_client].user)
                     self.run_cmd(i_client, commands)
 
-                self.update()
+                self.update(self.experiment_name)
 
             # Crée les processus amas/env/scheduler de l'experience chargé
             if cmd.lower() == "start":
diff --git a/iotAmak/tool/ssh_client.py b/iotAmak/tool/ssh_client.py
index 3f7d2e2..591b060 100644
--- a/iotAmak/tool/ssh_client.py
+++ b/iotAmak/tool/ssh_client.py
@@ -44,13 +44,13 @@ class SSHClient:
             print("pxssh failed on login.")
             print(e)
 
-    def update(self):
+    def update(self, experiment_name):
         for client in self.clients:
             transport = paramiko.Transport((client.hostname, 22))
             transport.connect(username=client.user, password=client.password)
             sftp = MySFTPClient.from_transport(transport)
-            sftp.mkdir("./Desktop/mqtt_goyon/iotamak-core", ignore_existing=True)
-            sftp.put_dir("/mnt/d/work/stage m1/iotamak-core", "./Desktop/mqtt_goyon/iotamak-core")
+            sftp.mkdir("Desktop/mqtt_goyon/example/" + experiment_name, ignore_existing=True)
+            sftp.put_dir("../"+experiment_name, "Desktop/mqtt_goyon/example/" + experiment_name)
             sftp.close()
 
 class MySFTPClient(paramiko.SFTPClient):
-- 
GitLab