2009-07-10 02:01:40 +08:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def open_files(outdir, i):
|
|
|
|
return (open(os.path.join(outdir, 'test%02d.in' % i), 'w'),
|
|
|
|
open(os.path.join(outdir, 'test%02d.out' % i), 'w'))
|
|
|
|
|
|
|
|
def close_files(input, output):
|
|
|
|
print os.path.basename(input.name), os.path.basename(output.name)
|
|
|
|
input.close()
|
|
|
|
output.close()
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if len(sys.argv) != 3:
|
|
|
|
print 'usage: %s input-file output-directory' % sys.argv[0]
|
|
|
|
return 2
|
|
|
|
|
2009-07-18 20:59:55 +08:00
|
|
|
infile = os.path.normpath(sys.argv[1])
|
|
|
|
outdir = os.path.normpath(sys.argv[2])
|
2009-07-10 02:01:40 +08:00
|
|
|
|
|
|
|
if not os.path.exists(outdir):
|
|
|
|
print >>sys.stderr, 'output directory %r does not exist!' % outdir
|
|
|
|
return 1
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
input, output = open_files(outdir, i)
|
|
|
|
current = input
|
|
|
|
|
|
|
|
for line in open(infile):
|
|
|
|
if line == '====\n':
|
|
|
|
current = output
|
|
|
|
elif line == '========\n':
|
|
|
|
close_files(input, output)
|
|
|
|
i += 1
|
|
|
|
input, output = open_files(outdir, i)
|
|
|
|
current = input
|
|
|
|
else:
|
|
|
|
current.write(line)
|
|
|
|
|
|
|
|
close_files(input, output)
|
2009-07-18 20:59:55 +08:00
|
|
|
print >>sys.stderr, "%s: %d test cases" % (infile, i + 1)
|
2009-07-10 02:01:40 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main() or 0)
|