##// END OF EJS Templates
restore auto_create behavior
MinRK -
Show More
@@ -72,26 +72,31 b' class ClusterDir(Configurable):'
72 log_dir = Unicode(u'')
72 log_dir = Unicode(u'')
73 pid_dir = Unicode(u'')
73 pid_dir = Unicode(u'')
74
74
75 auto_create = Bool(False,
76 help="""Whether to automatically create the ClusterDirectory if it does
77 not exist""")
78 overwrite = Bool(False,
79 help="""Whether to overwrite existing config files""")
75 location = Unicode(u'', config=True,
80 location = Unicode(u'', config=True,
76 help="""Set the cluster dir. This overrides the logic used by the
81 help="""Set the cluster dir. This overrides the logic used by the
77 `profile` option.""",
82 `profile` option.""",
78 )
83 )
79 profile = Unicode(u'default',
84 profile = Unicode(u'default', config=True,
80 help="""The string name of the profile to be used. This determines the name
85 help="""The string name of the profile to be used. This determines the name
81 of the cluster dir as: cluster_<profile>. The default profile is named
86 of the cluster dir as: cluster_<profile>. The default profile is named
82 'default'. The cluster directory is resolve this way if the
87 'default'. The cluster directory is resolve this way if the
83 `cluster_dir` option is not used.""", config=True
88 `cluster_dir` option is not used."""
84 )
89 )
85 auto_create = Bool(False,
86 help="""Whether to automatically create the ClusterDirectory if it does
87 not exist""")
88 overwrite = Bool(False,
89 help="""Whether to overwrite existing config files""")
90
90
91 _location_isset = Bool(False) # flag for detecting multiply set location
91 _location_isset = Bool(False) # flag for detecting multiply set location
92 _new_dir = Bool(False) # flag for whether a new dir was created
92 _new_dir = Bool(False) # flag for whether a new dir was created
93
93
94 def __init__(self, **kwargs):
94 def __init__(self, **kwargs):
95 # make sure auto_create,overwrite are set *before* location
96 for name in ('auto_create', 'overwrite'):
97 v = kwargs.pop(name, None)
98 if v is not None:
99 setattr(self, name, v)
95 super(ClusterDir, self).__init__(**kwargs)
100 super(ClusterDir, self).__init__(**kwargs)
96 if not self.location:
101 if not self.location:
97 self._profile_changed('profile', 'default', self.profile)
102 self._profile_changed('profile', 'default', self.profile)
@@ -101,7 +106,7 b' class ClusterDir(Configurable):'
101 raise RuntimeError("Cannot set ClusterDir more than once.")
106 raise RuntimeError("Cannot set ClusterDir more than once.")
102 self._location_isset = True
107 self._location_isset = True
103 if not os.path.isdir(new):
108 if not os.path.isdir(new):
104 if self.auto_create:
109 if self.auto_create:# or self.config.ClusterDir.auto_create:
105 os.makedirs(new)
110 os.makedirs(new)
106 self._new_dir = True
111 self._new_dir = True
107 else:
112 else:
@@ -388,7 +393,16 b' class ClusterApplication(BaseIPythonApplication):'
388 ``True``, then create the new cluster dir in the IPython directory.
393 ``True``, then create the new cluster dir in the IPython directory.
389 4. If all fails, then raise :class:`ClusterDirError`.
394 4. If all fails, then raise :class:`ClusterDirError`.
390 """
395 """
391 self.cluster_dir = ClusterDir(config=self.config, auto_create=self.auto_create_cluster_dir)
396 try:
397 self.cluster_dir = ClusterDir(auto_create=self.auto_create_cluster_dir, config=self.config)
398 except ClusterDirError as e:
399 self.log.fatal("Error initializing cluster dir: %s"%e)
400 self.log.fatal("A cluster dir must be created before running this command.")
401 self.log.fatal("Do 'ipcluster create -h' or 'ipcluster list -h' for more "
402 "information about creating and listing cluster dirs."
403 )
404 self.exit(1)
405
392 if self.cluster_dir._new_dir:
406 if self.cluster_dir._new_dir:
393 self.log.info('Creating new cluster dir: %s' % \
407 self.log.info('Creating new cluster dir: %s' % \
394 self.cluster_dir.location)
408 self.cluster_dir.location)
@@ -398,6 +412,7 b' class ClusterApplication(BaseIPythonApplication):'
398
412
399 def initialize(self, argv=None):
413 def initialize(self, argv=None):
400 """initialize the app"""
414 """initialize the app"""
415 self.init_crash_handler()
401 self.parse_command_line(argv)
416 self.parse_command_line(argv)
402 cl_config = self.config
417 cl_config = self.config
403 self.init_clusterdir()
418 self.init_clusterdir()
@@ -421,8 +436,7 b' class ClusterApplication(BaseIPythonApplication):'
421 def load_config_file(self, filename, path=None):
436 def load_config_file(self, filename, path=None):
422 """Load a .py based config file by filename and path."""
437 """Load a .py based config file by filename and path."""
423 # use config.application.Application.load_config
438 # use config.application.Application.load_config
424 # instead of inflexible
439 # instead of inflexible core.newapplication.BaseIPythonApplication.load_config
425 # core.newapplication.BaseIPythonApplication.load_config
426 return Application.load_config_file(self, filename, path=path)
440 return Application.load_config_file(self, filename, path=path)
427 #
441 #
428 # def load_default_config_file(self):
442 # def load_default_config_file(self):
@@ -204,15 +204,21 b' stop_aliases = dict('
204 class IPClusterStop(ClusterApplication):
204 class IPClusterStop(ClusterApplication):
205 name = u'ipcluster'
205 name = u'ipcluster'
206 description = stop_help
206 description = stop_help
207 auto_create_cluster_dir = Bool(False,
207 auto_create_cluster_dir = Bool(False)
208 help="whether to create the cluster_dir if it doesn't exist")
209 default_config_file_name = default_config_file_name
208 default_config_file_name = default_config_file_name
210
209
211 signal = Int(signal.SIGINT, config=True,
210 signal = Int(signal.SIGINT, config=True,
212 help="signal to use for stopping processes.")
211 help="signal to use for stopping processes.")
213
212
214 aliases = Dict(stop_aliases)
213 aliases = Dict(stop_aliases)
215
214
215 def init_clusterdir(self):
216 try:
217 super(IPClusterStop, self).init_clusterdir()
218 except ClusterDirError as e:
219 self.log.fatal("Failed ClusterDir init: %s"%e)
220 self.exit(1)
221
216 def start(self):
222 def start(self):
217 """Start the app for the stop subcommand."""
223 """Start the app for the stop subcommand."""
218 try:
224 try:
@@ -425,17 +431,6 b' class IPClusterStart(IPClusterEngines):'
425 # flags = Dict(flags)
431 # flags = Dict(flags)
426 aliases = Dict(start_aliases)
432 aliases = Dict(start_aliases)
427
433
428 def init_clusterdir(self):
429 try:
430 super(IPClusterStart, self).init_clusterdir()
431 except ClusterDirError:
432 raise ClusterDirError(
433 "Could not find a cluster directory. A cluster dir must "
434 "be created before running 'ipcluster start'. Do "
435 "'ipcluster create -h' or 'ipcluster list -h' for more "
436 "information about creating and listing cluster dirs."
437 )
438
439 def init_launchers(self):
434 def init_launchers(self):
440 self.controller_launcher = self.build_launcher(self.controller_launcher_class)
435 self.controller_launcher = self.build_launcher(self.controller_launcher_class)
441 self.engine_launcher = self.build_launcher(self.engine_launcher_class)
436 self.engine_launcher = self.build_launcher(self.engine_launcher_class)
@@ -110,9 +110,10 b' class IPControllerApp(ClusterApplication):'
110 description = _description
110 description = _description
111 # command_line_loader = IPControllerAppConfigLoader
111 # command_line_loader = IPControllerAppConfigLoader
112 default_config_file_name = default_config_file_name
112 default_config_file_name = default_config_file_name
113 auto_create_cluster_dir = True
114 classes = [ClusterDir, StreamSession, HubFactory, TaskScheduler, HeartMonitor, SQLiteDB] + maybe_mongo
113 classes = [ClusterDir, StreamSession, HubFactory, TaskScheduler, HeartMonitor, SQLiteDB] + maybe_mongo
115
114
115 auto_create_cluster_dir = Bool(True, config=True,
116 help="Whether to create cluster_dir if it exists.")
116 reuse_files = Bool(False, config=True,
117 reuse_files = Bool(False, config=True,
117 help='Whether to reuse existing json connection files [default: False]'
118 help='Whether to reuse existing json connection files [default: False]'
118 )
119 )
@@ -106,7 +106,7 b' class IPEngineApp(ClusterApplication):'
106 default_config_file_name = default_config_file_name
106 default_config_file_name = default_config_file_name
107 classes = List([ClusterDir, StreamSession, EngineFactory, Kernel, MPI])
107 classes = List([ClusterDir, StreamSession, EngineFactory, Kernel, MPI])
108
108
109 auto_create_cluster_dir = Bool(False, config=True,
109 auto_create_cluster_dir = Bool(False,
110 help="whether to create the cluster_dir if it doesn't exist")
110 help="whether to create the cluster_dir if it doesn't exist")
111
111
112 startup_script = Unicode(u'', config=True,
112 startup_script = Unicode(u'', config=True,
@@ -178,7 +178,6 b' class IPEngineApp(ClusterApplication):'
178 self.cluster_dir.security_dir,
178 self.cluster_dir.security_dir,
179 self.url_file_name
179 self.url_file_name
180 )
180 )
181
182 def init_engine(self):
181 def init_engine(self):
183 # This is the working dir by now.
182 # This is the working dir by now.
184 sys.path.insert(0, '')
183 sys.path.insert(0, '')
General Comments 0
You need to be logged in to leave comments. Login now