Back to index

salome-kernel  6.5.0
Public Member Functions | Public Attributes
launchConfigureParser.xml_parser Class Reference

List of all members.

Public Member Functions

def __init__
def boolValue
def intValue
def startElement
def endElement
def characters
def processingInstruction
def setDocumentLocator
def startDocument
def endDocument
def importFile

Public Attributes

 fileName
 importHistory
 space
 opts
 section
 current
 read

Detailed Description

Definition at line 236 of file launchConfigureParser.py.


Constructor & Destructor Documentation

def launchConfigureParser.xml_parser.__init__ (   self,
  fileName,
  _opts,
  _importHistory = [] 
)

Definition at line 237 of file launchConfigureParser.py.

00237 
00238     def __init__(self, fileName, _opts, _importHistory=[] ):
00239         if verbose(): print "Configure parser: processing %s ..." % fileName
00240         self.fileName = os.path.abspath(fileName)
00241         self.importHistory = _importHistory
00242         self.importHistory.append(self.fileName)
00243         self.space = []
00244         self.opts = _opts
00245         self.section = section_to_skip
00246         parser = xml.sax.make_parser()
00247         parser.setContentHandler(self)
00248         parser.parse(fileName)
00249         standalone, embedded = process_containers_params( self.opts.get( standalone_nam ),
00250                                                           self.opts.get( embedded_nam ) )
00251         if standalone is not None:
00252             self.opts[ standalone_nam ] = standalone
00253         if embedded is not None:
00254             self.opts[ embedded_nam ] = embedded
00255         pass


Member Function Documentation

def launchConfigureParser.xml_parser.boolValue (   self,
  str 
)

Definition at line 256 of file launchConfigureParser.py.

00256 
00257     def boolValue( self, str ):
00258         strloc = str
00259         if isinstance(strloc, types.UnicodeType):
00260             strloc = strloc.encode().strip()
00261         if isinstance(strloc, types.StringType):
00262             strlow = strloc.lower()
00263             if strlow in   ("1", "yes", "y", "on", "true", "ok"):
00264                 return True
00265             elif strlow in ("0", "no", "n", "off", "false", "cancel"):
00266                 return False
00267         return strloc
00268         pass

def launchConfigureParser.xml_parser.characters (   self,
  content 
)

Definition at line 336 of file launchConfigureParser.py.

00336 
00337     def characters(self, content):
00338         pass

Definition at line 349 of file launchConfigureParser.py.

00349 
00350     def endDocument(self):
00351         self.read = None
00352         pass
    
def launchConfigureParser.xml_parser.endElement (   self,
  name 
)

Definition at line 329 of file launchConfigureParser.py.

00329 
00330     def endElement(self, name):
00331         p = self.space.pop()
00332         self.current = None
00333         if self.section != section_to_skip and name == sec_tag:
00334             self.section = section_to_skip
00335         pass

def launchConfigureParser.xml_parser.importFile (   self,
  fname 
)

Definition at line 353 of file launchConfigureParser.py.

00353 
00354     def importFile(self, fname):
00355         # get absolute name
00356         if os.path.isabs (fname) :
00357             absfname = fname
00358         else:
00359             absfname = os.path.join(os.path.dirname(self.fileName), fname)
00360         
00361         # check existing and registry file
00362         for ext in ["", ".xml", ".XML"] :
00363             if os.path.exists(absfname + ext) :
00364                 absfname += ext
00365                 if absfname in self.importHistory :
00366                     if verbose(): print "Configure parser: Warning : file %s is already imported" % absfname
00367                     return # already imported
00368                 break
00369             pass
00370         else:
00371             if verbose(): print "Configure parser: Error : file %s does not exist" % absfname
00372             return
00373          
00374         # importing file
00375         try:
00376             # copy current options
00377             import copy
00378             opts = copy.deepcopy(self.opts)
00379             # import file
00380             imp = xml_parser(absfname, opts, self.importHistory)
00381             # merge results
00382             for key in imp.opts.keys():
00383                 if not self.opts.has_key(key):
00384                     self.opts[key] = imp.opts[key]
00385                     pass
00386                 pass
00387             pass
00388         except:
00389             if verbose(): print "Configure parser: Error : can not read configuration file %s" % absfname
00390         pass
00391       
00392 
00393 # -----------------------------------------------------------------------------

def launchConfigureParser.xml_parser.intValue (   self,
  str 
)

Definition at line 269 of file launchConfigureParser.py.

00269 
00270     def intValue( self, str ):
00271         strloc = str
00272         if isinstance(strloc, types.UnicodeType):
00273             strloc = strloc.encode().strip()
00274         if isinstance(strloc, types.StringType):
00275             strlow = strloc.lower()
00276             if strlow in   ("1", "yes", "y", "on", "true", "ok"):
00277                 return 1
00278             elif strlow in ("0", "no", "n", "off", "false", "cancel"):
00279                 return 0
00280             else:
00281                 return string.atoi(strloc)
00282         return strloc
00283         pass

def launchConfigureParser.xml_parser.processingInstruction (   self,
  target,
  data 
)

Definition at line 339 of file launchConfigureParser.py.

00339 
00340     def processingInstruction(self, target, data):
00341         pass

Definition at line 342 of file launchConfigureParser.py.

00342 
00343     def setDocumentLocator(self, locator):
00344         pass

Definition at line 345 of file launchConfigureParser.py.

00345 
00346     def startDocument(self):
00347         self.read = None
00348         pass

def launchConfigureParser.xml_parser.startElement (   self,
  name,
  attrs 
)

Definition at line 284 of file launchConfigureParser.py.

00284 
00285     def startElement(self, name, attrs):
00286         self.space.append(name)
00287         self.current = None
00288         
00289         # if we are importing file
00290         if self.space == [doc_tag, import_tag] and nam_att in attrs.getNames():
00291             self.importFile( attrs.getValue(nam_att) )
00292         
00293         # if we are analyzing "section" element and its "name" attribute is
00294         # either "launch" or module name -- set section_name
00295         if self.space == [doc_tag, sec_tag] and nam_att in attrs.getNames():
00296             section_name = attrs.getValue( nam_att )
00297             if section_name == lanch_nam:
00298                 self.section = section_name # launch section
00299             elif self.opts.has_key( modules_nam ) and \
00300                  section_name in self.opts[ modules_nam ]:
00301                 self.section = section_name # <module> section
00302             else:
00303                 self.section = section_to_skip # any other section
00304             pass
00305 
00306         # if we are analyzing "parameter" elements - children of either
00307         # "section launch" or "section "<module>"" element, then store them
00308         # in self.opts assiciative array (key = [<module>_ + ] value of "name" attribute)
00309         elif self.section != section_to_skip           and \
00310              self.space == [doc_tag, sec_tag, par_tag] and \
00311              nam_att in attrs.getNames()               and \
00312              val_att in attrs.getNames():
00313             nam = attrs.getValue( nam_att )
00314             val = attrs.getValue( val_att )
00315             if self.section == lanch_nam: # key for launch section
00316                 key = nam
00317             else:                         # key for <module> section
00318                 key = self.section + "_" + nam
00319             if nam in boolKeys:
00320                 self.opts[key] = self.boolValue( val )  # assign boolean value: 0 or 1
00321             elif nam in intKeys:
00322                 self.opts[key] = self.intValue( val )   # assign integer value
00323             elif nam in listKeys:
00324                 self.opts[key] = filter( lambda a: a.strip(), re.split( "[:;,]", val ) ) # assign list value: []
00325             else:
00326                 self.opts[key] = val
00327             pass
00328         pass


Member Data Documentation

Definition at line 286 of file launchConfigureParser.py.

Definition at line 239 of file launchConfigureParser.py.

Definition at line 240 of file launchConfigureParser.py.

Definition at line 243 of file launchConfigureParser.py.

Definition at line 346 of file launchConfigureParser.py.

Definition at line 244 of file launchConfigureParser.py.

Definition at line 242 of file launchConfigureParser.py.


The documentation for this class was generated from the following file: