浏览代码

Minor coding standards cleanup.

Mike Naberezny 17 年之前
父节点
当前提交
f91283872d
共有 2 个文件被更改,包括 50 次插入50 次删除
  1. 23 23
      src/supervisor/supervisorctl.py
  2. 27 27
      src/supervisor/tests/test_supervisorctl.py

+ 23 - 23
src/supervisor/supervisorctl.py

@@ -49,24 +49,24 @@ from supervisor.options import split_namespec
 from supervisor import xmlrpc
 from supervisor import xmlrpc
 
 
 class fgthread(threading.Thread):
 class fgthread(threading.Thread):
-    
-    # A subclass of threading.Thread, with a kill() method.
-    # To be used for foreground output/error streaming.
-    # http://mail.python.org/pipermail/python-list/2004-May/260937.html
+    """ A subclass of threading.Thread, with a kill() method.
+    To be used for foreground output/error streaming.
+    http://mail.python.org/pipermail/python-list/2004-May/260937.html
+    """
   
   
     def __init__(self, program, ctl):
     def __init__(self, program, ctl):
         threading.Thread.__init__(self)
         threading.Thread.__init__(self)
         import http_client
         import http_client
         self.killed = False
         self.killed = False
-        self.program=program
-        self.ctl=ctl
-        self.listener=http_client.Listener()
-        self.output_handler=http_client.HTTPHandler(self.listener,
-                                                    self.ctl.options.username,
-                                                    self.ctl.options.password)
-        self.error_handler=http_client.HTTPHandler(self.listener,
-                                                   self.ctl.options.username,
-                                                   self.ctl.options.password)
+        self.program = program
+        self.ctl = ctl
+        self.listener = http_client.Listener()
+        self.output_handler = http_client.HTTPHandler(self.listener,
+                                                      self.ctl.options.username,
+                                                      self.ctl.options.password)
+        self.error_handler = http_client.HTTPHandler(self.listener,
+                                                     self.ctl.options.username,
+                                                     self.ctl.options.password)
 
 
     def start(self):
     def start(self):
         # Start the thread
         # Start the thread
@@ -262,19 +262,19 @@ class Controller(cmd.Cmd):
             import readline
             import readline
         except ImportError:
         except ImportError:
             return None
             return None
-        line=readline.get_line_buffer()
+        line = readline.get_line_buffer()
         if line == '':
         if line == '':
             results = [i+' ' for i in self.vocab if i.startswith(text)]+[None]
             results = [i+' ' for i in self.vocab if i.startswith(text)]+[None]
             return results[state]
             return results[state]
         else:
         else:
-            exp=line.split()[0]
+            exp = line.split()[0]
             if exp in ['start','stop','restart','clear','status','tail','fg']:
             if exp in ['start','stop','restart','clear','status','tail','fg']:
                 if not line.endswith(' ') and len(line.split()) == 1:
                 if not line.endswith(' ') and len(line.split()) == 1:
-                    return [text+' ',None][state]
+                    return [text + ' ', None][state]
                 if exp == 'fg':
                 if exp == 'fg':
                     if line.endswith(' ') and len(line.split()) > 1:
                     if line.endswith(' ') and len(line.split()) > 1:
                         return None
                         return None
-                results=self.completionmatches(text,line)+[None]
+                results = self.completionmatches(text,line)+[None]
                 return results[state]
                 return results[state]
             elif exp in ['maintail','pid','reload','shutdown','exit','open',
             elif exp in ['maintail','pid','reload','shutdown','exit','open',
                          'quit','version','EOF']:
                          'quit','version','EOF']:
@@ -905,14 +905,14 @@ class DefaultControllerPlugin(ControllerPluginBase):
             self.ctl.output('Error: no process name supplied')
             self.ctl.output('Error: no process name supplied')
             self.help_fg()
             self.help_fg()
             return
             return
-        args=args.split()
-        if len(args)>1:
+        args = args.split()
+        if len(args) > 1:
             self.ctl.output('Error: too many process names supplied')
             self.ctl.output('Error: too many process names supplied')
             return
             return
-        program=args[0]
-        supervisor=self.ctl.get_supervisor()
+        program = args[0]
+        supervisor = self.ctl.get_supervisor()
         try:
         try:
-            info=supervisor.getProcessInfo(program)
+            info = supervisor.getProcessInfo(program)
         except xmlrpclib.Fault, msg:
         except xmlrpclib.Fault, msg:
             if msg.faultCode == xmlrpc.Faults.BAD_NAME:
             if msg.faultCode == xmlrpc.Faults.BAD_NAME:
                 self.ctl.output('Error: bad process name supplied')
                 self.ctl.output('Error: bad process name supplied')
@@ -925,7 +925,7 @@ class DefaultControllerPlugin(ControllerPluginBase):
             return
             return
         # everything good; continue
         # everything good; continue
         try:
         try:
-            a=fgthread(program,self.ctl)
+            a = fgthread(program,self.ctl)
             # this thread takes care of
             # this thread takes care of
             # the output/error messages
             # the output/error messages
             a.start()
             a.start()

+ 27 - 27
src/supervisor/tests/test_supervisorctl.py

@@ -590,37 +590,37 @@ class TestDefaultControllerPlugin(unittest.TestCase):
         self.assertEqual(plugin.ctl.stdout.getvalue(),
         self.assertEqual(plugin.ctl.stdout.getvalue(),
                          'supervisord: ERROR (unknown error reading log)\n')
                          'supervisord: ERROR (unknown error reading log)\n')
 
 
-    def test_fg_toofewargs(self):
-        plugin=self._makeOne()
-        result=plugin.do_fg('')
-        lines=plugin.ctl.stdout.getvalue().split('\n')
-        self.assertEqual(result,None)
-        self.assertEqual(lines[0],'Error: no process name supplied')
-
-    def test_fg_toomanyargs(self):
-        plugin=self._makeOne()
-        result=plugin.do_fg('foo bar')
-        line=plugin.ctl.stdout.getvalue()
-        self.assertEqual(result,None)
-        self.assertEqual(line,'Error: too many process names supplied\n')
+    def test_fg_too_few_args(self):
+        plugin = self._makeOne()
+        result = plugin.do_fg('')
+        lines = plugin.ctl.stdout.getvalue().split('\n')
+        self.assertEqual(result, None)
+        self.assertEqual(lines[0], 'Error: no process name supplied')
+
+    def test_fg_too_many_args(self):
+        plugin = self._makeOne()
+        result = plugin.do_fg('foo bar')
+        line = plugin.ctl.stdout.getvalue()
+        self.assertEqual(result, None)
+        self.assertEqual(line, 'Error: too many process names supplied\n')
 
 
     def test_fg_badprocname(self):
     def test_fg_badprocname(self):
-        plugin=self._makeOne()
-        result=plugin.do_fg('BAD_NAME')
-        line=plugin.ctl.stdout.getvalue()
-        self.assertEqual(result,None)
-        self.assertEqual(line,'Error: bad process name supplied\n')
+        plugin = self._makeOne()
+        result = plugin.do_fg('BAD_NAME')
+        line = plugin.ctl.stdout.getvalue()
+        self.assertEqual(result, None)
+        self.assertEqual(line, 'Error: bad process name supplied\n')
 
 
     def test_fg_procnotrunning(self):
     def test_fg_procnotrunning(self):
-        plugin=self._makeOne()
-        result=plugin.do_fg('bar')
-        line=plugin.ctl.stdout.getvalue()
-        self.assertEqual(result,None)
-        self.assertEqual(line,'Error: process not running\n')
-        result=plugin.do_fg('baz_01')
-        lines=plugin.ctl.stdout.getvalue().split('\n')
-        self.assertEqual(result,None)
-        self.assertEqual(lines[-2],'Error: process not running')
+        plugin = self._makeOne()
+        result = plugin.do_fg('bar')
+        line = plugin.ctl.stdout.getvalue()
+        self.assertEqual(result, None)
+        self.assertEqual(line, 'Error: process not running\n')
+        result = plugin.do_fg('baz_01')
+        lines = plugin.ctl.stdout.getvalue().split('\n')
+        self.assertEqual(result, None)
+        self.assertEqual(lines[-2], 'Error: process not running')
 
 
 class DummyListener:
 class DummyListener:
     def __init__(self):
     def __init__(self):