4
#===============================================================================
6
#===============================================================================
9
#4.0.264 - version update
17
logger = logging.getLogger('.'.join([os.path.splitext(os.path.basename(sys.argv[0]))[0],'manager','filtergraph',__name__]))
27
'executable': '4,perl',
36
'universal_newlines': False,
40
'script': '3,atoken.pl',
46
script = '3,atoken.pl'
51
def open(self,parent,cfg):
52
self.args = dict(cfg['args'])
53
self.kw = dict(cfg['kw'])
55
self.script = self.p.decodepath('%s,%s'%(__name__.split(',')[1],cfg['script']),True)
57
self.errors.append([__name__,'missing',cfg['script']])
58
logger.error('%s\t%s',*self.errors[-1][1:])
59
self.args[0] = self.script
60
self.kw['cwd'] = os.path.dirname(self.script)
63
# convert args dict to args list
64
self.args = [str(self.args[k]) for k in sorted(self.args.keys())]
65
if 'executable' in cfg['kw'] and cfg['kw']['executable']:
66
self.kw['executable'] = self.p.decodepath('%s,%s'%(__name__.split(',')[1],cfg['kw']['executable']),True)
67
if not self.kw['executable']:
68
self.errors.append([__name__,'missing',cfg['kw']['executable']])
69
logger.error('%s\t%s',*self.errors[-1][1:])
70
self.args.insert(0,cfg['exeoptions'] if cfg['exeoptions'] else '')
72
self.kw['executable'] = None
73
self.kw['stdin'] = subprocess.PIPE if cfg['kw']['stdin'] == 'PIPE' else cfg['kw']['stdin']
74
self.kw['stdout'] = subprocess.PIPE if cfg['kw']['stdout'] == 'PIPE' else cfg['kw']['stdout']
75
self.kw['stderr'] = subprocess.PIPE if cfg['kw']['stderr'] == 'PIPE' else cfg['kw']['stderr']
76
self.encoding = 'utf8' if 'utf8' in cfg['encoding'].lower().replace('-','') else cfg['encoding']
79
self.subproc = subprocess.Popen(self.args,**self.kw)
81
raise RuntimeError('failed \"[%s]\" \"%s %s\"'%(__name__,self.kw['executable'],' '.join(self.args)))
85
for i,line in enumerate(self.p.cfoutput[k]['tempbuff']):
86
self.subproc.stdin.write('%s\n'%(line.strip().encode(self.encoding)))
87
self.p.cfoutput[k]['tempbuff'][i] = self.subproc.stdout.readline().rstrip().decode(self.encoding)
96
'''Command prompt help.'''
97
return "\n%s\n\tUsage:\n\tfrom %s import filter\n"%(
98
os.path.basename(sys.argv[0]),
99
os.path.splitext(os.path.basename(sys.argv[0]))[0]
102
licensetxt=u'''CorpusFiltergraph™ v4.0
103
Copyright © 2010-2012 Precision Translation Tools Co., Ltd.
105
This program is free software: you can redistribute it and/or modify
106
it under the terms of the GNU Lesser General Public License as published by
107
the Free Software Foundation, either version 3 of the License, or
108
(at your option) any later version.
110
This program is distributed in the hope that it will be useful,
111
but WITHOUT ANY WARRANTY; without even the implied warranty of
112
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113
GNU Lesser General Public License for more details.
115
You should have received a copy of the GNU Lesser General Public License
116
along with this program. If not, see http://www.gnu.org/licenses/.
118
For more information, please contact Precision Translation Tools Co., Ltd.
119
at: http://www.precisiontranslationtools.com'''
121
if __name__ == "__main__":
124
sys.stdout.write(usage().encode('utf8')+'\n')