Hi,

I have been considering using supervisord for our local dev
environments here instead of a custom rolled solution that we've had
in place.  The thing that is holding me back right now is that we have
custom ports for all the processes we launch because we make it so we
can have multiple instances of the environments being run.

It seems like there's no way to easily have "dynamic" configuration
files right now, however I feel it would not be too hard to add
support.

One proposal I have is to allow reference to environment variables by
letting expansions like %($ENV_VAR)s be valid.

It's a fairly trivial change to make (hacked together patch attached).

The other thing that may be cool is allowing for preprocessing of
config files with a templating langauge.

As an aside, I kinda wish supervisor was on github.  Would make it
much easier to contribute.

Thanks,
Mike



----

diff --git a/src/supervisor/datatypes.py b/src/supervisor/datatypes.py
index 26bfe68..019ceb9 100644
--- a/src/supervisor/datatypes.py
+++ b/src/supervisor/datatypes.py
@@ -347,7 +347,8 @@ def gid_for_uid(uid):

 def existing_directory(v):
     import os
-    nv = v % {'here':here}
+    from supervisor.options import expand
+    nv = expand(v, {'here':here}, 'directory')
     nv = os.path.expanduser(nv)
     if os.path.isdir(nv):
         return nv
@@ -355,7 +356,8 @@ def existing_directory(v):

 def existing_dirpath(v):
     import os
-    nv = v % {'here':here}
+    from supervisor.options import expand
+    nv = expand(v, {'here':here}, 'dirpath')
     nv = os.path.expanduser(nv)
     dir = os.path.dirname(nv)
     if not dir:
diff --git a/src/supervisor/options.py b/src/supervisor/options.py
index 9c7e97b..63bec77 100644
--- a/src/supervisor/options.py
+++ b/src/supervisor/options.py
@@ -67,6 +67,10 @@ mydir = os.path.abspath(os.path.dirname(__file__))
 version_txt = os.path.join(mydir, 'version.txt')
 VERSION = open(version_txt).read().strip()

+eviron_expansions = dict(("$%s" % envvar, value)
+                         for envvar, value
+                         in os.environ.items())
+
 def normalize_path(v):
     return os.path.normpath(os.path.abspath(os.path.expanduser(v)))

@@ -1851,7 +1855,7 @@ def _init_signames():

 def expand(s, expansions, name):
     try:
-        return s % expansions
+        return s % dict(eviron_expansions, **expansions)
     except KeyError:
         raise ValueError(
             'Format string %r for %r contains names which cannot be '
_______________________________________________
Supervisor-users mailing list
[email protected]
http://lists.supervisord.org/mailman/listinfo/supervisor-users

Reply via email to