Skip to content

Commit 4296ce1

Browse files
committed
Use same conventions as other commands
1 parent 33c948a commit 4296ce1

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

supervisor/supervisorctl.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,56 +1282,55 @@ def help_version(self):
12821282
"version\t\t\tShow the version of the remote supervisord "
12831283
"process")
12841284

1285-
def do_fg(self, args=None):
1285+
def do_fg(self, arg):
12861286
if not self.ctl.upcheck():
12871287
return
12881288

1289-
if not args:
1290-
self.handle_error('Error: no process name supplied')
1289+
names = arg.split()
1290+
if not names:
1291+
self.handle_error('ERROR: no process name supplied')
12911292
self.help_fg()
12921293
return
1293-
1294-
args = args.split()
1295-
if len(args) > 1:
1296-
self.handle_error('Error: too many process names supplied')
1294+
if len(names) > 1:
1295+
self.handle_error('ERROR: too many process names supplied')
12971296
return
12981297

1299-
program = args[0]
1298+
name = names[0]
13001299
supervisor = self.ctl.get_supervisor()
1300+
13011301
try:
1302-
info = supervisor.getProcessInfo(program)
1303-
except xmlrpclib.Fault as msg:
1304-
if msg.faultCode == xmlrpc.Faults.BAD_NAME:
1305-
self.handle_error('Error: bad process name supplied')
1306-
return
1307-
# for any other fault
1308-
self.ctl.output(str(msg))
1302+
info = supervisor.getProcessInfo(name)
1303+
except xmlrpclib.Fault as e:
1304+
if e.faultCode == xmlrpc.Faults.BAD_NAME:
1305+
self.handle_error('ERROR: bad process name supplied')
1306+
else:
1307+
self.ctl.output('ERROR: ' + str(e))
13091308
return
13101309

1311-
if not info['state'] == states.ProcessStates.RUNNING:
1312-
self.handle_error('Error: process not running')
1310+
if info['state'] != states.ProcessStates.RUNNING:
1311+
self.handle_error('ERROR: process not running')
13131312
return
13141313

13151314
a = None
13161315
try:
13171316
# this thread takes care of the output/error messages
1318-
a = fgthread(program, self.ctl)
1317+
a = fgthread(name, self.ctl)
13191318
a.start()
13201319

13211320
# this takes care of the user input
13221321
while True:
13231322
inp = raw_input() + '\n'
13241323
try:
1325-
supervisor.sendProcessStdin(program, inp)
1326-
except xmlrpclib.Fault as msg:
1327-
if msg.faultCode == xmlrpc.Faults.NOT_RUNNING:
1324+
supervisor.sendProcessStdin(name, inp)
1325+
except xmlrpclib.Fault as e:
1326+
if e.faultCode == xmlrpc.Faults.NOT_RUNNING:
13281327
self.ctl.output('Process got killed')
13291328
self.ctl.output('Exiting foreground')
13301329
a.kill()
13311330
return
13321331

1333-
info = supervisor.getProcessInfo(program)
1334-
if not info['state'] == states.ProcessStates.RUNNING:
1332+
info = supervisor.getProcessInfo(name)
1333+
if info['state'] != states.ProcessStates.RUNNING:
13351334
self.ctl.output('Process got killed')
13361335
self.ctl.output('Exiting foreground')
13371336
a.kill()

supervisor/tests/test_supervisorctl.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,35 +1931,35 @@ def test_fg_too_few_args(self):
19311931
result = plugin.do_fg('')
19321932
self.assertEqual(result, None)
19331933
lines = plugin.ctl.stdout.getvalue().split('\n')
1934-
self.assertEqual(lines[0], 'Error: no process name supplied')
1934+
self.assertEqual(lines[0], 'ERROR: no process name supplied')
19351935
self.assertEqual(plugin.ctl.exit_status, LSBInitErrorCode.GENERIC)
19361936

19371937
def test_fg_too_many_args(self):
19381938
plugin = self._makeOne()
19391939
result = plugin.do_fg('foo bar')
19401940
self.assertEqual(result, None)
19411941
line = plugin.ctl.stdout.getvalue()
1942-
self.assertEqual(line, 'Error: too many process names supplied\n')
1942+
self.assertEqual(line, 'ERROR: too many process names supplied\n')
19431943
self.assertEqual(plugin.ctl.exit_status, LSBInitErrorCode.GENERIC)
19441944

19451945
def test_fg_badprocname(self):
19461946
plugin = self._makeOne()
19471947
result = plugin.do_fg('BAD_NAME')
19481948
self.assertEqual(result, None)
19491949
line = plugin.ctl.stdout.getvalue()
1950-
self.assertEqual(line, 'Error: bad process name supplied\n')
1950+
self.assertEqual(line, 'ERROR: bad process name supplied\n')
19511951
self.assertEqual(plugin.ctl.exit_status, LSBInitErrorCode.GENERIC)
19521952

19531953
def test_fg_procnotrunning(self):
19541954
plugin = self._makeOne()
19551955
result = plugin.do_fg('bar')
19561956
self.assertEqual(result, None)
19571957
line = plugin.ctl.stdout.getvalue()
1958-
self.assertEqual(line, 'Error: process not running\n')
1958+
self.assertEqual(line, 'ERROR: process not running\n')
19591959
result = plugin.do_fg('baz_01')
19601960
lines = plugin.ctl.stdout.getvalue().split('\n')
19611961
self.assertEqual(result, None)
1962-
self.assertEqual(lines[-2], 'Error: process not running')
1962+
self.assertEqual(lines[-2], 'ERROR: process not running')
19631963
self.assertEqual(plugin.ctl.exit_status, LSBInitErrorCode.GENERIC)
19641964

19651965
def test_fg_upcheck_failed(self):

0 commit comments

Comments
 (0)