Browse Source

Add [include] functionality.

Chris McDonough 17 years ago
parent
commit
3a06a6684f
3 changed files with 31 additions and 0 deletions
  1. 5 0
      CHANGES.txt
  2. 18 0
      src/supervisor/options.py
  3. 8 0
      src/supervisor/skel/sample.conf

+ 5 - 0
CHANGES.txt

@@ -33,6 +33,11 @@ Next Release
     the first integer that 'numprocs' will begin to start from.
     the first integer that 'numprocs' will begin to start from.
     Contributed by Antonio Beamud Montero.
     Contributed by Antonio Beamud Montero.
 
 
+  - Added capability for '[include]' config section to config format.
+    This section must contain a single key "files", which must name a
+    space-separated list of file globs that will be included in
+    supervisor's configuration.  Contributed by Ian Bicking.
+
 3.0a3
 3.0a3
 
 
   - Supervisorctl now reports a better error message when the main
   - Supervisorctl now reports a better error message when the main

+ 18 - 0
src/supervisor/options.py

@@ -29,6 +29,7 @@ import resource
 import stat
 import stat
 import pkg_resources
 import pkg_resources
 import select
 import select
+import glob
 
 
 from fcntl import fcntl
 from fcntl import fcntl
 from fcntl import F_SETFL, F_GETFL
 from fcntl import F_SETFL, F_GETFL
@@ -472,6 +473,23 @@ class ServerOptions(Options):
         parser = UnhosedConfigParser()
         parser = UnhosedConfigParser()
         parser.readfp(fp)
         parser.readfp(fp)
 
 
+        if parser.has_section('include'):
+            if not parser.has_option('include', 'files'):
+                raise ValueError(".ini file has [include] section, but no "
+                "files setting")
+            files = parser.get('include', 'files')
+            files = files.split()
+            if hasattr(fp, 'name'):
+                base = os.path.dirname(os.path.abspath(fp.name))
+            else:
+                base = '.'
+            for pattern in files:
+                pattern = os.path.join(base, pattern)
+                for filename in glob.glob(pattern):
+                    self.parse_warnings.append(
+                        'Included extra file "%s" during parsing' % filename)
+                    parser.read(filename)
+
         sections = parser.sections()
         sections = parser.sections()
         if not 'supervisord' in sections:
         if not 'supervisord' in sections:
             raise ValueError, '.ini file does not include supervisord section'
             raise ValueError, '.ini file does not include supervisord section'

+ 8 - 0
src/supervisor/skel/sample.conf

@@ -114,3 +114,11 @@ serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
 ;programs=progname1,progname2  ; each refers to 'x' in [program:x] definitions
 ;programs=progname1,progname2  ; each refers to 'x' in [program:x] definitions
 ;priority=999                  ; the relative start priority (default 999)
 ;priority=999                  ; the relative start priority (default 999)
 
 
+; The [include] section can just contain the "files" setting.  This
+; setting can list multiple files (separated by whitespace or
+; newlines).  It can also contain wildcards.  The filenames are
+; interpreted as relative to this file.  Included files *cannot*
+; include files themselves.
+
+;[include]
+;files = relative/directory/*.ini