~jtv/corpusfiltergraph/cross-python

« back to all changes in this revision

Viewing changes to trunk/lib/corpusfg/plugins/writer-null.py

  • Committer: tahoar
  • Date: 2012-05-02 15:46:23 UTC
  • Revision ID: svn-v4:bc069b21-dff4-4e29-a776-06a4e04bad4e::266
new layout. need to update code to use the new layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# -*- coding: utf8 -*-
 
3
 
 
4
#===============================================================================
 
5
# Author: Tom Hoar
 
6
#===============================================================================
 
7
 
 
8
#version:
 
9
#4.0.264 - version update
 
10
 
 
11
import sys
 
12
import os
 
13
import shutil
 
14
import codecs
 
15
from fnmatch import fnmatch
 
16
from flock import flock
 
17
import logging
 
18
import common as cf
 
19
 
 
20
logger = logging.getLogger('.'.join([os.path.splitext(os.path.basename(sys.argv[0]))[0],'manager','filtergraph',__name__]))
 
21
 
 
22
class writer(object):
 
23
 
 
24
        cfg = {
 
25
                'encoding': 'utf8',
 
26
                'rendertypes': '.*',
 
27
                'rootfolder': '',
 
28
                'roottype': '',
 
29
                'safemode': False,
 
30
                'stage' : None,
 
31
                'version': '4.0.264',
 
32
                }
 
33
        encoding = 'utf8'
 
34
        rendertypes = '.*'
 
35
        rootfolder = ''
 
36
        roottype = ''
 
37
        safemode = False
 
38
        stage = None
 
39
        isopen = False
 
40
        p = object
 
41
        errors = []
 
42
 
 
43
        def open(self,parent,cfg):
 
44
                if cfg['stage']:
 
45
                        self.stage = cfg['stage']
 
46
                else:
 
47
                        self.errors.append([__name__,'missing','[%s] \"stage=<missing>\"'%(__name__.split(',')[-1])])
 
48
                        logger.error('%s\t%s',*self.errors[-1][1:])
 
49
                if cfg['roottype']:
 
50
                        self.roottype = cfg['roottype'].strip(',').split(',')[0]
 
51
                        self.p.roottype = cfg['roottype'].strip(',').split(',')[0]
 
52
                else:
 
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']
 
59
 
 
60
        def run(self,fileobj,k=None,mode=None):
 
61
                '''saves buffer to file'''
 
62
                return
 
63
 
 
64
        def flush(self,fileobj,k=None):
 
65
                '''move temp output files to server'''
 
66
                for k in fileobj.keys():
 
67
                        del(fileobj[k])
 
68
 
 
69
        def close(self):
 
70
                return
 
71
 
 
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(':')
 
78
                        fss = fss + ':'
 
79
                elif fnmatch(folder,'*:*'):
 
80
                        # ssh hostname : folder
 
81
                        fss, folder = folder.split(':')
 
82
                        fss = fss + ':'
 
83
                elif fnmatch(folder,'\\\\*\\*'):
 
84
                        # MS Windows UNC \ folder
 
85
                        fss = '\\\\'+folder.lstrip(os.sep).split(os.sep)[0]
 
86
                        folder = folder.replace(fss,'')
 
87
                else:
 
88
                        # NFS mount / folder
 
89
                        fss = ''
 
90
                        folder = os.path.normpath(folder)
 
91
                        if folder == '.': folder = '*'
 
92
                folder = folder.lstrip('\\/')
 
93
                return [unicode(fss), unicode(folder)]
 
94
 
 
95
        def normalizeroot(self,rootfolder):
 
96
                return rootfolder.replace('\\',os.sep).replace('/',os.sep)
 
97
 
 
98
def usage():
 
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]
 
103
        )
 
104
 
 
105
licensetxt=u'''CorpusFiltergraph™ v4.0
 
106
Copyright © 2010-2012 Precision Translation Tools Co., Ltd.
 
107
 
 
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.
 
112
 
 
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.
 
117
 
 
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/.
 
120
 
 
121
For more information, please contact Precision Translation Tools Co., Ltd.
 
122
at: http://www.precisiontranslationtools.com'''
 
123
 
 
124
if __name__ == "__main__":
 
125
        import os
 
126
        import sys
 
127
        sys.stdout.write(usage().encode('utf8')+'\n')