-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_results.py
119 lines (106 loc) · 4.93 KB
/
get_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
"""
This file is part of cramb.
cramb is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cramb is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CRAMrBayesT. If not, see <https://www.gnu.org/licenses/>.
Copyright 2018 Rodrigo Aluizio
"""
from tkinter import *
from tkinter.ttk import *
from os import makedirs, remove
from os.path import exists, join
from requests.exceptions import ConnectionError
from download_folder_path import get_download_path as dl_dir
from tkinter import messagebox
import python_cipres.client as cra
def get_results(self, job):
"""
While loop that evaluates Job status and download the result
when the job is complete.
"""
self.send_button.config(state=DISABLED)
self.mb_font = Style()
self.mb_font.configure('TMessageBox', font=('Helvetica', 8))
while True:
try:
job.update()
while not job.isDone():
try:
job.update()
self.text_box.config(state=NORMAL)
self.text_box.insert(END, job.messages[-1] + '\n', "cool")
self.text_box.see(END)
self.text_box.update()
self.text_box.config(state=DISABLED)
except ConnectionError:
self.text_box(state=NORMAL)
self.text_box.insert(END, "Connection lost! Will keep trying!\n", "error")
self.text_box.see(END)
self.text_box.update()
self.text_box(state=DISABLED)
pass
else:
# Create a directory to store the results
dld = join(dl_dir(), str(job.metadata['clientJobName']))
if not exists(dld):
makedirs(dld)
self.text_box.config(state=NORMAL)
self.text_box.insert(END, "Downloading results of " + str(job.metadata['clientJobName']) + '.\n',
"cool")
self.text_box.see(END)
self.text_box.config(state=DISABLED)
self.text_box.update()
result_files = job.listResults(final=True)
try:
j = 0
for filename in result_files:
result_files[filename].download(directory=dld)
j += 1
self.progress.config(value=j, maximum=len(result_files)-1)
self.progress.update()
except ConnectionError:
self.text_box.config(state=NORMAL)
self.text_box.insert(END, "Connection lost!\nRestart the application and confirm the download of"
"previous results\n", "error")
self.text_box.see(END)
self.text_box.update()
self.text_box.config(state=DISABLED)
self.send_button.config(state=NORMAL)
break
job.delete()
self.text_box.config(state=NORMAL)
self.text_box.insert(END, "Job completed and files downloaded!\n", "done")
self.text_box.see(END)
self.text_box.config(state=DISABLED)
try:
remove(join(dl_dir(), str(job.metadata['clientJobName'] + '.pkl')))
except FileNotFoundError:
pass
self.send_button.config(state=NORMAL)
self.results_button.config(state=NORMAL)
except SystemExit:
confirm = messagebox.askyesno("Job executing!", "Are you sure you want to exit?", justify=CENTER)
if confirm:
messagebox.showwarning("Job result pending!", "You current job results will not be downloaded "
"automatically. You will have to retrieve the results "
"later!",
icon='warning', justify=CENTER)
self.send_button.config(state=NORMAL)
exit(0)
else:
continue
except cra.CipresError:
self.text_box.insert(END, "CIPRES services are currently unavailable!\nTry again later!\n", "error")
self.text_box.see(END)
self.text_box.config(state=DISABLED)
self.send_button.config(state=NORMAL)
self.send_button.config(state=NORMAL)
break