root/branch/3.2.2/testXML.py
| Revision 486, 2.3 kB (checked in by quasiben, 4 years ago) |
|---|
| Line | |
|---|---|
| 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # testXML.py - test .xml configuration files |
| 4 | # |
| 5 | # example use (on Unix): |
| 6 | # % mkdir xml-tests |
| 7 | # % cd xml-tests |
| 8 | # % cp ../*.pif . |
| 9 | # % cp ../*.txt . |
| 10 | # % testXML.py vectorPlot.xml |
| 11 | # % ../compucell3d.sh -i vectorPlot.xml |
| 12 | # % ls -l *.xml|awk {'print "testXML.py " $9'} > testAll.sh |
| 13 | # % sh testAll.sh |
| 14 | # |
| 15 | # for cleaner output, might also want to comment out following lines in compucell3d.sh: |
| 16 | # echo "Configuration file: $xmlFile" |
| 17 | # echo "CompuCell3D - version $COMPUCELL3D_MAJOR_VERSION.$COMPUCELL3D_MINOR_VERSION.$COMPUCELL3D_BUILD_VERSION" |
| 18 | |
| 19 | |
| 20 | import sys |
| 21 | import string |
| 22 | import re |
| 23 | #import subprocess |
| 24 | import os, time |
| 25 | |
| 26 | |
| 27 | def processLine(line, output): |
| 28 | # line = string.strip(line) + "\n" # if want to strip blanks |
| 29 | |
| 30 | # for now, let's just do a simple replacement of Steps. |
| 31 | if string.find(line, "<Steps>") > -1: |
| 32 | # print 'found one: ' + line |
| 33 | # line = re.sub('\>','',line) |
| 34 | # print 'now line: ' + line |
| 35 | output.write( '<Steps>10</Steps>\n') |
| 36 | else: |
| 37 | output.write(line) |
| 38 | |
| 39 | def usage(): |
| 40 | msg = """Usage:\n testXML.py foo.xml\n |
| 41 | This script attempts to |
| 42 | The converted code is printed on the standard output. |
| 43 | |
| 44 | """ |
| 45 | print msg |
| 46 | |
| 47 | def main(): |
| 48 | if len(sys.argv) < 2: |
| 49 | usage() |
| 50 | sys.exit(1) |
| 51 | |
| 52 | # allow input config file to either have the .xml suffix or not |
| 53 | # we assume we'll read the input .xml file from the parent directory |
| 54 | # and output to the working dir. |
| 55 | name = sys.argv[1] |
| 56 | output = sys.stdout |
| 57 | if name[-4:] == '.xml': |
| 58 | infile = "../" + name |
| 59 | outfile = name |
| 60 | input = open(infile, 'r') |
| 61 | output = open(outfile, 'w') |
| 62 | else: |
| 63 | infile = "../" + name + ".xml" |
| 64 | outfile = name + ".xml" |
| 65 | input = open(infile, 'r') |
| 66 | output = open(outfile, 'w') |
| 67 | # print "infile,outfile= ",infile,outfile |
| 68 | |
| 69 | for line in input.readlines(): |
| 70 | processLine(line, output) |
| 71 | input.close() |
| 72 | |
| 73 | output.close() |
| 74 | |
| 75 | # execute cc3d on this .xml config file |
| 76 | cmd = "../compucell3d.sh -i " + outfile |
| 77 | print cmd |
| 78 | # subprocess.call(cmd) |
| 79 | os.system(cmd) |
| 80 | |
| 81 | # assuming you've redirected cerr and cout (from the player's main.cpp), concat to a master output file |
| 82 | os.system("cat cc3d-out.txt >> cc3d-all.txt") |
| 83 | os.system("echo '-------------------------------' >> cc3d-all.txt") |
| 84 | time.sleep(1) |
| 85 | |
| 86 | if __name__ == "__main__": |
| 87 | main() |
Note: See TracBrowser
for help on using the browser.
