12e5b6d6dSopenharmony_ci#!/usr/bin/python -B 22e5b6d6dSopenharmony_ci# 32e5b6d6dSopenharmony_ci# Copyright (C) 2017 and later: Unicode, Inc. and others. 42e5b6d6dSopenharmony_ci# License & terms of use: http://www.unicode.org/copyright.html 52e5b6d6dSopenharmony_ci# 62e5b6d6dSopenharmony_ci# Copyright (C) 2009, International Business Machines 72e5b6d6dSopenharmony_ci# Corporation and others. All Rights Reserved. 82e5b6d6dSopenharmony_ci# 92e5b6d6dSopenharmony_ci# file name: genteststub.py 102e5b6d6dSopenharmony_ci# encoding: US-ASCII 112e5b6d6dSopenharmony_ci# tab size: 8 (not used) 122e5b6d6dSopenharmony_ci# indentation:2 132e5b6d6dSopenharmony_ci 142e5b6d6dSopenharmony_ci__author__ = "Claire Ho" 152e5b6d6dSopenharmony_ci 162e5b6d6dSopenharmony_ciimport sys 172e5b6d6dSopenharmony_ci 182e5b6d6dSopenharmony_ci# read file 192e5b6d6dSopenharmony_ciprint "command: python genteststub.py <inputFileName.txt> <outputFileName.txt>" 202e5b6d6dSopenharmony_ciprint "if the fileName.txt is omitted, the default data file is CollationTest_NON_IGNORABLE_SHORT.txt" 212e5b6d6dSopenharmony_ciif len(sys.argv) >= 2: 222e5b6d6dSopenharmony_ci fname=sys.argv[1] 232e5b6d6dSopenharmony_cielse : 242e5b6d6dSopenharmony_ci fname="CollationTest_NON_IGNORABLE_SHORT.txt" 252e5b6d6dSopenharmony_ciopenfile = open(fname, 'r'); 262e5b6d6dSopenharmony_ci 272e5b6d6dSopenharmony_ci#output file name 282e5b6d6dSopenharmony_ciext=fname.find(".txt"); 292e5b6d6dSopenharmony_ciif len(sys.argv) >=3 : 302e5b6d6dSopenharmony_ci wFname = sys.argv[2] 312e5b6d6dSopenharmony_cielif (ext>0) : 322e5b6d6dSopenharmony_ci wFname = fname[:ext+1]+"_STUB.txt" 332e5b6d6dSopenharmony_cielse : 342e5b6d6dSopenharmony_ci wFname = "out.txt" 352e5b6d6dSopenharmony_ciwrfile = open(wFname,'w') 362e5b6d6dSopenharmony_ci 372e5b6d6dSopenharmony_ciprint "Reading file: "+fname+" ..." 382e5b6d6dSopenharmony_ciprint "Writing file: "+wFname+" ..." 392e5b6d6dSopenharmony_cicount=10 402e5b6d6dSopenharmony_cifor line in openfile.readlines(): 412e5b6d6dSopenharmony_ci pos = line.find("#") 422e5b6d6dSopenharmony_ci if pos == 0: 432e5b6d6dSopenharmony_ci # print the header 442e5b6d6dSopenharmony_ci wrfile.write(line.rstrip()+"\n") 452e5b6d6dSopenharmony_ci continue 462e5b6d6dSopenharmony_ci if pos >= 0: line = line[:pos] 472e5b6d6dSopenharmony_ci line = line.rstrip() 482e5b6d6dSopenharmony_ci if line: 492e5b6d6dSopenharmony_ci if (count==10): 502e5b6d6dSopenharmony_ci wrfile.write(line+"\n") 512e5b6d6dSopenharmony_ci count=0 522e5b6d6dSopenharmony_ci count=count+1 532e5b6d6dSopenharmony_ciif count!=1: 542e5b6d6dSopenharmony_ci if line: 552e5b6d6dSopenharmony_ci wrfile.write(line+"\n") # write the last case 562e5b6d6dSopenharmony_ciwrfile.close() 572e5b6d6dSopenharmony_ciopenfile.close() 58