Home | History | Annotate | Download | only in genuca
      1 #!/usr/bin/python
      2 #   Copyright (C) 2009, International Business Machines
      3 #   Corporation and others.  All Rights Reserved.
      4 #
      5 #   file name:  genteststub.py
      6 #   encoding:   US-ASCII
      7 #   tab size:   8 (not used)
      8 #   indentation:2
      9 
     10 __author__ = "Claire Ho"
     11 
     12 import sys
     13 
     14 # read file
     15 print "command:  python genteststub.py <inputFileName.txt>  <outputFileName.txt>"
     16 print "if the fileName.txt is omitted, the default data file is CollationTest_NON_IGNORABLE_SHORT.txt"
     17 if len(sys.argv) >= 2:
     18   fname=sys.argv[1]
     19 else :
     20   fname="CollationTest_NON_IGNORABLE_SHORT.txt"
     21 openfile = open(fname, 'r');
     22 
     23 #output file name
     24 ext=fname.find(".txt");
     25 if len(sys.argv) >=3 :
     26   wFname = sys.argv[2]
     27 elif (ext>0) :
     28   wFname = fname[:ext+1]+"_STUB.txt"
     29 else :
     30   wFname = "out.txt"
     31 wrfile = open(wFname,'w')
     32 
     33 print "Reading file: "+fname+" ..."
     34 print "Writing file: "+wFname+" ..."
     35 count=10
     36 for line in openfile.readlines():
     37   pos = line.find("#")
     38   if pos == 0:
     39     # print the header
     40     wrfile.write(line.rstrip()+"\n")
     41     continue
     42   if pos >= 0: line = line[:pos]
     43   line = line.rstrip()
     44   if line:
     45     if (count==10):
     46       wrfile.write(line+"\n")
     47       count=0
     48     count=count+1
     49 if count!=1:
     50   if line:
     51     wrfile.write(line+"\n")  # write the last case
     52 wrfile.close()
     53 openfile.close()
     54