/[circus]/circus/circus/config.py
ViewVC logotype

Diff of /circus/circus/config.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by tvon, Sun Nov 17 04:22:16 2002 UTC revision 1.14 by tvon, Sat Nov 23 19:43:43 2002 UTC
# Line 21  __author__ = "Thomas von Schwerdtner <tv Line 21  __author__ = "Thomas von Schwerdtner <tv
21  __date__ = "Wed Nov 11 2002"  __date__ = "Wed Nov 11 2002"
22  __version__ = "$Revision$"  __version__ = "$Revision$"
23    
24  import ConfigParser, sys, os  import sys, os
25    
26  class Config(ConfigParser.ConfigParser):  class Config:
27      """An advanced ConfigParser module with our defaults auto-loaded      """An advanced ConfigParser module with our defaults auto-loaded
28      """      """
29    
30      # Think about these paths a little bit more, namely the order.      # Think about these paths a little bit more, namely the order.
31      # All are read in given order.      # All are read in given order.
32      config_file_paths = [      config_file_paths = [
33          '/etc/circus/circus.cfg',          '/etc/circus/config.py',
34          os.path.expanduser('~/.circus/circus.cfg')          os.path.expanduser('~/.circus/config.py')
35          ]          ]
36    
     config_defaults = {  
         "main" : {  
             "circus_home" : '/usr/local/share/circus',  
             "module_path" : '%(circus_home)s/modules',  
             },  
         "modules" : {  
             "autoload" : ""  
             }  
         }  
       
   
     def __init__(self):  
         """Setup some our default values.  ConfigParser's standard method  
         of setting defaults is ignored since it is inadequate for our needs"""  
   
         ConfigParser.ConfigParser.__init__(self)  
   
         for section in self.config_defaults:  
             self.add_section(section)  
             for key, value in self.config_defaults[section].items():  
                 self.set(section, key, value)  
37    
         self.read(self.config_file_paths)  
         
38      def update_module_path(self, path = None):      def update_module_path(self, path = None):
39          """Add <path> to python's module path list after some error          """Add <path> to python's module path list after some error
40          checking.  If <path> is not given, then add the path from          checking.  If <path> is not given, then add the path from
# Line 65  class Config(ConfigParser.ConfigParser): Line 42  class Config(ConfigParser.ConfigParser):
42          """          """
43                    
44          if path == None:          if path == None:
45              addpath = self.get('main', 'module_path')              addpath = self.module_path
46                    
47          # pass over non-existant paths          # pass over non-existant paths
48          if not os.path.exists(addpath):          if not os.path.exists(addpath):
# Line 82  class Config(ConfigParser.ConfigParser): Line 59  class Config(ConfigParser.ConfigParser):
59                    
60          sys.path.append(addpath)          sys.path.append(addpath)
61    
           
     def dump_config(self):  
         for section in self.sections():  
             sys.stderr.write(section + "\n")  
             for option in self.options(section):  
                 sys.stderr.write("-- " + option + "=" +  
                     self.get(section, option) + "\n")  
   

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26