diff --git a/scripts/scene_completion.py b/scripts/scene_completion.py index 5cb59b6f750ada98c6f758cc10aaac59e7a0bf35..9457d47fecdbdf4b3680ddc42638ad7acabf5b5f 100644 --- a/scripts/scene_completion.py +++ b/scripts/scene_completion.py @@ -3,6 +3,7 @@ from dotenv import load_dotenv from scp import SCPClient import os import subprocess +import time load_dotenv() hostname = os.getenv("HOSTNAME") @@ -10,6 +11,8 @@ username = os.getenv("USERNAME") password = os.getenv("PASSWORD") def send_files(shifted_disparity_path, shifted_t_path): + # sends two files needed to iridis + # files keep their names. NAMES MUST BE shifted_disparity.png AND shifted_t.png command = [ "scp", @@ -44,25 +47,76 @@ def get_completed_scene(shifted_disparity_path, shifted_t_path): client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # Connect to the server - client.connect(hostname, username=username, password=password) - - # Execute commands on the server - stdin, stdout, stderr = client.exec_command("cd mona/MDBNet360_GDP/") - stdin, stdout, stderr = client.exec_command("module load conda") - stdin, stdout, stderr = client.exec_command("source activate") - stdin, stdout, stderr = client.exec_command("conda activate sscenv") - stdin, stdout, stderr = client.exec_command("cd mona/MDBNet360_GDP/sbatch --partition=ecsstudents --account=ecsstudents run_obj_job.sh") - + try: + client.connect(hostname, username=username, password=password) + print("SSH connection established.") + + # Check if the connection is active + if client.get_transport().is_active(): + print("Connection is active.") + else: + print("Connection is not active.") + exit(1) # Exit the script if the connection is not active + except Exception as e: + print(f"Failed to connect to {hostname}: {e}") + exit(1) + + stdin, stdout, stderr = client.exec_command( + "cd mona/MDBNet360_GDP/" + + " && module load conda" + + " && source activate" + + " && conda activate ssc_env" + + " && sbatch --partition=ecsstudents --account=ecsstudents run_enhance360_job.sh" + ) + output = stdout.read().decode() + print(output) + + stdin, stdout, stderr = client.exec_command("squeue -lu kproject") + output = stdout.read().decode() + print(output) + + time.sleep(30) + + while "RUNNING" in output: + print("Sleeping for 30") + time.sleep(30) + stdin, stdout, stderr = client.exec_command("squeue -lu kproject") + output = stdout.read().decode() + print(output) - # Print the output of the command - print(stdout.read()) + print("Finish Enhancing") + + stdin, stdout, stderr = client.exec_command( + "cd mona/MDBNet360_GDP/ && ls" + + " && module load conda" + + " && source activate" + + " && conda activate ssc_env" + + " && sbatch --partition=ecsstudents --account=ecsstudents run_obj_job.sh" + ) + output = stdout.read().decode() + print(output) + + stdin, stdout, stderr = client.exec_command("squeue -lu kproject") + output = stdout.read().decode() + print(output) + time.sleep(30) + + while "RUNNING" in output: + print("Sleeping for 30") + time.sleep(30) + stdin, stdout, stderr = client.exec_command("squeue -lu kproject") + output = stdout.read().decode() + print(output) + + print("CLOSING") # Close the SSH connection client.close() + return True else: return False -out = send_files("C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Listening\\shifted-disparity.png", "C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Listening\\shifted_t.png") +out = get_completed_scene("C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Courtyard\\shifted-disparity.png", "C:\\Project\\AVVR-Pipeline-GDP4\\edgenet-360\\Data\\Courtyard\\shifted_t.png") print(out) \ No newline at end of file