@@ -15,12 +15,13 @@ Part of the DOMjudge Programming Contest Jury System and licensed
15
15
under the GNU GPL. See README and COPYING for details.
16
16
'''
17
17
18
- import json
19
18
from os import listdir
19
+ from typing import List
20
+ import json
20
21
import os .path
21
22
import re
23
+ import subprocess
22
24
import sys
23
- from typing import List
24
25
import yaml
25
26
26
27
sys .path .append ('@domserver_libdir@' )
@@ -213,19 +214,46 @@ if os.path.exists('problems.yaml') or os.path.exists('problems.json') or os.path
213
214
214
215
confirmIndividually = dj_utils .confirm ("Confirm individually for every problem" , False )
215
216
for problem in problems :
216
- print (f'Preparing problem \' { problem } \' .' )
217
+ print (f'\n Preparing problem \' { problem } \' .' )
217
218
if os .path .exists (f'{ problem } .zip' ):
218
219
os .unlink (f'{ problem } .zip' )
219
220
if not os .path .isdir (problem ) or not os .path .isfile (f'{ problem } /problem.yaml' ):
220
221
print ('Problem directory not found or doesn\' t contain a problem.yaml.' )
221
222
exit (3 )
222
- os .system (f'cd { problem } && zip -r \' ../{ problem } \' -- .timelimit *' )
223
+ zip_command = f"zip -r '../{ problem } ' -- .timelimit *"
224
+ process = subprocess .Popen (zip_command , cwd = problem , stdout = subprocess .PIPE , stderr = subprocess .STDOUT , text = True , shell = True )
225
+
226
+ lastLine = None
227
+ for line in process .stdout :
228
+ if lastLine :
229
+ sys .stdout .write ("\r " + " " * len (lastLine ))
230
+ sys .stdout .write (f"\r { line .strip ()} " )
231
+ sys .stdout .flush ()
232
+ lastLine = line
233
+
234
+ exit_code = process .wait ()
235
+ if exit_code == 0 :
236
+ if lastLine :
237
+ sys .stdout .write ("\r " + " " * len (lastLine ) + "\r " )
238
+ else :
239
+ print (f"\n Zipping problem failed with exit code: { exit_code } " )
223
240
224
241
if ((not confirmIndividually ) or dj_utils .confirm (f'Ready to import problem \' { problem } \' to problem={ problem } . Continue?' , True )):
225
242
print (f'Uploading problem \' { problem } \' , please be patient, this may take a while.' )
226
243
response = dj_utils .upload_file (
227
244
f'contests/{ cid } /problems' , 'zip' , f'{ problem } .zip' , {'problem' : problem })
228
- print (json .dumps (response , indent = 4 ))
245
+ if response and 'problem_id' in response :
246
+ print (f'Problem imported with ID { response ["problem_id" ]} :' )
247
+ if 'messages' in response :
248
+ messages = response ['messages' ]
249
+ types = {'info' : '🛈 ' , 'warning' : '⚠️ ' , 'danger' : '🚨' }
250
+ for t ,e in types .items ():
251
+ if t in messages and messages [t ]:
252
+ print (f' { e } { t .capitalize ()} :' )
253
+ for message in messages [t ]:
254
+ print (f' - { message } ' )
255
+ else :
256
+ print (json .dumps (response , indent = 4 ))
229
257
else :
230
258
print ('Skipping contest import.' )
231
259
else :
0 commit comments