@@ -130,6 +130,11 @@ def create_workdir_structure(site, contest):
130
130
"""
131
131
Method to create the working directory structure
132
132
"""
133
+
134
+ # No need to create directories for SPOJ as it does not have contests
135
+ if site == 'spoj' :
136
+ return
137
+
133
138
try :
134
139
with open (os .path .join (Utilities .cache_dir , 'constants.json' ), 'r' ) as f :
135
140
data = f .read ()
@@ -157,6 +162,9 @@ def check_cache(site, contest, problem):
157
162
contest ))
158
163
return False
159
164
165
+ # Handle case for SPOJ specially as it does not have contests
166
+ contest = '' if site == 'spoj' else contest
167
+
160
168
if os .path .isdir (os .path .join (Utilities .cache_dir , site , contest , problem )):
161
169
return True
162
170
else :
@@ -169,6 +177,10 @@ def store_files(site, contest, problem, inputs, outputs):
169
177
"""
170
178
Method to store the test cases in files
171
179
"""
180
+
181
+ # Handle case for SPOJ specially as it does not have contests
182
+ contest = '' if site == 'spoj' else contest
183
+
172
184
for i , inp in enumerate (inputs ):
173
185
filename = os .path .join (
174
186
Utilities .cache_dir , site , contest , problem , 'Input' + str (i ))
@@ -251,6 +263,9 @@ def handle_kbd_interrupt(site, contest, problem):
251
263
from shutil import rmtree
252
264
print 'Cleaning up...'
253
265
266
+ # Handle case for SPOJ specially as it does not have contests
267
+ contest = '' if site == 'spoj' else contest
268
+
254
269
if problem is not None :
255
270
path = os .path .join (Utilities .cache_dir , site , contest , problem )
256
271
if os .path .isdir (path ):
@@ -275,8 +290,11 @@ def run_solution(problem):
275
290
print 'ERROR : No such file'
276
291
sys .exit (0 )
277
292
293
+ # For SPOJ, go up two directory levels as it does not have contests
294
+ up_dir_level = 2 if problem_path .split ('/' )[- 2 ] == 'spoj' else 3
295
+
278
296
testcases_path = os .path .join (
279
- Utilities .cache_dir , * problem_path .split ('/' )[- 3 :])
297
+ Utilities .cache_dir , * problem_path .split ('/' )[- up_dir_level :])
280
298
281
299
if os .path .isdir (testcases_path ):
282
300
num_cases = len (os .listdir (testcases_path )) / 2
@@ -401,15 +419,26 @@ def run_solution(problem):
401
419
402
420
else :
403
421
print 'Test cases not found locally...'
404
- args = {
405
- 'site' : testcases_path .split ('/' )[- 3 ],
406
- 'contest' : testcases_path .split ('/' )[- 2 ],
407
- 'problem' : testcases_path .split ('/' )[- 1 ],
408
- 'force' : True
409
- }
422
+
423
+ # Handle case for SPOJ specially as it does not have contests
424
+ if problem_path .split ('/' )[- 2 ] == 'spoj' :
425
+ args = {
426
+ 'site' : 'spoj' ,
427
+ 'contest' : None ,
428
+ 'problem' : testcases_path .split ('/' )[- 1 ],
429
+ 'force' : True
430
+ }
431
+ else :
432
+ args = {
433
+ 'site' : testcases_path .split ('/' )[- 3 ],
434
+ 'contest' : testcases_path .split ('/' )[- 2 ],
435
+ 'problem' : testcases_path .split ('/' )[- 1 ],
436
+ 'force' : True
437
+ }
438
+
410
439
Utilities .download_problem_testcases (args )
411
440
412
- print 'Done. Running your solution against sample cases...'
441
+ print 'Running your solution against sample cases...'
413
442
Utilities .run_solution (problem + '.' + extension )
414
443
415
444
@staticmethod
@@ -715,6 +744,13 @@ def parse_html(self, req):
715
744
soup = bs (req .text , 'html.parser' )
716
745
717
746
test_cases = soup .findAll ('pre' )
747
+
748
+ if test_cases is None or len (test_cases ) == 0 :
749
+ print 'Problem not found..'
750
+ Utilities .handle_kbd_interrupt (
751
+ self .site , self .contest , self .problem )
752
+ sys .exit (0 )
753
+
718
754
formatted_inputs , formatted_outputs = [], []
719
755
720
756
input_list = [
0 commit comments