@@ -58,30 +58,74 @@ def main(args):
58
58
job_queues = {joe : [] for joe in joes }
59
59
60
60
params = {"comments" : args .comments }
61
+
62
+ if args .url_mode or args .sample_url_mode :
61
63
62
- success = False
63
-
64
- # Try to submit to best server, if it fails continue until no server is left
65
- while joes and not success :
66
- try :
67
- joe = pick_best_joe (joes )
68
- except AllServersOfflineError as e :
69
- print ("Failed to fetch any server: " , e , file = sys .stderr )
70
- break
71
- if args . url_mode or args . sample_url_mode :
64
+ success = False
65
+
66
+ # Try to submit to best server, if it fails continue until no server is left
67
+ while joes and not success :
68
+ try :
69
+ joe = pick_best_joe (joes )
70
+ except AllServersOfflineError as e :
71
+ print ("Failed to fetch any server: " , e , file = sys .stderr )
72
+ break
73
+
72
74
success = submit_url (args , joe , job_queues , params )
73
- else :
74
- success = submit_sample (args , joe , job_queues , params )
75
75
76
- if success :
77
- break
76
+ if success :
77
+ break
78
+
79
+ joes .remove (joe )
80
+ print ("Trying to submit to next server" )
78
81
79
- joes .remove (joe )
80
- print ("Trying to submit to next server" )
82
+ if not joes and not success :
83
+ print ("No more servers to submit to, submission failed" , file = sys .stderr )
84
+
85
+ # File or directory submission
86
+ else :
87
+
88
+ # if given a directory, collect all files
89
+ if os .path .isdir (args .path_or_url ):
90
+ paths = [os .path .join (args .path_or_url , name ) for name in os .listdir (args .path_or_url )]
91
+ else :
92
+ paths = [args .path_or_url ]
81
93
82
- if not joes and not success :
83
- print ("No more servers to submit to, submission failed" , file = sys .stderr )
94
+ for path in paths :
84
95
96
+ success = False
97
+ joes_clone = list (joes )
98
+
99
+ # Try to submit to best server, if it fails continue until no server is left
100
+ while joes and not success :
101
+ try :
102
+ joe = pick_best_joe (joes_clone )
103
+ except AllServersOfflineError as e :
104
+ print ("Failed to fetch any server: " , e , file = sys .stderr )
105
+ break
106
+
107
+ name = os .path .basename (path )
108
+ try :
109
+ with open (path , "rb" ) as f :
110
+ data = joe .submit_sample (f , params = params )
111
+
112
+ print ("Submitted '{0}' with webid(s): {1} to server: {2}" .format (name , "," .join (data ["webids" ]), joe .apiurl ))
113
+ for webid in data ["webids" ]:
114
+ job_queues [joe ].append (Submission (name , webid ))
115
+ success = True
116
+
117
+ except Exception as e :
118
+ print ("Submitting '{0}' failed: {1}" .format (name , e ), file = sys .stderr )
119
+
120
+ if success :
121
+ break
122
+
123
+ joes_clone .remove (joe )
124
+ print ("Trying to submit to next server" )
125
+
126
+ if not joes_clone and not success :
127
+ print ("No more servers to submit to, submission failed" , file = sys .stderr )
128
+
85
129
def job_count ():
86
130
return sum (len (jobs ) for jobs in job_queues .values ())
87
131
@@ -132,36 +176,6 @@ def submit_url(args, joe, job_queues, params):
132
176
except Exception as e :
133
177
print ("Submitting '{0}' failed: {1}" .format (args .path_or_url , e ))
134
178
return False
135
-
136
- def submit_sample (args , joe , job_queues , params ):
137
- '''
138
- Tries to commit a sample or directory to the server joe
139
- Returns true if at least one sample submission was successful, False otherwise
140
- '''
141
-
142
- # if given a directory, collect all files
143
- if os .path .isdir (args .path_or_url ):
144
- paths = [os .path .join (args .path_or_url , name ) for name in os .listdir (args .path_or_url )]
145
- else :
146
- paths = [args .path_or_url ]
147
-
148
- for path in paths :
149
- name = os .path .basename (path )
150
- try :
151
- with open (path , "rb" ) as f :
152
- data = joe .submit_sample (f , params = params )
153
-
154
- print ("Submitted '{0}' with webid(s): {1} to server: {2}" .format (args .path_or_url , "," .join (data ["webids" ]), joe .apiurl ))
155
- for webid in data ["webids" ]:
156
- job_queues [joe ].append (Submission (name , webid ))
157
- except Exception as e :
158
- print ("Submitting '{0}' failed: {1}" .format (name , e ), file = sys .stderr )
159
-
160
- # If at least one submission worked, return True
161
- if job_queues [joe ]:
162
- return True
163
- else :
164
- return False
165
179
166
180
def handle_finished_analysis (joe , submission , info , outdir ):
167
181
# download best run
@@ -241,7 +255,7 @@ def pick_best_joe(joes):
241
255
pass
242
256
243
257
if not min_joes :
244
- raise AllServersOfflineError ("All servers are offline." )
258
+ raise AllServersOfflineError ("All servers are offline or no more servers left ." )
245
259
246
260
return random .choice (min_joes )
247
261
0 commit comments