浏览代码

Allow an options instance to be passed to main(). Closes #111

Mike Naberezny 11 年之前
父节点
当前提交
049dbef428
共有 3 个文件被更改,包括 33 次插入2 次删除
  1. 4 0
      CHANGES.txt
  2. 3 2
      supervisor/supervisord.py
  3. 26 0
      supervisor/tests/test_supervisord.py

+ 4 - 0
CHANGES.txt

@@ -18,6 +18,10 @@
 - Removed ``setuptools`` from the ``requires`` list in ``setup.py`` because
   it caused installation issues on some systems.
 
+- The ``main()`` function of the ``supervisord`` module now allows an
+  ``options`` instance to be passed in.  This is consistent with the
+  ``main()`` function of ``supervisorctl``, which already allowed this.
+
 3.0 (2013-07-30)
 ----------------
 

+ 3 - 2
supervisor/supervisord.py

@@ -344,12 +344,13 @@ def profile(cmd, globals, locals, sort_order, callers):
 
 
 # Main program
-def main(args=None, test=False):
+def main(args=None, options=None, test=False):
     assert os.name == "posix", "This code makes Unix-specific assumptions"
     # if we hup, restart by making a new Supervisor()
     first = True
     while 1:
-        options = ServerOptions()
+        if options is None:
+            options = ServerOptions()
         options.realize(args, doc=__doc__)
         options.first = first
         options.test = test

+ 26 - 0
supervisor/tests/test_supervisord.py

@@ -35,6 +35,32 @@ class EntryPointTests(unittest.TestCase):
         output = new_stdout.getvalue()
         self.assertTrue(output.find('supervisord started') != 1, output)
 
+    def test_main_allows_injection_of_options_instance(self):
+        from supervisor.supervisord import main
+        from supervisor.options import ServerOptions
+        conf = os.path.join(
+            os.path.abspath(os.path.dirname(__file__)), 'fixtures',
+            'donothing.conf')
+        import StringIO
+        new_stdout = StringIO.StringIO()
+        old_stdout = sys.stdout
+
+        options = ServerOptions()
+        self.assertFalse(hasattr(options, "args"))
+
+        try:
+            tempdir = tempfile.mkdtemp()
+            log = os.path.join(tempdir, 'log')
+            pid = os.path.join(tempdir, 'pid')
+            sys.stdout = new_stdout
+            main(args=['-c', conf, '-l', log, '-j', pid, '-n'],
+                 options=options, test=True)
+        finally:
+            sys.stdout = old_stdout
+            shutil.rmtree(tempdir)
+
+        self.assertTrue(hasattr(options, "args"))
+
     if sys.version_info[:2] >= (2, 4):
         def test_main_profile(self):
             from supervisor.supervisord import main