diff --git a/IPython/parallel/apps/clusterdir.py b/IPython/parallel/apps/clusterdir.py index 8f520d7..b707c02 100755 --- a/IPython/parallel/apps/clusterdir.py +++ b/IPython/parallel/apps/clusterdir.py @@ -72,26 +72,31 @@ class ClusterDir(Configurable): log_dir = Unicode(u'') pid_dir = Unicode(u'') + auto_create = Bool(False, + help="""Whether to automatically create the ClusterDirectory if it does + not exist""") + overwrite = Bool(False, + help="""Whether to overwrite existing config files""") location = Unicode(u'', config=True, help="""Set the cluster dir. This overrides the logic used by the `profile` option.""", ) - profile = Unicode(u'default', + profile = Unicode(u'default', config=True, help="""The string name of the profile to be used. This determines the name of the cluster dir as: cluster_. The default profile is named 'default'. The cluster directory is resolve this way if the - `cluster_dir` option is not used.""", config=True + `cluster_dir` option is not used.""" ) - auto_create = Bool(False, - help="""Whether to automatically create the ClusterDirectory if it does - not exist""") - overwrite = Bool(False, - help="""Whether to overwrite existing config files""") _location_isset = Bool(False) # flag for detecting multiply set location _new_dir = Bool(False) # flag for whether a new dir was created def __init__(self, **kwargs): + # make sure auto_create,overwrite are set *before* location + for name in ('auto_create', 'overwrite'): + v = kwargs.pop(name, None) + if v is not None: + setattr(self, name, v) super(ClusterDir, self).__init__(**kwargs) if not self.location: self._profile_changed('profile', 'default', self.profile) @@ -101,7 +106,7 @@ class ClusterDir(Configurable): raise RuntimeError("Cannot set ClusterDir more than once.") self._location_isset = True if not os.path.isdir(new): - if self.auto_create: + if self.auto_create:# or self.config.ClusterDir.auto_create: os.makedirs(new) self._new_dir = True else: @@ -388,7 +393,16 @@ class ClusterApplication(BaseIPythonApplication): ``True``, then create the new cluster dir in the IPython directory. 4. If all fails, then raise :class:`ClusterDirError`. """ - self.cluster_dir = ClusterDir(config=self.config, auto_create=self.auto_create_cluster_dir) + try: + self.cluster_dir = ClusterDir(auto_create=self.auto_create_cluster_dir, config=self.config) + except ClusterDirError as e: + self.log.fatal("Error initializing cluster dir: %s"%e) + self.log.fatal("A cluster dir must be created before running this command.") + self.log.fatal("Do 'ipcluster create -h' or 'ipcluster list -h' for more " + "information about creating and listing cluster dirs." + ) + self.exit(1) + if self.cluster_dir._new_dir: self.log.info('Creating new cluster dir: %s' % \ self.cluster_dir.location) @@ -398,6 +412,7 @@ class ClusterApplication(BaseIPythonApplication): def initialize(self, argv=None): """initialize the app""" + self.init_crash_handler() self.parse_command_line(argv) cl_config = self.config self.init_clusterdir() @@ -421,8 +436,7 @@ class ClusterApplication(BaseIPythonApplication): 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 + # instead of inflexible core.newapplication.BaseIPythonApplication.load_config return Application.load_config_file(self, filename, path=path) # # def load_default_config_file(self): diff --git a/IPython/parallel/apps/ipclusterapp.py b/IPython/parallel/apps/ipclusterapp.py index a6f3579..3257733 100755 --- a/IPython/parallel/apps/ipclusterapp.py +++ b/IPython/parallel/apps/ipclusterapp.py @@ -204,15 +204,21 @@ stop_aliases = dict( class IPClusterStop(ClusterApplication): name = u'ipcluster' description = stop_help - auto_create_cluster_dir = Bool(False, - help="whether to create the cluster_dir if it doesn't exist") + auto_create_cluster_dir = Bool(False) default_config_file_name = default_config_file_name signal = Int(signal.SIGINT, config=True, help="signal to use for stopping processes.") aliases = Dict(stop_aliases) - + + def init_clusterdir(self): + try: + super(IPClusterStop, self).init_clusterdir() + except ClusterDirError as e: + self.log.fatal("Failed ClusterDir init: %s"%e) + self.exit(1) + def start(self): """Start the app for the stop subcommand.""" try: @@ -425,17 +431,6 @@ class IPClusterStart(IPClusterEngines): # flags = Dict(flags) aliases = Dict(start_aliases) - def init_clusterdir(self): - try: - super(IPClusterStart, self).init_clusterdir() - except ClusterDirError: - raise ClusterDirError( - "Could not find a cluster directory. A cluster dir must " - "be created before running 'ipcluster start'. Do " - "'ipcluster create -h' or 'ipcluster list -h' for more " - "information about creating and listing cluster dirs." - ) - def init_launchers(self): self.controller_launcher = self.build_launcher(self.controller_launcher_class) self.engine_launcher = self.build_launcher(self.engine_launcher_class) diff --git a/IPython/parallel/apps/ipcontrollerapp.py b/IPython/parallel/apps/ipcontrollerapp.py index 6cc0044..3df9b1b 100755 --- a/IPython/parallel/apps/ipcontrollerapp.py +++ b/IPython/parallel/apps/ipcontrollerapp.py @@ -110,9 +110,10 @@ class IPControllerApp(ClusterApplication): description = _description # command_line_loader = IPControllerAppConfigLoader default_config_file_name = default_config_file_name - auto_create_cluster_dir = True classes = [ClusterDir, StreamSession, HubFactory, TaskScheduler, HeartMonitor, SQLiteDB] + maybe_mongo + auto_create_cluster_dir = Bool(True, config=True, + help="Whether to create cluster_dir if it exists.") reuse_files = Bool(False, config=True, help='Whether to reuse existing json connection files [default: False]' ) diff --git a/IPython/parallel/apps/ipengineapp.py b/IPython/parallel/apps/ipengineapp.py index bfd74c9..a31ad91 100755 --- a/IPython/parallel/apps/ipengineapp.py +++ b/IPython/parallel/apps/ipengineapp.py @@ -106,7 +106,7 @@ class IPEngineApp(ClusterApplication): default_config_file_name = default_config_file_name classes = List([ClusterDir, StreamSession, EngineFactory, Kernel, MPI]) - auto_create_cluster_dir = Bool(False, config=True, + auto_create_cluster_dir = Bool(False, help="whether to create the cluster_dir if it doesn't exist") startup_script = Unicode(u'', config=True, @@ -178,7 +178,6 @@ class IPEngineApp(ClusterApplication): self.cluster_dir.security_dir, self.url_file_name ) - def init_engine(self): # This is the working dir by now. sys.path.insert(0, '')