Browse Source

Attempt to fix %(here)s in included files.

Alex Eftimie 10 years ago
parent
commit
abfbcd6c13

+ 15 - 0
supervisor/options.py

@@ -567,6 +567,7 @@ class ServerOptions(Options):
         expansions = {'here':self.here}
         expansions.update(self.environ_expansions)
         if parser.has_section('include'):
+            parser.expand_here(self.here)
             if not parser.has_option('include', 'files'):
                 raise ValueError(".ini file has [include] section, but no "
                 "files setting")
@@ -591,6 +592,10 @@ class ServerOptions(Options):
                         parser.read(filename)
                     except ConfigParser.ParsingError as why:
                         raise ValueError(str(why))
+                    else:
+                        parser.expand_here(
+                            os.path.abspath(os.path.dirname(filename))
+                        )
 
         sections = parser.sections()
         if not 'supervisord' in sections:
@@ -1715,6 +1720,16 @@ class UnhosedConfigParser(ConfigParser.RawConfigParser):
                 self.section_to_file[section] = filename
         return ok_filenames
 
+    def expand_here(self, here):
+        if here is None:
+            return
+        HERE_FORMAT = '%(here)s'
+        for section in self.sections():
+            for key, value in self.items(section):
+                if HERE_FORMAT in value:
+                    value = value.replace(HERE_FORMAT, here)
+                    self.set(section, key, value)
+
 
 class Config(object):
     def __ne__(self, other):

+ 2 - 0
supervisor/tests/fixtures/example/included.conf

@@ -0,0 +1,2 @@
+[supervisord]
+childlogdir = %(here)s

+ 5 - 0
supervisor/tests/fixtures/include.conf

@@ -0,0 +1,5 @@
+[include]
+files = ./example/included.conf
+
+[supervisord]
+logfile = %(here)s

+ 13 - 0
supervisor/tests/test_options.py

@@ -2586,6 +2586,19 @@ class ServerOptionsTests(unittest.TestCase):
         instance.poller.before_daemonize.assert_called_once_with()
         instance.poller.after_daemonize.assert_called_once_with()
 
+    def test_include_here(self):
+        conf = os.path.join(
+            os.path.abspath(os.path.dirname(__file__)), 'fixtures',
+            'include.conf')
+        root_here = os.path.dirname(conf)
+        include_here = os.path.join(root_here, 'example')
+        parser = self._makeOne()
+        parser.configfile = conf
+        parser.process_config_file(True)
+        section = parser.configroot.supervisord
+        self.assertEqual(section.logfile, root_here)
+        self.assertEqual(section.childlogdir, include_here)
+
 class TestProcessConfig(unittest.TestCase):
     def _getTargetClass(self):
         from supervisor.options import ProcessConfig