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