Hy Mesar, I not have a Github account, but sending the script.don't surprise, very fresh the script, possible future need changing little, but work.
Following parameters are need give: - Input file, this is the required plain text file.- Liblouis translation table, need now the full path, for example /usr/share/liblouis/tables/hu1.ctb.
- Output file, this file will be the new generated test harness file.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.
My example words listf ile wonderful generated the script with the new test harness file, the new generated Python script rans without any errors.
Attila
#!/usr/bin/env python #!coding: utf-8 import os, sys, louis def generate_header(): header='# -*- coding: utf-8 -*-\n\ \n\ """\n\ Liblouis test harness for the '+os.path.basename(sys.argv[2])+' table\n\ Please see the liblouis documentationfor more information.\n\ """\n\ \n\ import sys\n\ import louis\n\ \n\ table = \''+os.path.basename(sys.argv[2])+'\'\n\ \n\ tests = [\n' return header def generate_content(lines): content='' harness_list=lines.split('\n') for item in harness_list: item=item.replace('\n', '') item=item.decode('utf-8') if item !='': content=content+' {\n' content=content+' \'txt\': u\''+item+'\', \n' content=content+' \'brl\': u\''+louis.translateString([sys.argv[2]], item, None, 0)+'\', \n' content=content+' },\n' content=content+']' return content #Main program print len(sys.argv) if len(sys.argv)!=4: print 'Usage: '+sys.argv[0]+' test text containing file Liblouis table new test harness file' sys.exit() if not os.path.exists(sys.argv[1]): print 'Error: The '+sys.argv[1]+' file doesn\'t exist.' sys.exit() if not os.path.exists(sys.argv[2]): print 'Error: The '+sys.argv[2]+' file doesn\'t exist.' sys.exit() f=open(sys.argv[1], 'r') lines=f.read() f.close() g=open(sys.argv[3], 'w') header=generate_header() content=generate_content(lines) g.write(header) g.write(content.encode('utf-8')) g.close() print 'Test harness file generation are complete.\n Please look the '+sys.argv[3]+' file, and do the corrections if this is need'