From d546ac8c20e4d4ee08ac5b6a14dd21362a750aef Mon Sep 17 00:00:00 2001 From: Namya LG <53875297+Namyalg@users.noreply.github.com> Date: Wed, 25 May 2022 15:00:27 +0530 Subject: [PATCH 1/2] Create simulation_status.py --- local/tests/simulation_status.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 local/tests/simulation_status.py diff --git a/local/tests/simulation_status.py b/local/tests/simulation_status.py new file mode 100644 index 00000000..e48b8551 --- /dev/null +++ b/local/tests/simulation_status.py @@ -0,0 +1,35 @@ +import os + + +def get_container_id(): + """ + Return the container id corresponding to the image gcbm-api + """ + container_id = "" + os.system('docker ps >> simulation.txt') + with open('simulation.txt') as file_handle: + lines = file_handle.readlines() + for line in lines: + if 'gcbm-api' in line: + container_id = line.split()[0] + os.system('rm simulation.txt') + return container_id + + +def get_simulation_status(): + """ + If the container gcbm-api is running, the associated logs are returned + """ + container_id = get_container_id() + logs_file_name = container_id + ".txt" + if container_id != '': + logs_cmd = "docker logs " + container_id + " > " + logs_file_name + " 2>&1" + os.system(logs_cmd) + logs = [] + with open(logs_file_name) as file_handle: + logs = file_handle.readlines() + os.system('rm ' + logs_file_name) + return {'container_running': True, 'logs': logs} + return {'container_running': False} + +print(get_simulation_status()) From aea0a574a74320c011ed7fccd7d85f35f310b2d8 Mon Sep 17 00:00:00 2001 From: Namya LG <53875297+Namyalg@users.noreply.github.com> Date: Tue, 7 Jun 2022 19:54:24 +0530 Subject: [PATCH 2/2] Update simulation_status.py --- local/tests/simulation_status.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local/tests/simulation_status.py b/local/tests/simulation_status.py index e48b8551..3718453d 100644 --- a/local/tests/simulation_status.py +++ b/local/tests/simulation_status.py @@ -28,7 +28,7 @@ def get_simulation_status(): logs = [] with open(logs_file_name) as file_handle: logs = file_handle.readlines() - os.system('rm ' + logs_file_name) + #os.system('rm ' + logs_file_name) return {'container_running': True, 'logs': logs} return {'container_running': False}