Browse Source

Refactoring `Options.process_config()`

Moving a chunk of code out from `Options.process_config()` to
`Options.process_config_file()`. The latter function is now responsible
for only reading the config file while the former initializes config
data structure in general.

This commit makes it possible to skip the reading of an external
(on-disc) config file while still using default values etc.

The test `ControllerTests.test_real_controller_initialization(...)`
still fails because some default config values are not initialized
correctly. All other tests pass.
Jens Rantil 13 years ago
parent
commit
9017fd6fb7
1 changed files with 18 additions and 14 deletions
  1. 18 14
      supervisor/options.py

+ 18 - 14
supervisor/options.py

@@ -289,26 +289,15 @@ class Options:
         if self.configfile is None:
             self.configfile = self.default_configfile()
 
-        if self.configfile:
-            self.process_config()
+        self.process_config()
 
     def process_config(self, do_usage=True):
         """Process configuration data structure.
         
         This includes reading config file if necessary, setting defaults etc.
         """
-        if not hasattr(self.configfile, 'read'):
-            self.here = os.path.abspath(os.path.dirname(self.configfile))
-            set_here(self.here)
-        try:
-            self.read_config(self.configfile)
-        except ValueError, msg:
-            if do_usage:
-                # if this is not called from an RPC method, run usage and exit.
-                self.usage(str(msg))
-            else:
-                # if this is called from an RPC method, raise an error
-                raise ValueError(msg)
+        if self.configfile:
+            self.process_config_file(do_usage)
 
         # Copy config options to attributes of self.  This only fills
         # in options that aren't already set from the command line.
@@ -333,6 +322,21 @@ class Options:
             if getattr(self, name) is None:
                 self.usage(message)
 
+    def process_config_file(self, do_usage):
+        # Process config file
+        if not hasattr(self.configfile, 'read'):
+            self.here = os.path.abspath(os.path.dirname(self.configfile))
+            set_here(self.here)
+        try:
+            self.read_config(self.configfile)
+        except ValueError, msg:
+            if do_usage:
+                # if this is not called from an RPC method, run usage and exit.
+                self.usage(str(msg))
+            else:
+                # if this is called from an RPC method, raise an error
+                raise ValueError(msg)
+
     def get_plugins(self, parser, factory_key, section_prefix):
         factories = []