6
|
1 from commons.core.parsing.FindRep import FindRep
|
|
2 from xml.sax import make_parser
|
|
3 from xml.sax.handler import feature_namespaces
|
|
4 import os
|
|
5
|
|
6
|
|
7 class MrepsToSet(object):
|
|
8
|
|
9 def __init__(self, mrepsInputFileName="", mrepsOuputFileName="", outputFileName=None, errorFilter=0):
|
|
10 self._mrepsInputFileName = mrepsInputFileName
|
|
11 self._mrepsOuputFileName = mrepsOuputFileName
|
|
12 self._outputFileName = outputFileName or "%s.Mreps.set" % mrepsOuputFileName
|
|
13 self._errorFilter = errorFilter
|
|
14
|
|
15 def run(self):
|
|
16 xmlParser = make_parser()
|
|
17 xmlParser.setFeature( feature_namespaces, 0 )
|
|
18 xmlParser.setContentHandler( FindRep( self._outputFileName, self._errorFilter, 0 ) )
|
|
19 xmlParser.parse( self._mrepsOuputFileName )
|
|
20
|
|
21 def clean( self ):
|
|
22 """
|
|
23 Remove the output file (xml) from Mreps to keep only the 'set' file.
|
|
24 """
|
|
25 if os.path.exists(self._mrepsOuputFileName):
|
|
26 os.remove(self._mrepsOuputFileName)
|
|
27
|
|
28
|
|
29
|
|
30
|
|
31 |