From d66d4761c38f8783a0e6efbbbaf3307fcbb08bf8 2009-10-31 19:07:09 From: Brian Granger Date: 2009-10-31 19:07:09 Subject: [PATCH] Added a log retrieval interface to Cluster. --- diff --git a/IPython/kernel/clientconnector.py b/IPython/kernel/clientconnector.py index f7833f3..034dbd5 100644 --- a/IPython/kernel/clientconnector.py +++ b/IPython/kernel/clientconnector.py @@ -14,6 +14,7 @@ # Imports #----------------------------------------------------------------------------- +from __future__ import with_statement import os from IPython.kernel.fcutil import Tub, find_furl @@ -474,6 +475,30 @@ class AsyncCluster(object): cluster_dir=self.cluster_dir_obj.location ) + def get_ipengine_logs(self): + return self.get_logs_by_name('ipengine') + + def get_ipcontroller_logs(self): + return self.get_logs_by_name('ipcontroller') + + def get_ipcluster_logs(self): + return self.get_logs_by_name('ipcluster') + + def get_logs_by_name(self, name='ipcluster'): + log_dir = self.cluster_dir_obj.log_dir + logs = {} + for log in os.listdir(log_dir): + if log.startswith(name + '-') and log.endswith('.log'): + with open(os.path.join(log_dir, log), 'r') as f: + logs[log] = f.read() + return logs + + def get_logs(self): + d = self.get_ipcluster_logs() + d.update(self.get_ipengine_logs()) + d.update(self.get_ipcontroller_logs()) + return d + def _handle_start(self, r): self.state = 'running' @@ -580,5 +605,51 @@ class Cluster(object): cluster_dir=self.cluster_dir_obj.location ) - + def __repr__(self): + s = "