Hi Attila, On Tue 08/05/12,15:29, Hammer Attila wrote: > I not have a Github account, but sending the script. > don't surprise, very fresh the script, possible future need changing > little, but work. Thanks, Just small improvements in the version attached. > The script only 53 lines. Try it, and tells me what can I need > changing in the script to the script working more flexible with the > future and helps beginner table creators generating test harnesses > with the new tables. I think its generally ok, we can always improve it later when there is a new need. > My example words listf ile wonderful generated the script with the > new test harness file, the new generated Python script rans without > any errors. Yes, and with the attached version it is even stronger against errors, there is only the last example in the hello file that will break it, but its ok. Please check it, and see if I have forgotten anything. Thanks. Mesar
#!/usr/bin/env python #!coding: utf-8 import os, sys, louis tableName = os.path.basename(sys.argv[2]) header = [ '# -*- coding: utf-8 -*-', '', '"""', 'Liblouis test harness for the %s table.' % tableName, 'Please see the liblouis documentationfor more information.', '"""' '', 'import sys, louis', '', 'table = \'%s\'' % tableName, '', 'tests = [' ] def generate_content(lines): content = '' limit = len(lines) firstLine = True for i in range(limit): lines[i] = lines[i].replace('\n', '') lines[i] = lines[i].decode('utf-8') if lines[i] == '': continue if firstLine: content = ' {\n' firstLine = False else: content += ' {\n' txtQuoting = "'"; brlQuoting = "'" if "'" in lines[i] and '"' in lines[i]: txtQuoting = '"""' elif "'" in lines[i]: txtQuoting = '"' content += ' \'txt\': u%s%s%s,\n' %(txtQuoting, lines[i], txtQuoting) brl = louis.translateString([sys.argv[2]], lines[i], None, 0) if "'" in brl and '"' in brl: brlQuoting = '"""' elif "'" in brl: brlQuoting = '"' content += ' \'brl\': u%s%s%s,\n' %(brlQuoting, brl, brlQuoting) content += ' },' content += '\n]' return content #Main program #print len(sys.argv) if len(sys.argv)!=4: print 'Usage: '+sys.argv[0]+' <textFile> <liblouisTable> <testHarnessFile>' sys.exit() if not os.path.exists(sys.argv[1]): print 'Error: '+sys.argv[1]+' file doesn\'t exist.' sys.exit() if not os.path.exists(sys.argv[2]): print 'Error: '+sys.argv[2]+' file doesn\'t exist.' sys.exit() f=open(sys.argv[1], 'r') lines=f.readlines() f.close() g=open(sys.argv[3], 'w') g.write("\n".join(header)+"\n") content=generate_content(lines) g.write(content.encode('utf-8')) g.close() print 'Test harness generation is complete.\nPlease inspect %s, and do any needed corrections' %sys.argv[3]
hello' world" hello world, this is a test. """foo bar 'bas"""