Skip to content

Commit b21b51a

Browse files
author
unknown
committed
parse.py now successfully downloads on win7 (replaced two system calls w/ Python funcs) and will only execute chmod on unix
1 parent 6166fc2 commit b21b51a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

parse.py

100755100644
+9-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from subprocess import call
1616
from functools import partial, wraps
1717
import re
18+
import os
19+
import shutil
1820

1921
# User modifiable constants:
2022
TEMPLATE='main.cc'
@@ -183,7 +185,8 @@ def generate_test_script(folder, num_tests, problem):
183185
' fi\n'
184186
'done\n'
185187
.format(num_tests, BOLD, NORM, GREEN_F, RED_F, TIME_CMD, TIME_AP))
186-
call(['chmod', '+x', folder + 'test.sh'])
188+
if os.name in ['posix']:
189+
call(['chmod', '+x', folder + 'test.sh'])
187190

188191
# Main function.
189192
def main():
@@ -203,8 +206,11 @@ def main():
203206
for index, problem in enumerate(content.problems):
204207
print ('Downloading Problem %s: %s...' % (problem, content.problem_names[index]))
205208
folder = '%s/%s/' % (contest, problem)
206-
call(['mkdir', '-p', folder])
207-
call(['cp', '-n', TEMPLATE, '%s/%s/%s.cc' % (contest, problem, problem)])
209+
if not os.path.exists(folder):
210+
os.makedirs(folder)
211+
# call(['mkdir', '-p', folder])
212+
# call(['cp', '-n', TEMPLATE, '%s/%s/%s.cc' % (contest, problem, problem)])
213+
shutil.copyfile(TEMPLATE, '%s/%s/%s.cc' % (contest, problem, problem))
208214
num_tests = parse_problem(folder, contest, problem)
209215
print('%d sample test(s) found.' % num_tests)
210216
generate_test_script(folder, num_tests, problem)

0 commit comments

Comments
 (0)