Browse Source

Remove environ_expansions()

Mike Naberezny 10 năm trước cách đây
mục cha
commit
cca4a5ec3c
2 tập tin đã thay đổi với 12 bổ sung21 xóa
  1. 8 15
      supervisor/options.py
  2. 4 6
      supervisor/tests/test_options.py

+ 8 - 15
supervisor/options.py

@@ -103,6 +103,10 @@ class Options:
                        '/etc/supervisord.conf']
         self.searchpaths = searchpaths
 
+        self.environ_expansions = {}
+        for k, v in os.environ.items():
+            self.environ_expansions['ENV_%s' % k] = v
+
     def default_configfile(self):
         """Return the name of the found config file or print usage/exit."""
         config = None
@@ -538,14 +542,14 @@ class ServerOptions(Options):
             except (IOError, OSError):
                 raise ValueError("could not read config file %s" % fp)
         parser = UnhosedConfigParser()
-        parser.expansions = environ_expansions()
+        parser.expansions = self.environ_expansions
         try:
             parser.readfp(fp)
         except ConfigParser.ParsingError, why:
             raise ValueError(str(why))
 
         expansions = {'here':self.here}
-        expansions.update(environ_expansions())
+        expansions.update(self.environ_expansions)
         if parser.has_section('include'):
             if not parser.has_option('include', 'files'):
                 raise ValueError(".ini file has [include] section, but no "
@@ -889,7 +893,7 @@ class ServerOptions(Options):
         for process_num in range(numprocs_start, numprocs + numprocs_start):
             expansions = common_expansions
             expansions.update({'process_num': process_num})
-            expansions.update(environ_expansions())
+            expansions.update(self.environ_expansions)
 
             environment = dict_of_key_value_pairs(
                 expand(environment_str, expansions, 'environment'))
@@ -1579,7 +1583,7 @@ class ClientOptions(Options):
             except (IOError, OSError):
                 raise ValueError("could not read config file %s" % fp)
         config = UnhosedConfigParser()
-        config.expansions = environ_expansions()
+        config.expansions = self.environ_expansions
         config.mysection = 'supervisorctl'
         config.readfp(fp)
         sections = config.sections()
@@ -2061,17 +2065,6 @@ def expand(s, expansions, name):
             (s, name, str(ex))
         )
 
-def environ_expansions():
-    """Return dict of environment variables, suitable for use in string
-    expansions.
-
-    Every environment variable is prefixed by 'ENV_'.
-    """
-    x = {}
-    for key, value in os.environ.items():
-        x['ENV_%s' % key] = value
-    return x
-
 def make_namespec(group_name, process_name):
     # we want to refer to the process by its "short name" (a process named
     # process1 in the group process1 has a name "process1").  This is for

+ 4 - 6
supervisor/tests/test_options.py

@@ -1487,12 +1487,11 @@ class ServerOptionsTests(unittest.TestCase):
 
         """)
         from supervisor.options import UnhosedConfigParser
-        from supervisor.options import environ_expansions
         from supervisor.dispatchers import default_handler
+        instance = self._makeOne()
         config = UnhosedConfigParser()
-        config.expansions = environ_expansions()
+        config.expansions = instance.environ_expansions
         config.read_string(text)
-        instance = self._makeOne()
         gconfigs = instance.process_groups_from_parser(config)
         self.assertEqual(len(gconfigs), 2)
 
@@ -1713,11 +1712,10 @@ class ServerOptionsTests(unittest.TestCase):
         priority = %(ENV_FOO_PRIORITY)s
         """)
         from supervisor.options import UnhosedConfigParser
-        from supervisor.options import environ_expansions
+        instance = self._makeOne()
         config = UnhosedConfigParser()
-        config.expansions = environ_expansions()
+        config.expansions = instance.environ_expansions
         config.read_string(text)
-        instance = self._makeOne()
 
         #Patch pwd and grp module functions to give us sentinel
         #uid/gid values so that the test does not depend on