Ignore:
Timestamp:
09/14/12 14:45:50 (9 years ago)
Author:
ramonb
Message:

jobmond.py:

  • added lots of configparsing debug prints
  • fix to comment parsing when /* and */ on same line
  • ignore /* for lines starting with include: can be wildcard
  • fix to section { and } parsing: only close section when {}count hits 0
  • fix to include file parsing: should be string not list
  • include line should be split, not strip
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/jobmond/jobmond.py

    r666 r667  
    9191    return loadConfig( config_filename )
    9292
    93 # Fixme:  This doesn't DTRT with commented-out bits of the file.  E.g.
    94 # it picked up a commented-out `mcast_join' and tried to use a
    95 # multicast channel when it shouldn't have done.
    9693class GangliaConfigParser:
    9794
     
    140137    def getVal( self, section, valname ):
    141138
     139        debug_msg( 10, "Parsing: '" + self.config_file + "' - searching for section: " + section + " value: " + valname )
     140
    142141        cfg_fp      = open( self.config_file )
    143142        cfg_lines   = cfg_fp.readlines()
     
    146145        section_start = False
    147146        section_found = False
     147        include_start = False
    148148        value         = None
    149149        comment_start = False
    150150
     151        acc_count     = 0
     152
    151153        for line in cfg_lines:
    152154
    153155            line = line.strip()
     156            debug_msg( 10, "line org: " + line )
    154157            line = self.removeComments( line )
    155 
    156             if line.find( '/*' ) != -1:
    157 
    158                 line = line[:line.find('/*')]
    159                 comment_start = True
    160 
    161             if line.find( '*/' ) != -1:
    162 
    163                 line = line[line.find('*/'):]
     158            debug_msg( 10, "line remove comments: " + line )
     159
     160            if line.find( '/*' ) != -1 and line.find( 'include', 0, 7 ):
     161
     162                debug_msg( 10, "line comment start */: " + line )
     163
     164                if line.find( '*/' ) != -1:
     165
     166                    begin_line = line[:line.find('/*')]
     167                    rest_line = line[(line.find('*/')+2):]
     168
     169                    line = begin_line + rest_line
     170
     171                    debug_msg( 10, "line comment end */: " + line )
     172
     173                else:
     174
     175                    line = line[:line.find('/*')]
     176                    comment_start = True
     177
     178                    debug_msg( 10, "line find /*: " + line )
     179
     180                debug_msg( 10, "line find /*: " + line )
     181
     182            if line.find( '*/' ) != -1 and comment_start:
     183
     184                line = line[(line.find('*/')+2):]
    164185                comment_start = False
     186                debug_msg( 10, "line comment end*/: " + line )
    165187
    166188            if comment_start:
    167189
     190                debug_msg( 10, "line ignoring comment: " + line )
    168191                continue
    169192
    170193            if line.find( 'include' ) != -1:
    171194
    172                 line = line.removeHaakjes()
    173 
    174                 include_line  = line.strip(' ')[1:]
     195                debug_msg( 10, "line include: " + line )
     196                line = self.removeHaakjes( line )
     197                line = self.removeQuotes( line )
     198                debug_msg( 10, "line removeHaakjes: " + line )
     199
     200                include_line  = line.split(' ')[1]
     201
     202                debug_msg( 10, "line includes: " + str( include_line ) )
    175203
    176204                for include_file in glob( include_line ):
     205
     206                    debug_msg( 10, "include file found: '" + include_file + "'" )
    177207
    178208                    include_parser = GangliaConfigParser( include_file )
     
    184214                        #break ? FIXME value can be overriden by other includes: perhaps users problem
    185215
     216                        debug_msg( 10, "VALUE found: '" + value + "'" )
     217
    186218                    del include_parser
    187219
     
    190222                section_found   = True
    191223
     224                debug_msg( 10, "section start: '" + section + "'" )
     225
    192226            if line.find( '{' ) != -1 and section_found:
    193227
    194228                section_start   = True
     229                acc_count       = acc_count + 1
    195230
    196231            if line.find( '}' ) != -1 and section_found:
    197232
    198                 section_start   = False
    199                 section_found   = False
     233                acc_count       = acc_count - 1
     234
     235                if acc_count == 0:
     236
     237                    debug_msg( 10, "section closed: '" + section + "'" )
     238                    section_start   = False
     239                    section_found   = False
    200240
    201241            if line.find( valname ) != -1 and section_start:
    202242
    203243                value       = string.join( line.split( '=' )[1:], '' ).strip()
     244
     245        debug_msg( 10, "Parsing done: '" + self.config_file + "' " )
    204246
    205247        return value
Note: See TracChangeset for help on using the changeset viewer.