Commits

Vince Spicer committed 580501a

Support combining multiple INI files with #!include

Scan the base INI matching "#!include filename"
if filename exists relative the to base INI then
parse it and parse the base INI last

EX: #!include logging.ini
#!include beaker.ini
#!include mail.ini

[app:myapp]
.....

  • Participants
  • Parent commits 9921ad7

Comments (0)

Files changed (1)

paste/deploy/loadwsgi.py

 
 class ConfigLoader(_Loader):
 
+    _include_re = re.compile(r"#!include\s+(.*?)\s*$")
+
     def __init__(self, filename):
         self.filename = filename = filename.strip()
         defaults = {
             }
         self.parser = NicerConfigParser(filename, defaults=defaults)
         self.parser.optionxform = str  # Don't lower-case keys
+
         with open(filename) as f:
+            config_files = []
+            for line in f:
+                match = self._include_re.search(line)
+                if match:
+                    config_files.append(match.groups()[0])
+            if config_files:
+                basedir = os.path.split(filename)[0]
+                for conf in config_files:
+                    path = os.path.join(basedir, conf)
+                    if os.path.exists(path):
+                        self.parser.read_file(open(path))
+            f.seek(0)
             self.parser.read_file(f)
 
     def update_defaults(self, new_defaults, overwrite=True):
     """ Loader that supports specifying functions inside modules, without
     using eggs at all. Configuration should be in the format:
         use = call:my.module.path:function_name
-        
+
     Dot notation is supported in both the module and function name, e.g.:
         use = call:my.module.path:object.method
     """