Skip to content
Browse files

restore auto_create behavior

  • Loading branch information...
1 parent ad7f39d commit a618140e27c7f278b87f3109ed7159f26af75bd2 @minrk committed May 24, 2011
View
36 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_<profile>. 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 @@ def _location_changed(self, name, old, new):
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 @@ def init_clusterdir(self):
``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 @@ def init_clusterdir(self):
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 @@ def to_work_dir(self):
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):
View
23 IPython/parallel/apps/ipclusterapp.py
@@ -204,15 +204,21 @@ def initialize(self, argv=None):
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 @@ def _classes_default(self,):
# 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)
View
3 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]'
)
View
3 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 @@ def find_url_file(self):
self.cluster_dir.security_dir,
self.url_file_name
)
-
def init_engine(self):
# This is the working dir by now.
sys.path.insert(0, '')

0 comments on commit a618140

Please sign in to comment.
Something went wrong with that request. Please try again.