Changeset 573

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

Added configuration file parser

Location:
tea4cups/trunk
Files:
2 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) :     
  • tea4cups/trunk/cupsoftee.conf

    r571 r573  
    2020[global] 
    2121debug : yes 
     22#tee_0 : blah 
     23#tee_1 : blah 
     24#tee_2 : blah 
    2225 
    2326# Sample section for print queue HP2100 
    2427# Uncomment and adapt to your needs. 
    2528# 
    26 #[HP2100] 
     29[HP2100] 
     30#blah:  
     31#tee_2 : zut    # overwrites the [global] value of tee_2 
     32#tee_4 : gniak 
    2733# 
    2834#