From 475b2c39563c4f0a38b16e5f26dac0f57799950c 2011-06-20 23:40:15
From: MinRK <benjaminrk@gmail.com>
Date: 2011-06-20 23:40:15
Subject: [PATCH] use BaseIPythonApp.load_config, not Application.load_config

---

diff --git a/IPython/parallel/apps/clusterdir.py b/IPython/parallel/apps/clusterdir.py
index 3766d26..5c5a8ec 100755
--- a/IPython/parallel/apps/clusterdir.py
+++ b/IPython/parallel/apps/clusterdir.py
@@ -36,7 +36,7 @@ from IPython.utils.path import (
     get_ipython_dir,
     expand_path
 )
-from IPython.utils.traitlets import Unicode, Bool, Instance, Dict
+from IPython.utils.traitlets import Unicode, Bool, Instance, Dict, List
 
 #-----------------------------------------------------------------------------
 # Module errors
@@ -303,12 +303,12 @@ class ClusterDirCrashHandler(CrashHandler):
 base_aliases = {
     'profile' : "ClusterDir.profile",
     'cluster_dir' : 'ClusterDir.location',
-    'auto_create' : 'ClusterDirApplication.auto_create',
     'log_level' : 'ClusterApplication.log_level',
     'work_dir' : 'ClusterApplication.work_dir',
     'log_to_file' : 'ClusterApplication.log_to_file',
     'clean_logs' : 'ClusterApplication.clean_logs',
     'log_url' : 'ClusterApplication.log_url',
+    'config' : 'ClusterApplication.config_file',
 }
 
 base_flags = {
@@ -329,7 +329,7 @@ class ClusterApplication(BaseIPythonApplication):
     The cluster directory is resolved as follows:
 
     * If the ``cluster_dir`` option is given, it is used.
-    * If ``cluster_dir`` is not given, the application directory is
+    * If ``cluster_dir`` is not given, the application directory is 
       resolve using the profile name as ``cluster_<profile>``. The search 
       path for this directory is then i) cwd if it is found there
       and ii) in ipython_dir otherwise.
@@ -357,16 +357,27 @@ class ClusterApplication(BaseIPythonApplication):
     log_to_file = Bool(config=True,
         help="whether to log to a file")
 
-    clean_logs = Bool(False, shortname='--clean-logs', config=True,
+    clean_logs = Bool(False, config=True,
         help="whether to cleanup old logfiles before starting")
 
-    log_url = Unicode('', shortname='--log-url', config=True,
+    log_url = Unicode('', config=True,
         help="The ZMQ URL of the iplogger to aggregate logging.")
 
     config_file = Unicode(u'', config=True,
-        help="""Path to ipcontroller configuration file.  The default is to use
+        help="""Path to ip<appname> configuration file.  The default is to use
          <appname>_config.py, as found by cluster-dir."""
     )
+    def _config_file_paths_default(self):
+        # don't include profile dir
+        return [ os.getcwdu(), self.ipython_dir ]
+    
+    def _config_file_changed(self, name, old, new):
+        if os.pathsep in new:
+            path, new = new.rsplit(os.pathsep)
+            self.config_file_paths.insert(0, path)
+        self.config_file_name = new
+    
+    config_file_name = Unicode('')
     
     loop = Instance('zmq.eventloop.ioloop.IOLoop')
     def _loop_default(self):
@@ -409,6 +420,9 @@ class ClusterApplication(BaseIPythonApplication):
         else:
             self.log.info('Using existing cluster dir: %s' % \
                             self.cluster_dir.location)
+        
+        # insert after cwd:
+        self.config_file_paths.insert(1, self.cluster_dir.location)
     
     def initialize(self, argv=None):
         """initialize the app"""
@@ -416,14 +430,7 @@ class ClusterApplication(BaseIPythonApplication):
         self.parse_command_line(argv)
         cl_config = self.config
         self.init_clusterdir()
-        if self.config_file:
-            self.load_config_file(self.config_file)
-        elif self.default_config_file_name:
-            try:
-                self.load_config_file(self.default_config_file_name, 
-                                        path=self.cluster_dir.location)
-            except IOError:
-                self.log.warn("Warning: Default config file not found")
+        self.load_config_file()
         # command-line should *override* config file, but command-line is necessary
         # to determine clusterdir, etc.
         self.update_config(cl_config)
@@ -438,17 +445,6 @@ class ClusterApplication(BaseIPythonApplication):
         # This is the working dir by now.
         sys.path.insert(0, '')
 
-    def load_config_file(self, filename, path=None):
-        """Load a .py based config file by filename and path."""
-        # use config.application.Application.load_config
-        # instead of inflexible core.newapplication.BaseIPythonApplication.load_config
-        return Application.load_config_file(self, filename, path=path)
-    #
-    # def load_default_config_file(self):
-    #     """Load a .py based config file by filename and path."""
-    #     return BaseIPythonApplication.load_config_file(self)
-
-    # disable URL-logging
     def reinit_logging(self):
         # Remove old log files
         log_dir = self.cluster_dir.log_dir
diff --git a/IPython/parallel/apps/ipclusterapp.py b/IPython/parallel/apps/ipclusterapp.py
index 35a4cbd..8ef7221 100755
--- a/IPython/parallel/apps/ipclusterapp.py
+++ b/IPython/parallel/apps/ipclusterapp.py
@@ -178,7 +178,7 @@ class IPClusterCreate(ClusterApplication):
     description = create_help
     auto_create_cluster_dir = Bool(True,
         help="whether to create the cluster_dir if it doesn't exist")
-    default_config_file_name = default_config_file_name
+    config_file_name = Unicode(default_config_file_name)
     
     reset = Bool(False, config=True,
         help="Whether to reset config files as part of 'create'."
@@ -210,7 +210,7 @@ class IPClusterStop(ClusterApplication):
     name = u'ipcluster'
     description = stop_help
     auto_create_cluster_dir = Bool(False)
-    default_config_file_name = default_config_file_name
+    config_file_name = Unicode(default_config_file_name)
     
     signal = Int(signal.SIGINT, config=True,
         help="signal to use for stopping processes.")
@@ -277,7 +277,7 @@ class IPClusterEngines(ClusterApplication):
     name = u'ipcluster'
     description = engines_help
     usage = None
-    default_config_file_name = default_config_file_name
+    config_file_name = Unicode(default_config_file_name)
     default_log_level = logging.INFO
     auto_create_cluster_dir = Bool(False)
     classes = List()
@@ -409,8 +409,6 @@ class IPClusterStart(IPClusterEngines):
 
     name = u'ipcluster'
     description = start_help
-    usage = None
-    default_config_file_name = default_config_file_name
     default_log_level = logging.INFO
     auto_create_cluster_dir = Bool(True, config=True,
         help="whether to create the cluster_dir if it doesn't exist")
diff --git a/IPython/parallel/apps/ipcontrollerapp.py b/IPython/parallel/apps/ipcontrollerapp.py
index 9495101..40bb50d 100755
--- a/IPython/parallel/apps/ipcontrollerapp.py
+++ b/IPython/parallel/apps/ipcontrollerapp.py
@@ -110,8 +110,7 @@ class IPControllerApp(ClusterApplication):
 
     name = u'ipcontroller'
     description = _description
-    # command_line_loader = IPControllerAppConfigLoader
-    default_config_file_name = default_config_file_name
+    config_file_name = Unicode(default_config_file_name)
     classes = [ClusterDir, StreamSession, HubFactory, TaskScheduler, HeartMonitor, SQLiteDB] + maybe_mongo
     
     auto_create_cluster_dir = Bool(True, config=True,
diff --git a/IPython/parallel/apps/ipengineapp.py b/IPython/parallel/apps/ipengineapp.py
index e04274a..fdd4b68 100755
--- a/IPython/parallel/apps/ipengineapp.py
+++ b/IPython/parallel/apps/ipengineapp.py
@@ -102,7 +102,7 @@ class IPEngineApp(ClusterApplication):
 
     app_name = Unicode(u'ipengine')
     description = Unicode(_description)
-    default_config_file_name = default_config_file_name
+    config_file_name = Unicode(default_config_file_name)
     classes = List([ClusterDir, StreamSession, EngineFactory, Kernel, MPI])
 
     auto_create_cluster_dir = Bool(False,
diff --git a/IPython/parallel/apps/iploggerapp.py b/IPython/parallel/apps/iploggerapp.py
index 8c98692..5b1cf73 100755
--- a/IPython/parallel/apps/iploggerapp.py
+++ b/IPython/parallel/apps/iploggerapp.py
@@ -20,7 +20,7 @@ import sys
 
 import zmq
 
-from IPython.utils.traitlets import Bool, Dict
+from IPython.utils.traitlets import Bool, Dict, Unicode
 
 from IPython.parallel.apps.clusterdir import (
     ClusterApplication,
@@ -58,7 +58,7 @@ class IPLoggerApp(ClusterApplication):
 
     name = u'iploggerz'
     description = _description
-    default_config_file_name = default_config_file_name
+    config_file_name = Unicode(default_config_file_name)
     auto_create_cluster_dir = Bool(False)
     
     classes = [LogWatcher, ClusterDir]