Show
Ignore:
Timestamp:
03/11/05 17:41:31 (19 years ago)
Author:
jerome
Message:

Added configuration file parser

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • tea4cups/trunk/cupsoftee

    r571 r573  
    5959            self.config = ConfigParser.ConfigParser() 
    6060            self.config.read([self.conffile]) 
    61             self.debug = self.isTrue(getGlobalOption("debug", ignore=1)) 
     61            self.debug = self.isTrue(self.getGlobalOption("debug", ignore=1)) 
    6262        else :     
    6363            self.config = FakeConfig() 
     
    9292                raise ConfigError, "Option %s not found in section [%s] of %s" % (option, sectionname, self.conffile) 
    9393                 
    94     def getSectionNames(self) :     
    95         """Returns the list of sections, i.e. all sections names minus 'global'.""" 
    96         return [pname for pname in self.config.sections() if pname != "global"] 
     94    def enumTeeBranches(self, sectionname) : 
     95        """Returns the list of branches for a particular section's Tee.""" 
     96        try : 
     97            globalbranches = [ (k, v) for (k, v) in self.config.items("global") if k.startswith("tee_") ] 
     98        except ConfigParser.NoSectionError, msg :     
     99            self.printInfo("Invalid configuration file : %s" % msg, "error") 
     100            globalbranches = [] 
     101        try : 
     102            sectionbranches = [ (k, v) for (k, v) in self.config.items(sectionname) if k.startswith("tee_") ] 
     103        except ConfigParser.NoSectionError, msg :     
     104            self.printInfo("Invalid configuration file : %s" % msg, "error") 
     105            sectionbranches = [] 
     106        branches = {} 
     107        for (k, v) in globalbranches : 
     108            value = v.strip() 
     109            if value : 
     110                branches[k] = value 
     111        for (k, v) in sectionbranches :     
     112            value = v.strip() 
     113            if value : 
     114                branches[k] = value # overwrite any global option or set a new value 
     115            else :     
     116                del branches[k] # empty value disables a global option 
     117        return branches 
    97118         
    98119    def discoverOtherBackends(self) :