Commits

Eric Larson committed 5af7f11 Draft

pep8

Comments (0)

Files changed (5)

eggmonster/client/_em_emi.py

 
 logger = logging.getLogger('em.emi.parent')
 
+
 def get_app_info(sock):
     ret = sock.recv(65536)
     if not ret:
 
     return app_info, buf
 
+
 def sendsig(child, sig):
     signal_name = {signal.SIGKILL: 'KILL', signal.SIGTERM: 'TERM'}.get(
         sig, 'SIG%s' % sig)
     logger.debug('Sending %s signal to child process.' % signal_name)
     os.kill(child, sig)
 
+
 def process_server_commands(sock, buf, child):
     while True:
         while '\n' not in buf:
         elif cmd == 'kill':
             sendsig(child, signal.SIGKILL)
 
+
 def connect_to_master():
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     if 'fcntl' in globals():
     sock.connect((emenv.master_host, emenv.master_emi_port))
     return sock
 
+
 def get_config(HOSTNAME, app_name, app_num, flags):
     sock = connect_to_master()
     sock.sendall('%s %s %s %s\r\n' % (HOSTNAME, app_name, app_num, flags))
     (entry_point, env, pkg_info), buf = get_app_info(sock)
     return entry_point, env, pkg_info, buf, sock
 
+
 def main(app_name, num, spawn_app, extra_args, debug):
 
     app_id = ', appid=%s:%s' % (app_name, num)
     finally:
         logger.debug('Exiting.')
 
+
 def _main(app_name, num, spawn_app, extra_args):
     master_user = os.environ['EMI_USER']
     master_uid = pwd.getpwnam(master_user)[2]
     # upper case - flag enabled
     # lower case - flag disabled
     flags = ''.join([
-        'm' if spawn_app else 'M', # monitored by eggmaster
+        'm' if spawn_app else 'M',  # monitored by eggmaster
     ])
 
     entry_point, env, pkg_info, buf, sock = get_config(HOSTNAME, app_name,
     logger.debug('Child process stopped: exitcode=%s, signalled=%s',
         os.WEXITSTATUS(res), os.WIFSIGNALED(res))
 
+
 def run_app(pkginfo, entry_point, env, num, spawn_app, extra_args):
     if not spawn_app:
         pid = os.fork()
             return pid
 
     # update the logger to indicate we're now in a child process
-    globals().update(logger = logging.getLogger('em.emi.child'))
+    globals().update(logger=logging.getLogger('em.emi.child'))
 
     logger.debug('About to locate entry point "%s" in package "%s".',
         (spawn_app or entry_point), pkginfo)
 
 from string import Template
 
+
 def fill_config_placeholders(env, num):
     fill_dict = {
         'num': num,

eggmonster/commands/emi.py

 import sys
 from eggmonster.client._em_emi import main
 
+
 def run():
     if '!' in sys.argv:
         delimiter_index = sys.argv.index('!')
-        prog_args = sys.argv[delimiter_index+1:]
+        prog_args = sys.argv[delimiter_index + 1:]
         monster_args = sys.argv[:delimiter_index]
     else:
         prog_args = []

eggmonster/commands/monster_launchd.py

 #!/usr/bin/env python
 
-import sys, cgi, os
+import os
 import getpass
 from eggmonster.launch import main
 from optparse import OptionParser
 except ImportError:
     pass
 
+
 def setup_parser():
     parser = OptionParser()
     current_user = getpass.getuser()
     parser.add_option("-u", "--user", default=current_user,
         help="setuid() to this user in application processes "
         "(default: %(current_user)s)" % vars())
-    
+
     default_host_id = platform.node()
     parser.add_option('-i', '--host-id', default=default_host_id,
         help="The host id to use (defaults to %(default_host_id)s)." %
         help='Print debug information about launching processes.')
     return parser
 
+
 def get_options():
     parser = setup_parser()
     options, args = parser.parse_args()
 
     return options
 
+
 def run():
     options = get_options()
 

eggmonster/internal_log.py

 
 import eggmonster
 
+
 def get_host():
     """
     Determine a good host for eggmonster logging. Log to the host specified
-    by EGGMONSTER_LOG_HOST if defined in the environment, or log to 
+    by EGGMONSTER_LOG_HOST if defined in the environment, or log to
     `monster-log` if it resolves.
     """
     env_host = os.environ.get('EGGMONSTER_LOG_HOST')
             return None
     return host, port
 
+
 def configure(debug_flag, extra_identity=''):
     logger = logging.getLogger('em')
     logger.setLevel(logging.DEBUG)
 
-    formatter = logging.Formatter('%%(name)s [pid=%%(process)s%s] %%(message)s' % extra_identity)
+    formatter = logging.Formatter('%%(name)s [pid=%%(process)s%s] %%(message)s'
+                                  % extra_identity)
 
     # Set up stderr handler.
     sys_handler = logging.StreamHandler(sys.stderr)

eggmonster/launch.py

 
 EM_VERSION = require('eggmonster')[0].version
 
+
 def main(user, debug, host_id=None):
     eggmonster.internal_log.configure(debug)
 
             logger.info('Resetting connection to master in 5 seconds...')
             time.sleep(5)
 
+
 def launch_loop(sock, debug):
     sockfile = sock.makefile('r', 1)
     for line in sockfile:
         if line.strip() != 'noop':
             launch_app(line, debug)
 
+
 # Usefully nabbed from:
 #   http://jimmyg.org/blog/2009/working-with-python-subprocess.html
 def whereis(program):
             return target
     return None
 
+
 def launch_app(line, debug):
     try:
         app_id, n, package = line.strip().split(None, 2)
     except OSError:
         logger.error('Problem invoking process: %s' % (args,))
         if not whereis('emi'):
-            logger.error('Could not find "emi" executable on path: %s' % os.environ.get('PATH', ''))
+            logger.error('Could not find "emi" executable on path: %s'
+                         % os.environ.get('PATH', ''))
         raise
 
     logger.debug('Running "%s" [pid=%s]' % (' '.join(args), proc.pid))