@@ -15,12 +15,13 @@ Part of the DOMjudge Programming Contest Jury System and licensed
1515under the GNU GPL. See README and COPYING for details.
1616'''
1717
18- import json
1918from os import listdir
19+ from typing import List
20+ import json
2021import os .path
2122import re
23+ import subprocess
2224import sys
23- from typing import List
2425import yaml
2526
2627sys .path .append ('@domserver_libdir@' )
@@ -213,19 +214,46 @@ if os.path.exists('problems.yaml') or os.path.exists('problems.json') or os.path
213214
214215 confirmIndividually = dj_utils .confirm ("Confirm individually for every problem" , False )
215216 for problem in problems :
216- print (f'Preparing problem \' { problem } \' .' )
217+ print (f'\n Preparing problem \' { problem } \' .' )
217218 if os .path .exists (f'{ problem } .zip' ):
218219 os .unlink (f'{ problem } .zip' )
219220 if not os .path .isdir (problem ) or not os .path .isfile (f'{ problem } /problem.yaml' ):
220221 print ('Problem directory not found or doesn\' t contain a problem.yaml.' )
221222 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 } " )
223240
224241 if ((not confirmIndividually ) or dj_utils .confirm (f'Ready to import problem \' { problem } \' to problem={ problem } . Continue?' , True )):
225242 print (f'Uploading problem \' { problem } \' , please be patient, this may take a while.' )
226243 response = dj_utils .upload_file (
227244 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 ))
229257 else :
230258 print ('Skipping contest import.' )
231259else :
0 commit comments