This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
66 lines (56 loc) · 1.89 KB
/
utils.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
import requests, json
import global_vars
def list_of_list_to_dict(input_list):
ret = dict()
for pair in input_list:
ret[pair[0]] = pair[1]
return ret
def send_run_to_jobe(jobe_url, request_data):
success = False
error_string = None
error_code = None
reponse_data = None
try:
r = None
r = requests.post(jobe_url + '/jobe/index.php/restapi/runs', json = request_data, timeout = global_vars.TTL_jobe_submit_runs)
r.raise_for_status()
# Success with result
success = True
reponse_data = r.json()
# All other error
except requests.Timeout:
error_string = 'timeout'
error_code = -1
except requests.ConnectionError: # No connection between jobe and this proxy
error_string = 'no_connection'
error_code = -2
except:
error_string = 'other_error'
error_code = r.status_code
return [success, reponse_data, error_code, error_string]
def send_file_to_jobe(jobe_url, file_list):
success = False
error_string = None
error_code = None
for file_pair in file_list:
try:
r = None
with open(global_vars.PATH_PREFIX_file_cache + file_pair[0], 'r') as f:
r = requests.put(jobe_url + '/jobe/index.php/restapi/files/' + file_pair[0], json = json.loads(f.read()))
r.raise_for_status()
# All other error
except requests.Timeout:
error_string = 'timeout'
error_code = -1
break
except requests.ConnectionError: # No connection between jobe and this proxy
error_string = 'no_connection'
error_code = -2
break
except:
error_string = 'other_error'
error_code = r.status_code
break
# Success with result
success = True
return [success, error_code, error_string]