From ae1a6688432bddf28cf3057ae5c7e3eba49ee81d 2011-11-28 01:47:41
From: MinRK <benjaminrk@gmail.com>
Date: 2011-11-28 01:47:41
Subject: [PATCH] minor cleanup in ipcontroller/ipengine

small adjustments to log formatting, and add new info-level
message indicating full path of json files being written/read.

---

diff --git a/IPython/parallel/apps/ipcontrollerapp.py b/IPython/parallel/apps/ipcontrollerapp.py
index 4ef765d..8fc424a 100755
--- a/IPython/parallel/apps/ipcontrollerapp.py
+++ b/IPython/parallel/apps/ipcontrollerapp.py
@@ -210,6 +210,7 @@ class IPControllerApp(BaseParallelApplication):
                     location = '127.0.0.1'
             cdict['location'] = location
         fname = os.path.join(self.profile_dir.security_dir, fname)
+        self.log.info("writing connection info to %s", fname)
         with open(fname, 'w') as f:
             f.write(json.dumps(cdict, indent=2))
         os.chmod(fname, stat.S_IRUSR|stat.S_IWUSR)
@@ -219,7 +220,9 @@ class IPControllerApp(BaseParallelApplication):
         c = self.config
         self.log.debug("loading config from JSON")
         # load from engine config
-        with open(os.path.join(self.profile_dir.security_dir, self.engine_json_file)) as f:
+        fname = os.path.join(self.profile_dir.security_dir, self.engine_json_file)
+        self.log.info("loading connection info from %s", fname)
+        with open(fname) as f:
             cfg = json.loads(f.read())
         key = c.Session.key = asbytes(cfg['exec_key'])
         xport,addr = cfg['url'].split('://')
@@ -231,7 +234,9 @@ class IPControllerApp(BaseParallelApplication):
         if not self.engine_ssh_server:
             self.engine_ssh_server = cfg['ssh']
         # load client config
-        with open(os.path.join(self.profile_dir.security_dir, self.client_json_file)) as f:
+        fname = os.path.join(self.profile_dir.security_dir, self.client_json_file)
+        self.log.info("loading connection info from %s", fname)
+        with open(fname) as f:
             cfg = json.loads(f.read())
         assert key == cfg['exec_key'], "exec_key mismatch between engine and client keys"
         xport,addr = cfg['url'].split('://')
diff --git a/IPython/parallel/apps/ipengineapp.py b/IPython/parallel/apps/ipengineapp.py
index f8530cc..494bbd3 100755
--- a/IPython/parallel/apps/ipengineapp.py
+++ b/IPython/parallel/apps/ipengineapp.py
@@ -177,22 +177,6 @@ class IPEngineApp(BaseParallelApplication):
     aliases = Dict(aliases)
     flags = Dict(flags)
 
-    # def find_key_file(self):
-    #     """Set the key file.
-    # 
-    #     Here we don't try to actually see if it exists for is valid as that
-    #     is hadled by the connection logic.
-    #     """
-    #     config = self.master_config
-    #     # Find the actual controller key file
-    #     if not config.Global.key_file:
-    #         try_this = os.path.join(
-    #             config.Global.profile_dir, 
-    #             config.Global.security_dir,
-    #             config.Global.key_file_name
-    #         )
-    #         config.Global.key_file = try_this
-        
     def find_url_file(self):
         """Set the url file.
 
@@ -212,7 +196,7 @@ class IPEngineApp(BaseParallelApplication):
         at a *lower* priority than command-line/config files.
         """
         
-        self.log.info("Loading url_file %r"%self.url_file)
+        self.log.info("Loading url_file %r", self.url_file)
         config = self.config
         
         with open(self.url_file) as f:
@@ -256,17 +240,17 @@ class IPEngineApp(BaseParallelApplication):
             url_specified = False
 
         if self.wait_for_url_file and not os.path.exists(self.url_file):
-            self.log.warn("url_file %r not found"%self.url_file)
-            self.log.warn("Waiting up to %.1f seconds for it to arrive."%self.wait_for_url_file)
+            self.log.warn("url_file %r not found", self.url_file)
+            self.log.warn("Waiting up to %.1f seconds for it to arrive.", self.wait_for_url_file)
             tic = time.time()
             while not os.path.exists(self.url_file) and (time.time()-tic < self.wait_for_url_file):
-                # wait for url_file to exist, for up to 10 seconds
+                # wait for url_file to exist, or until time limit
                 time.sleep(0.1)
             
         if os.path.exists(self.url_file):
             self.load_connector_file()
         elif not url_specified:
-            self.log.critical("Fatal: url file never arrived: %s"%self.url_file)
+            self.log.fatal("Fatal: url file never arrived: %s", self.url_file)
             self.exit(1)
         
         
@@ -278,7 +262,7 @@ class IPEngineApp(BaseParallelApplication):
         
         if self.startup_script:
             enc = sys.getfilesystemencoding() or 'utf8'
-            cmd="execfile(%r)"%self.startup_script.encode(enc)
+            cmd="execfile(%r)" % self.startup_script.encode(enc)
             exec_lines.append(cmd)
         if self.startup_command:
             exec_lines.append(self.startup_command)
@@ -294,7 +278,7 @@ class IPEngineApp(BaseParallelApplication):
     
     def forward_logging(self):
         if self.log_url:
-            self.log.info("Forwarding logging to %s"%self.log_url)
+            self.log.info("Forwarding logging to %s", self.log_url)
             context = self.engine.context
             lsock = context.socket(zmq.PUB)
             lsock.connect(self.log_url)