瀏覽代碼

Replaced helper method Controller.get_supervisor() with Controller.get_server_proxy().
The new method works the same but takes an optional namespace arg that defaults to
"supervisor". This makes it easier for plugin authors to get a proxy to other namespaces,
since many plugins will interact with custom rpcinterfaces..

Mike Naberezny 16 年之前
父節點
當前提交
98c97b0623
共有 2 個文件被更改,包括 28 次插入26 次删除
  1. 21 21
      src/supervisor/supervisorctl.py
  2. 7 5
      src/supervisor/tests/test_supervisorctl.py

+ 21 - 21
src/supervisor/supervisorctl.py

@@ -116,7 +116,7 @@ class Controller(cmd.Cmd):
                       'restart','start','stop','version','clear',
                       'fg','open','quit','remove','shutdown','status',
                       'tail','help']
-        self.info=self.get_supervisor().getAllProcessInfo()
+        self.info=self.get_server_proxy().getAllProcessInfo()
         cmd.Cmd.__init__(self, completekey, stdin, stdout)
         for name, factory, kwargs in self.options.plugin_factories:
             plugin = factory(self, **kwargs)
@@ -192,14 +192,14 @@ class Controller(cmd.Cmd):
         if stuff is not None:
             self.stdout.write(stuff + '\n')
 
-    def get_supervisor(self):
+    def get_server_proxy(self, namespace='supervisor'):
         proxy = self.options.getServerProxy()
-        namespace = getattr(proxy, 'supervisor')
-        return namespace
+        proxy_for_namespace = getattr(proxy, namespace)
+        return proxy_for_namespace
 
     def upcheck(self):
         try:
-            supervisor = self.get_supervisor()
+            supervisor = self.get_server_proxy()
             api = supervisor.getVersion() # deprecated
             from supervisor import rpcinterface
             if api != rpcinterface.API_VERSION:
@@ -451,7 +451,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
                     self.ctl.output('Error: bad argument %s' % modifier)
                     return
 
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
 
         if bytes is None:
             return self._tailf('/logtail/%s/%s' % (name, channel))
@@ -518,7 +518,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
         else:
             bytes = 1600
 
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
 
         try:
             output = supervisor.readLog(-bytes, 0)
@@ -565,7 +565,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
         if not self.ctl.upcheck():
             return
         
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
 
         names = arg.strip().split()
 
@@ -592,7 +592,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
                      "processes.")
 
     def do_pid(self, arg):
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
         pid = supervisor.getPID()
         self.ctl.output(str(pid))
 
@@ -621,7 +621,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
             return
 
         names = arg.strip().split()
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
 
         if not names:
             self.ctl.output("Error: start requires a process name")
@@ -681,7 +681,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
             return
 
         names = arg.strip().split()
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
 
         if not names:
             self.ctl.output('Error: stop requires a process name')
@@ -748,7 +748,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
         else:
             really = 1
         if really:
-            supervisor = self.ctl.get_supervisor()
+            supervisor = self.ctl.get_server_proxy()
             try:
                 supervisor.shutdown()
             except xmlrpclib.Fault, e:
@@ -768,7 +768,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
         else:
             really = 1
         if really:
-            supervisor = self.ctl.get_supervisor()
+            supervisor = self.ctl.get_server_proxy()
             try:
                 supervisor.restart()
             except xmlrpclib.Fault, e:
@@ -814,7 +814,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
         return template % formatted
 
     def do_avail(self, arg):
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
         try:
             configinfo = supervisor.getAllConfigInfo()
         except xmlrpclib.Fault, e:
@@ -828,7 +828,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
         self.ctl.output("avail\t\t\tDisplay all configured processes")
 
     def do_reread(self, arg):
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
         try:
             result = supervisor.reloadConfig()
         except xmlrpclib.Fault, e:
@@ -847,7 +847,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
     def do_add(self, arg):
         names = arg.strip().split()
 
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
         for name in names:
             try:
                 supervisor.addProcessGroup(name)
@@ -871,7 +871,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
     def do_remove(self, arg):
         names = arg.strip().split()
 
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
         for name in names:
             try:
                 result = supervisor.removeProcessGroup(name)
@@ -895,7 +895,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
         def log(name, message):
             self.ctl.output("%s: %s" % (name, message))
 
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
         try:
             result = supervisor.reloadConfig()
         except xmlrpclib.Fault, e:
@@ -957,7 +957,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
             self.help_clear()
             return
 
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
 
         if 'all' in names:
             results = supervisor.clearAllProcessLogs()
@@ -1000,7 +1000,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
     def do_version(self, arg):
         if not self.ctl.upcheck():
             return
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
         self.ctl.output(supervisor.getSupervisorVersion())
 
     def help_version(self):
@@ -1020,7 +1020,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
             self.ctl.output('Error: too many process names supplied')
             return
         program = args[0]
-        supervisor = self.ctl.get_supervisor()
+        supervisor = self.ctl.get_server_proxy()
         try:
             info = supervisor.getProcessInfo(program)
         except xmlrpclib.Fault, msg:

+ 7 - 5
src/supervisor/tests/test_supervisorctl.py

@@ -526,7 +526,7 @@ class TestDefaultControllerPlugin(unittest.TestCase):
                           'inuse': False, 'autostart': False,
                           'process_prio': 999, 'group_prio': 999 }]
 
-        plugin.ctl.get_supervisor = lambda : FakeSupervisor()
+        plugin.ctl.get_server_proxy = lambda : FakeSupervisor()
         plugin.ctl.output = calls.append
         result = plugin.do_avail('')
         self.assertEqual(result, None)
@@ -752,7 +752,7 @@ class TestDefaultControllerPlugin(unittest.TestCase):
 
     def test_maintail_readlog_error_nofile(self):
         plugin = self._makeOne()
-        supervisor_rpc = plugin.ctl.get_supervisor()
+        supervisor_rpc = plugin.ctl.get_server_proxy()
         from supervisor import xmlrpc
         supervisor_rpc._readlog_error = xmlrpc.Faults.NO_FILE
         result = plugin.do_maintail('-100')
@@ -761,7 +761,7 @@ class TestDefaultControllerPlugin(unittest.TestCase):
 
     def test_maintail_readlog_error_failed(self):
         plugin = self._makeOne()
-        supervisor_rpc = plugin.ctl.get_supervisor()
+        supervisor_rpc = plugin.ctl.get_server_proxy()
         from supervisor import xmlrpc
         supervisor_rpc._readlog_error = xmlrpc.Faults.FAILED
         result = plugin.do_maintail('-100')
@@ -840,8 +840,10 @@ class DummyController:
     def upcheck(self):
         return True
 
-    def get_supervisor(self):
-        return self.options.getServerProxy().supervisor
+    def get_server_proxy(self, namespace="supervisor"):
+        proxy = self.options.getServerProxy()
+        proxy_for_namespace = getattr(proxy, namespace)
+        return proxy_for_namespace  
 
     def output(self, data):
         self.stdout.write(data + '\n')