##// END OF EJS Templates
restore auto_create behavior
MinRK -
Show More
@@ -72,26 +72,31 b' class ClusterDir(Configurable):'
72 72 log_dir = Unicode(u'')
73 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 80 location = Unicode(u'', config=True,
76 81 help="""Set the cluster dir. This overrides the logic used by the
77 82 `profile` option.""",
78 83 )
79 profile = Unicode(u'default',
84 profile = Unicode(u'default', config=True,
80 85 help="""The string name of the profile to be used. This determines the name
81 86 of the cluster dir as: cluster_<profile>. The default profile is named
82 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 91 _location_isset = Bool(False) # flag for detecting multiply set location
92 92 _new_dir = Bool(False) # flag for whether a new dir was created
93 93
94 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 100 super(ClusterDir, self).__init__(**kwargs)
96 101 if not self.location:
97 102 self._profile_changed('profile', 'default', self.profile)
@@ -101,7 +106,7 b' class ClusterDir(Configurable):'
101 106 raise RuntimeError("Cannot set ClusterDir more than once.")
102 107 self._location_isset = True
103 108 if not os.path.isdir(new):
104 if self.auto_create:
109 if self.auto_create:# or self.config.ClusterDir.auto_create:
105 110 os.makedirs(new)
106 111 self._new_dir = True
107 112 else:
@@ -388,7 +393,16 b' class ClusterApplication(BaseIPythonApplication):'
388 393 ``True``, then create the new cluster dir in the IPython directory.
389 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 406 if self.cluster_dir._new_dir:
393 407 self.log.info('Creating new cluster dir: %s' % \
394 408 self.cluster_dir.location)
@@ -398,6 +412,7 b' class ClusterApplication(BaseIPythonApplication):'
398 412
399 413 def initialize(self, argv=None):
400 414 """initialize the app"""
415 self.init_crash_handler()
401 416 self.parse_command_line(argv)
402 417 cl_config = self.config
403 418 self.init_clusterdir()
@@ -421,8 +436,7 b' class ClusterApplication(BaseIPythonApplication):'
421 436 def load_config_file(self, filename, path=None):
422 437 """Load a .py based config file by filename and path."""
423 438 # use config.application.Application.load_config
424 # instead of inflexible
425 # core.newapplication.BaseIPythonApplication.load_config
439 # instead of inflexible core.newapplication.BaseIPythonApplication.load_config
426 440 return Application.load_config_file(self, filename, path=path)
427 441 #
428 442 # def load_default_config_file(self):
@@ -204,15 +204,21 b' stop_aliases = dict('
204 204 class IPClusterStop(ClusterApplication):
205 205 name = u'ipcluster'
206 206 description = stop_help
207 auto_create_cluster_dir = Bool(False,
208 help="whether to create the cluster_dir if it doesn't exist")
207 auto_create_cluster_dir = Bool(False)
209 208 default_config_file_name = default_config_file_name
210 209
211 210 signal = Int(signal.SIGINT, config=True,
212 211 help="signal to use for stopping processes.")
213 212
214 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 222 def start(self):
217 223 """Start the app for the stop subcommand."""
218 224 try:
@@ -425,17 +431,6 b' class IPClusterStart(IPClusterEngines):'
425 431 # flags = Dict(flags)
426 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 434 def init_launchers(self):
440 435 self.controller_launcher = self.build_launcher(self.controller_launcher_class)
441 436 self.engine_launcher = self.build_launcher(self.engine_launcher_class)
@@ -110,9 +110,10 b' class IPControllerApp(ClusterApplication):'
110 110 description = _description
111 111 # command_line_loader = IPControllerAppConfigLoader
112 112 default_config_file_name = default_config_file_name
113 auto_create_cluster_dir = True
114 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 117 reuse_files = Bool(False, config=True,
117 118 help='Whether to reuse existing json connection files [default: False]'
118 119 )
@@ -106,7 +106,7 b' class IPEngineApp(ClusterApplication):'
106 106 default_config_file_name = default_config_file_name
107 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 110 help="whether to create the cluster_dir if it doesn't exist")
111 111
112 112 startup_script = Unicode(u'', config=True,
@@ -178,7 +178,6 b' class IPEngineApp(ClusterApplication):'
178 178 self.cluster_dir.security_dir,
179 179 self.url_file_name
180 180 )
181
182 181 def init_engine(self):
183 182 # This is the working dir by now.
184 183 sys.path.insert(0, '')
General Comments 0
You need to be logged in to leave comments. Login now