Patrick Meredith | b89dd23 | 2005-10-13 16:26:50 +0000 | [diff] [blame^] | 1 | #! /usr/bin/python |
| 2 | |
| 3 | #changelog: |
| 4 | #10/13/2005: exntended to remove variables of the form %tmp(.#)* rather than just |
| 5 | #%tmp.#, i.e. it now will remove %tmp.12.3.15 etc, additionally fixed a spelling error in |
| 6 | #the comments |
| 7 | #10/12/2005: now it only removes nodes and edges for which the label is %tmp.# rather |
| 8 | #than removing all lines for which the lable CONTAINS %tmp.# |
| 9 | import re |
| 10 | import sys |
| 11 | if( len(sys.argv) < 3 ): |
| 12 | print 'usage is: ./DSAclean <dot_file_to_be_cleaned> <out_put_file>' |
| 13 | sys.exit(1) |
| 14 | #get a file object |
| 15 | input = open(sys.argv[1], 'r') |
| 16 | output = open(sys.argv[2], 'w') |
| 17 | #we'll get this one line at a time...while we could just put the whole thing in a string |
| 18 | #it would kill old computers |
| 19 | buffer = input.readline() |
| 20 | while buffer != '': |
| 21 | if re.compile("label(\s*)=(\s*)\"\s%tmp(.\d*)*(\s*)\"").search(buffer): |
| 22 | #skip next line, write neither this line nor the next |
| 23 | buffer = input.readline() |
| 24 | else: |
| 25 | #this isn't a tmp Node, we can write it |
| 26 | output.write(buffer) |
| 27 | #prepare for the next iteration |
| 28 | buffer = input.readline() |
| 29 | input.close() |
| 30 | output.close() |