/[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.11 by tvon, Sun Nov 17 01:57:49 2002 UTC revision 1.12 by tvon, Sun Nov 17 03:26:20 2002 UTC
# Line 27  class Config(ConfigParser.ConfigParser): Line 27  class Config(ConfigParser.ConfigParser):
27      """An advanced ConfigParser module with our defaults auto-loaded      """An advanced ConfigParser module with our defaults auto-loaded
28      """      """
29    
     user_config = None  
     circus_home = None  
     module_path = None  
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/circus.cfg',
34          os.path.expanduser('~/.circus/circus.cfg')          os.path.expanduser('~/.circus/circus.cfg')
35          ]          ]
36    
37      config_defaults = {      config_defaults = {
38          "main" : {          "main" : {
39              "circus_home" : os.environ['CIRCUS_HOME'],              "circus_home" : '/usr/local/share/circus',
40              "module_path" : os.environ['CIRCUS_MODULES'],              "module_path" : '%(circus_home)s/modules',
41              },              },
42          "modules" : {          "modules" : {
43              "autoload" : ""              "autoload" : ""
# Line 60  class Config(ConfigParser.ConfigParser): Line 58  class Config(ConfigParser.ConfigParser):
58    
59          self.read(self.config_file_paths)          self.read(self.config_file_paths)
60                
61      def set_module_path(self, path = None):      def update_module_path(self, path = None):
62          """Add <path> to python's module path list after some error          """Add <path> to python's module path list after some error
63          checking.  If <path> is not given, then add the path(s) from          checking.  If <path> is not given, then add the path from
64          the config.          the config.
65          """          """
66            if path == None:
67                addpath = self.get('main', 'module_path')
68            
69          # no non-existant paths          # no non-existant paths
70          # XXX: Should raise an exception here, returning -1 is for kids :)          # XXX: Should raise an exception here, returning -1 is for kids :)
71          if not os.path.exists(path):          if not os.path.exists(addpath):
72              return -1              return -1
73    
74          # Clean it up in case its relative from circus_home          # Clean it up in case its relative from circus_home
75          path = os.path.abspath(path)          path = os.path.abspath(addpath)
76    
77          for p in sys.path:          for p in sys.path:
78              p = os.path.abspath(p)              p = os.path.abspath(p)
79              if path in (p, p + os.sep):              if addpath in (p, p + os.sep):
80                  return 0                  return 0
81                    
82          sys.path.append(path)          sys.path.append(addpath)
83    
84                    
85      def dump_config(self):      def dump_config(self):
86          for section in self.sections():          for section in self.sections():
87              print section              sys.stderr.write(section + "\n")
88              for option in self.options(section):              for option in self.options(section):
89                  print " ", option, "=", self.get(section, option)                  sys.stderr.write("-- " + option + "=" +
90                        self.get(section, option) + "\n")
91    

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

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