Commit bfc66011 authored by rabauti's avatar rabauti
Browse files

sh wrap

parent b5ea55d3
This diff is collapsed.
#!/bin/sh
ELEMENT_ID=$1
SENTENCE=$2
echo "$SENTENCE"
\ No newline at end of file
#/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import getopt
import subprocess
#lähtefail
infile = '/Users/rabauti/repos/tu/ut_veakorpus/korpus_tsv/korpus.tsv'
sh_script = '/Users/rabauti/repos/tu/ut_veakorpus/korpus_sh/sh/sh.sh'
outfile = '/Users/rabauti/repos/tu/ut_veakorpus/korpus_sh/korpus.a'
###############################
# commandline parameters
###############################
def usage():
eprint('Kasutamise näide: ')
eprint('python wrapSH.py --tsv_file=../korpus_tsv/korpus.tsv --sh_script=./sh/cg.sh --result_file=./korpus.cg ')
def getOptions():
options = {}
try:
opts, args = getopt.getopt(sys.argv[1:], "hvt:s:r:", ["help", "verbose", "tsv_file=", "sh_script=", "result_file="])
#print (opts)
except getopt.GetoptError as err:
# print help information and exit:
eprint ("Option is not recognized")
usage()
sys.exit(2)
output = None
verbose = False
for o, a in opts:
if o == "-v":
verbose = True
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-t", "--tsv_file") :
options['tsv_file'] = a
elif o in ("-r", "--result_file"):
options['result_file'] = a
elif o in ("-s", "--sh_script"):
options['sh_script'] = a
else:
assert False, ("unhandled option %s"%o)
return options
options = getOptions()
if not "tsv_file" in options or not len(options['tsv_file']):
options['tsv_file'] = '../korpus_tsv/korpus.tsv'
if not "result_file" in options or not len(options['result_file']):
sys.stderr.write('Tulemusfaili nimi on määramata (--result_file=)\n')
sys.stderr.write('Tulemus salvestatakse faili ./korpus.RESULT \n')
options['result_file'] = './korpus.RESULT'
if not "sh_script" in options or not len(options['sh_script']):
sys.stderr.write('Korpuse teisenduse sh skript on on määramata (--sh_script=)\n')
exit()
try:
tsv_file = open(options['tsv_file'])
except:
sys.stderr.write('\tEi õnnestunud avada lugemiseks faili %s \n' %options['tsv_file'])
exit()
outfile = open(options['result_file'], "w")
bash_command_template = ' %s "%%s" "%%s" >> %s' % (options['sh_script'], options['result_file'])
#TODO exception püüdmine
for row in tsv_file.read().split('\n'):
arr = row.split('\t')
if len(arr)>1:
if len(arr[0]) and len(arr[1]):
print ([options['sh_script'], '"%s"'%arr[0] , '"%s"'%arr[1]] )
subprocess.run([options['sh_script'], '"%s"'%arr[0] , '"%s"'%arr[1]], stdout=outfile)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment