3 # Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
5 # Jansson is free software; you can redistribute it and/or modify
6 # it under the terms of the MIT license. See LICENSE for details.
11 def open_files(outdir, i, name):
12 basename = '%02d_%s' % (i, name)
14 input_path = os.path.join(outdir, basename + '.in')
15 output_path = os.path.join(outdir, basename + '.out')
16 return open(input_path, 'w'), open(output_path, 'w')
19 if len(sys.argv) != 3:
20 print 'usage: %s input-file output-directory' % sys.argv[0]
23 infile = os.path.normpath(sys.argv[1])
24 outdir = os.path.normpath(sys.argv[2])
26 if not os.path.exists(outdir):
27 print >>sys.stderr, 'output directory %r does not exist!' % outdir
32 input, output = None, None
34 for line in open(infile):
35 if line.startswith('==== '):
37 if input is not None and output is not None:
40 input, output = open_files(outdir, n, line[5:line.find(' ====\n')])
42 elif line == '====\n':
47 if input is not None and output is not None:
51 print >>sys.stderr, "%s: %d test cases" % (infile, n)
53 if __name__ == '__main__':