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__]))
24
'args2': '3,morph.en',
29
'executable': '4,perl',
38
'universal_newlines': False,
42
'script': '3,english_stemmer.pl',
48
script = '3,english_stemmer.pl'
53
def open(self,parent,cfg):
54
self.args = dict(cfg['args'])
55
self.kw = dict(cfg['kw'])
57
self.script = self.p.decodepath('%s,%s'%(__name__.split(',')[1],cfg['script']),True)
59
self.errors.append([__name__,'missing',cfg['script']])
60
logger.error('%s\t%s',*self.errors[-1][1:])
61
self.args[0] = self.script
62
self.kw['cwd'] = os.path.dirname(self.script)
65
# convert args dict to args list
66
self.args[2] = self.p.decodepath('%s,%s'%(__name__.split(',')[1],self.args[2]),True)
68
self.errors.append([__name__,'missing',cfg['args'][2]])
69
logger.error('%s\t%s',*self.errors[-1][1:])
70
self.args = [str(self.args[k]) for k in sorted(self.args.keys())]
71
if 'executable' in cfg['kw'] and cfg['kw']['executable']:
72
self.kw['executable'] = self.p.decodepath('%s,%s'%(__name__.split(',')[1],cfg['kw']['executable']),True)
73
if not self.kw['executable']:
74
self.errors.append([__name__,'missing',cfg['kw']['executable']])
75
logger.error('%s\t%s',*self.errors[-1][1:])
76
self.args.insert(0,cfg['exeoptions'] if cfg['exeoptions'] else '')
78
self.kw['executable'] = None
79
self.kw['stdin'] = subprocess.PIPE if cfg['kw']['stdin'] == 'PIPE' else cfg['kw']['stdin']
80
self.kw['stdout'] = subprocess.PIPE if cfg['kw']['stdout'] == 'PIPE' else cfg['kw']['stdout']
81
self.kw['stderr'] = subprocess.PIPE if cfg['kw']['stderr'] == 'PIPE' else cfg['kw']['stderr']
82
self.encoding = 'utf8' if 'utf8' in cfg['encoding'].lower().replace('-','') else cfg['encoding']
85
self.subproc = subprocess.Popen(self.args,**self.kw)
87
raise RuntimeError('failed \"[%s]\" \"%s %s\"'%(__name__,self.kw['executable'],' '.join(self.args)))
91
for i,line in enumerate(self.p.cfoutput[k]['tempbuff']):
92
self.subproc.stdin.write('%s\n'%(line.strip().encode(self.encoding)))
93
self.p.cfoutput[k]['tempbuff'][i] = self.subproc.stdout.readline().rstrip().decode(self.encoding)
102
'''Command prompt help.'''
103
return "\n%s\n\tUsage:\n\tfrom %s import filter\n"%(
104
os.path.basename(sys.argv[0]),
105
os.path.splitext(os.path.basename(sys.argv[0]))[0]
108
licensetxt=u'''CorpusFiltergraph™ v4.0
109
Copyright © 2010-2012 Precision Translation Tools Co., Ltd.
111
This program is free software: you can redistribute it and/or modify
112
it under the terms of the GNU Lesser General Public License as published by
113
the Free Software Foundation, either version 3 of the License, or
114
(at your option) any later version.
116
This program is distributed in the hope that it will be useful,
117
but WITHOUT ANY WARRANTY; without even the implied warranty of
118
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
119
GNU Lesser General Public License for more details.
121
You should have received a copy of the GNU Lesser General Public License
122
along with this program. If not, see http://www.gnu.org/licenses/.
124
For more information, please contact Precision Translation Tools Co., Ltd.
125
at: http://www.precisiontranslationtools.com'''
127
if __name__ == "__main__":
130
sys.stdout.write(usage().encode('utf8')+'\n')