4
#===============================================================================
6
#===============================================================================
9
#4.0.264 - version update
15
from fnmatch import fnmatch
16
from flock import flock
20
logger = logging.getLogger('.'.join([os.path.splitext(os.path.basename(sys.argv[0]))[0],'manager','filtergraph',__name__]))
43
def open(self,parent,cfg):
45
self.stage = cfg['stage']
47
self.errors.append([__name__,'missing','[%s] \"stage=<missing>\"'%(__name__.split(',')[-1])])
48
logger.error('%s\t%s',*self.errors[-1][1:])
50
self.roottype = cfg['roottype'].strip(',').split(',')[0]
51
self.p.roottype = cfg['roottype'].strip(',').split(',')[0]
53
self.errors.append([__name__,'missing','[%s] \"roottype=<missing>\"'%(__name__.split(',')[-1])])
54
logger.error('%s\t%s',*self.errors[-1][1:])
55
self.encoding = 'utf8' if 'utf8' in cfg['encoding'].lower().replace('-','') else cfg['encoding']
56
self.rendertypes = os.extsep+cfg['rendertypes'].lstrip(os.extsep)
57
self.rootfolder = self.normalizeroot(cfg['rootfolder'])
58
self.safemode = cfg['safemode']
60
def run(self,fileobj,k=None,mode=None):
61
'''saves buffer to file'''
64
def flush(self,fileobj,k=None):
65
'''move temp output files to server'''
66
for k in fileobj.keys():
72
def getroot(self,rootfolder):
73
'''Splits rootfolder to file system and rootfolder'''
74
folder = os.path.abspath(os.path.expanduser(rootfolder.rstrip().replace('/',os.sep).replace('\\',os.sep)))
75
if fnmatch(folder,'?:*'):
76
# DOS drive letter : folder
77
fss, folder = folder.split(':')
79
elif fnmatch(folder,'*:*'):
80
# ssh hostname : folder
81
fss, folder = folder.split(':')
83
elif fnmatch(folder,'\\\\*\\*'):
84
# MS Windows UNC \ folder
85
fss = '\\\\'+folder.lstrip(os.sep).split(os.sep)[0]
86
folder = folder.replace(fss,'')
90
folder = os.path.normpath(folder)
91
if folder == '.': folder = '*'
92
folder = folder.lstrip('\\/')
93
return [unicode(fss), unicode(folder)]
95
def normalizeroot(self,rootfolder):
96
return rootfolder.replace('\\',os.sep).replace('/',os.sep)
99
'''Command prompt help.'''
100
return "\n%s\n\tUsage:\n\tfrom %s import reader\n"%(
101
os.path.basename(sys.argv[0]),
102
os.path.splitext(os.path.basename(sys.argv[0]))[0]
105
licensetxt=u'''CorpusFiltergraph™ v4.0
106
Copyright © 2010-2012 Precision Translation Tools Co., Ltd.
108
This program is free software: you can redistribute it and/or modify
109
it under the terms of the GNU Lesser General Public License as published by
110
the Free Software Foundation, either version 3 of the License, or
111
(at your option) any later version.
113
This program is distributed in the hope that it will be useful,
114
but WITHOUT ANY WARRANTY; without even the implied warranty of
115
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
116
GNU Lesser General Public License for more details.
118
You should have received a copy of the GNU Lesser General Public License
119
along with this program. If not, see http://www.gnu.org/licenses/.
121
For more information, please contact Precision Translation Tools Co., Ltd.
122
at: http://www.precisiontranslationtools.com'''
124
if __name__ == "__main__":
127
sys.stdout.write(usage().encode('utf8')+'\n')