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.
10 from optparse import OptionParser
12 def strip_file(filename):
13 with open(filename) as fobj:
15 with open(filename, 'w') as fobj:
16 fobj.write(data.strip())
18 def open_files(outdir, i, name):
19 basename = '%02d_%s' % (i, name)
21 input_path = os.path.join(outdir, basename + '.in')
22 output_path = os.path.join(outdir, basename + '.out')
23 return open(input_path, 'w'), open(output_path, 'w')
26 parser = OptionParser('usage: %prog [options] inputfile outputdir')
27 parser.add_option('--strip', help='strip whitespace from input',
28 action='store_true', default=False)
29 options, args = parser.parse_args()
35 infile = os.path.normpath(args[0])
36 outdir = os.path.normpath(args[1])
38 if not os.path.exists(outdir):
39 print >>sys.stderr, 'output directory %r does not exist!' % outdir
44 input, output = None, None
46 for line in open(infile):
47 if line.startswith('==== '):
49 if input is not None and output is not None:
53 strip_file(input.name)
54 input, output = open_files(outdir, n, line[5:line.find(' ====\n')])
56 elif line == '====\n':
61 if input is not None and output is not None:
65 print >>sys.stderr, "%s: %d test cases" % (infile, n)
67 if __name__ == '__main__':