[Supervisor-checkins] r845 - in supervisor/trunk/src/supervisor: . tests
Mike Naberezny
mike at maintainable.com
Sun Apr 19 14:23:09 EDT 2009
Author: Mike Naberezny <mike at maintainable.com>
Date: Sun Apr 19 14:23:08 2009
New Revision: 845
Log:
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..
Modified:
supervisor/trunk/src/supervisor/supervisorctl.py
supervisor/trunk/src/supervisor/tests/test_supervisorctl.py
Modified: supervisor/trunk/src/supervisor/supervisorctl.py
==============================================================================
--- supervisor/trunk/src/supervisor/supervisorctl.py (original)
+++ supervisor/trunk/src/supervisor/supervisorctl.py Sun Apr 19 14:23:08 2009
@@ -116,7 +116,7 @@
'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 @@
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 @@
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 @@
else:
bytes = 1600
- supervisor = self.ctl.get_supervisor()
+ supervisor = self.ctl.get_server_proxy()
try:
output = supervisor.readLog(-bytes, 0)
@@ -565,7 +565,7 @@
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 @@
"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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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:
Modified: supervisor/trunk/src/supervisor/tests/test_supervisorctl.py
==============================================================================
--- supervisor/trunk/src/supervisor/tests/test_supervisorctl.py (original)
+++ supervisor/trunk/src/supervisor/tests/test_supervisorctl.py Sun Apr 19 14:23:08 2009
@@ -526,7 +526,7 @@
'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 @@
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 @@
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 @@
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')
More information about the Supervisor-checkins
mailing list