##// END OF EJS Templates
Work on ipcontroller....
Brian Granger -
Show More
@@ -25,10 +25,12 b' Notes'
25
25
26 import logging
26 import logging
27 import os
27 import os
28
28 import sys
29 import sys
29 import traceback
30 import traceback
30 from copy import deepcopy
31 from copy import deepcopy
31
32
33 from IPython.core import release
32 from IPython.utils.genutils import get_ipython_dir, filefind
34 from IPython.utils.genutils import get_ipython_dir, filefind
33 from IPython.config.loader import (
35 from IPython.config.loader import (
34 PyFileConfigLoader,
36 PyFileConfigLoader,
@@ -42,7 +44,7 b' from IPython.config.loader import ('
42 #-----------------------------------------------------------------------------
44 #-----------------------------------------------------------------------------
43
45
44
46
45 class IPythonArgParseConfigLoader(ArgParseConfigLoader):
47 class BaseAppArgParseConfigLoader(ArgParseConfigLoader):
46 """Default command line options for IPython based applications."""
48 """Default command line options for IPython based applications."""
47
49
48 def _add_other_arguments(self):
50 def _add_other_arguments(self):
@@ -77,6 +79,7 b' class Application(object):'
77
79
78 config_file_name = 'ipython_config.py'
80 config_file_name = 'ipython_config.py'
79 name = 'ipython'
81 name = 'ipython'
82 description = 'IPython: an enhanced interactive Python shell.'
80 default_log_level = logging.WARN
83 default_log_level = logging.WARN
81
84
82
85
@@ -141,6 +144,7 b' class Application(object):'
141 """
144 """
142 self.default_config = Config()
145 self.default_config = Config()
143 self.default_config.Global.ipythondir = get_ipython_dir()
146 self.default_config.Global.ipythondir = get_ipython_dir()
147 self.default_config.Global.log_level = self.log_level
144
148
145 def log_default_config(self):
149 def log_default_config(self):
146 self.log.debug('Default config loaded:')
150 self.log.debug('Default config loaded:')
@@ -155,7 +159,10 b' class Application(object):'
155
159
156 def create_command_line_config(self):
160 def create_command_line_config(self):
157 """Create and return a command line config loader."""
161 """Create and return a command line config loader."""
158 return IPythonArgParseConfigLoader(description=self.name)
162 return BaseAppArgParseConfigLoader(
163 description=self.description,
164 version=release.version
165 )
159
166
160 def pre_load_command_line_config(self):
167 def pre_load_command_line_config(self):
161 """Do actions just before loading the command line config."""
168 """Do actions just before loading the command line config."""
@@ -331,4 +338,93 b' class Application(object):'
331 self.abort()
338 self.abort()
332 elif action == 'exit':
339 elif action == 'exit':
333 self.exit()
340 self.exit()
334 No newline at end of file
341
342
343 class AppWithDirArgParseConfigLoader(ArgParseConfigLoader):
344 """Default command line options for IPython based applications."""
345
346 def _add_other_arguments(self):
347 self.parser.add_argument('-ipythondir', '--ipython-dir',
348 dest='Global.ipythondir',type=str,
349 help='Set to override default location of Global.ipythondir.',
350 default=NoConfigDefault,
351 metavar='Global.ipythondir')
352 self.parser.add_argument('-p','-profile', '--profile',
353 dest='Global.profile',type=str,
354 help='The string name of the ipython profile to be used.',
355 default=NoConfigDefault,
356 metavar='Global.profile')
357 self.parser.add_argument('-log_level', '--log-level',
358 dest="Global.log_level",type=int,
359 help='Set the log level (0,10,20,30,40,50). Default is 30.',
360 default=NoConfigDefault)
361 self.parser.add_argument('-app_dir', '--app-dir',
362 dest='Global.app_dir',type=str,
363 help='Set the application directory where everything for this '
364 'application will be found (including the config file).',
365 default=NoConfigDefault,
366 metavar='Global.app_dir')
367
368
369 class ApplicationWithDir(Application):
370
371 name = 'appname'
372 description = 'Application: foo and bar it.'
373 config_file_name = 'appname_config.py'
374 default_log_level = logging.WARN
375
376 def create_default_config(self):
377 super(ApplicationWithDir, self).create_default_config()
378 self.default_config.Global.profile = 'default'
379 self.default_config.Global.app_dir = ''
380
381 def create_command_line_config(self):
382 """Create and return a command line config loader."""
383 return AppWithDirArgParseConfigLoader(
384 description=self.description,
385 version=release.version
386 )
387
388 def find_config_file_name(self):
389 """Find the config file name for this application."""
390 self.find_app_dir()
391 self.create_app_dir()
392
393 def find_app_dir(self):
394 """This resolves into full paths, the app directory.
395
396 This method must set ``self.app_dir`` to the full path of
397 the directory.
398 """
399 # Instead, first look for an explicit app_dir
400 try:
401 self.app_dir = self.command_line_config.Global.app_dir
402 except AttributeError:
403 self.app_dir = self.default_config.Global.app_dir
404 self.app_dir = os.path.expandvars(os.path.expanduser(self.app_dir))
405 if not self.app_dir:
406 # Then look for a profile
407 try:
408 self.profile = self.command_line_config.Global.profile
409 except AttributeError:
410 self.profile = self.default_config.Global.profile
411 app_dir_name = 'cluster_' + self.profile
412 try_this = os.path.join(os.getcwd(), app_dir_name)
413 if os.path.isdir(try_this):
414 self.app_dir = try_this
415 else:
416 self.app_dir = os.path.join(self.ipythondir, app_dir_name)
417 # These have to be set because they could be different from the one
418 # that we just computed. Because command line has the highest
419 # priority, this will always end up in the master_config.
420 self.default_config.Global.app_dir = self.app_dir
421 self.command_line_config.Global.app_dir = self.app_dir
422
423 def create_app_dir(self):
424 """Make sure that the cluster, security and log dirs exist."""
425 if not os.path.isdir(self.app_dir):
426 os.makedirs(self.app_dir, mode=0777)
427
428 def find_config_file_paths(self):
429 """Set the search paths for resolving the config file."""
430 self.config_file_paths = (self.app_dir,)
@@ -28,7 +28,7 b' import os'
28 import sys
28 import sys
29 import warnings
29 import warnings
30
30
31 from IPython.core.application import Application, IPythonArgParseConfigLoader
31 from IPython.core.application import Application, BaseAppArgParseConfigLoader
32 from IPython.core import release
32 from IPython.core import release
33 from IPython.core.iplib import InteractiveShell
33 from IPython.core.iplib import InteractiveShell
34 from IPython.config.loader import (
34 from IPython.config.loader import (
@@ -283,20 +283,23 b' cl_args = ('
283 # # These are only here to get the proper deprecation warnings
283 # # These are only here to get the proper deprecation warnings
284 (('-pylab',), dict(
284 (('-pylab',), dict(
285 action='store_true', dest='Global.pylab', default=NoConfigDefault,
285 action='store_true', dest='Global.pylab', default=NoConfigDefault,
286 help="Disabled. Pylab has been disabled until matplotlib supports this version of IPython.")
286 help="Disabled. Pylab has been disabled until matplotlib "
287 "supports this version of IPython.")
287 )
288 )
288 )
289 )
289
290
290
291
291 class IPythonAppCLConfigLoader(IPythonArgParseConfigLoader):
292 class IPythonAppCLConfigLoader(BaseAppArgParseConfigLoader):
292
293
293 arguments = cl_args
294 arguments = cl_args
294
295
295
296
296 _default_config_file_name = 'ipython_config.py'
297 _default_config_file_name = 'ipython_config.py'
297
298
299
298 class IPythonApp(Application):
300 class IPythonApp(Application):
299 name = 'ipython'
301 name = 'ipython'
302 description = 'IPython: an enhanced interactive Python shell.'
300 config_file_name = _default_config_file_name
303 config_file_name = _default_config_file_name
301
304
302 def create_default_config(self):
305 def create_default_config(self):
@@ -313,11 +316,6 b' class IPythonApp(Application):'
313 # By default always interact by starting the IPython mainloop.
316 # By default always interact by starting the IPython mainloop.
314 self.default_config.Global.interact = True
317 self.default_config.Global.interact = True
315
318
316 # Let the parent class set the default, but each time log_level
317 # changes from config, we need to update self.log_level as that is
318 # what updates the actual log level in self.log.
319 self.default_config.Global.log_level = self.log_level
320
321 # No GUI integration by default
319 # No GUI integration by default
322 self.default_config.Global.wthread = False
320 self.default_config.Global.wthread = False
323 self.default_config.Global.q4thread = False
321 self.default_config.Global.q4thread = False
@@ -326,8 +324,9 b' class IPythonApp(Application):'
326 def create_command_line_config(self):
324 def create_command_line_config(self):
327 """Create and return a command line config loader."""
325 """Create and return a command line config loader."""
328 return IPythonAppCLConfigLoader(
326 return IPythonAppCLConfigLoader(
329 description=ipython_desc,
327 description=self.description,
330 version=release.version)
328 version=release.version
329 )
331
330
332 def post_load_command_line_config(self):
331 def post_load_command_line_config(self):
333 """Do actions after loading cl config."""
332 """Do actions after loading cl config."""
@@ -540,7 +539,7 b' def load_default_config(ipythondir=None):'
540
539
541
540
542 def launch_new_instance():
541 def launch_new_instance():
543 """Create a run a full blown IPython instance"""
542 """Create and run a full blown IPython instance"""
544 app = IPythonApp()
543 app = IPythonApp()
545 app.start()
544 app.start()
546
545
@@ -26,7 +26,11 b' from twisted.python import log'
26
26
27 from IPython.config.loader import Config, NoConfigDefault
27 from IPython.config.loader import Config, NoConfigDefault
28
28
29 from IPython.core.application import Application, IPythonArgParseConfigLoader
29 from IPython.core.application import (
30 ApplicationWithDir,
31 BaseAppArgParseConfigLoader
32 )
33
30 from IPython.core import release
34 from IPython.core import release
31
35
32 from IPython.utils.traitlets import Int, Str, Bool, Instance
36 from IPython.utils.traitlets import Int, Str, Bool, Instance
@@ -152,25 +156,22 b' cl_args = ('
152 (('-r','--reuse-furls'), dict(
156 (('-r','--reuse-furls'), dict(
153 action='store_true', dest='Global.reuse_furls', default=NoConfigDefault,
157 action='store_true', dest='Global.reuse_furls', default=NoConfigDefault,
154 help='Try to reuse all FURL files.')
158 help='Try to reuse all FURL files.')
155 ),
159 )
156 (('-cluster_dir', '--cluster-dir',), dict(
157 type=str, dest='Global.cluster_dir', default=NoConfigDefault,
158 help='Absolute or relative path to the cluster directory.',
159 metavar='Global.cluster_dir')
160 ),
161 )
160 )
162
161
163
162
164 class IPControllerAppCLConfigLoader(IPythonArgParseConfigLoader):
163 class IPControllerAppCLConfigLoader(BaseAppArgParseConfigLoader):
165
164
166 arguments = cl_args
165 arguments = cl_args
167
166
168
167
169 _default_config_file_name = 'ipcontroller_config.py'
168 _default_config_file_name = 'ipcontroller_config.py'
170
169
171 class IPControllerApp(Application):
170
171 class IPControllerApp(ApplicationWithDir):
172
172
173 name = 'ipcontroller'
173 name = 'ipcontroller'
174 description = 'Start the IPython controller for parallel computing.'
174 config_file_name = _default_config_file_name
175 config_file_name = _default_config_file_name
175 default_log_level = logging.DEBUG
176 default_log_level = logging.DEBUG
176
177
@@ -178,71 +179,16 b' class IPControllerApp(Application):'
178 super(IPControllerApp, self).create_default_config()
179 super(IPControllerApp, self).create_default_config()
179 self.default_config.Global.reuse_furls = False
180 self.default_config.Global.reuse_furls = False
180 self.default_config.Global.import_statements = []
181 self.default_config.Global.import_statements = []
181 self.default_config.Global.profile = 'default'
182 self.default_config.Global.log_dir_name = 'log'
182 self.default_config.Global.log_dir_name = 'log'
183 self.default_config.Global.security_dir_name = 'security'
183 self.default_config.Global.security_dir_name = 'security'
184 self.default_config.Global.log_to_file = False
184 self.default_config.Global.log_to_file = False
185 # Resolve the default cluster_dir using the default profile
186 self.default_config.Global.cluster_dir = ''
187
188 def create_command_line_config(self):
189 """Create and return a command line config loader."""
190
191 return IPControllerAppCLConfigLoader(
192 description="Start an IPython controller",
193 version=release.version)
194
195 def find_config_file_name(self):
196 """Find the config file name for this application."""
197 self.find_cluster_dir()
198 self.create_cluster_dir()
199
200 def find_cluster_dir(self):
201 """This resolves into full paths, the various cluster directories.
202
203 This method must set ``self.cluster_dir`` to the full paths of
204 the directory.
205 """
206 # Ignore self.command_line_config.Global.config_file
207 # Instead, first look for an explicit cluster_dir
208 try:
209 self.cluster_dir = self.command_line_config.Global.cluster_dir
210 except AttributeError:
211 self.cluster_dir = self.default_config.Global.cluster_dir
212 self.cluster_dir = os.path.expandvars(os.path.expanduser(self.cluster_dir))
213 if not self.cluster_dir:
214 # Then look for a profile
215 try:
216 self.profile = self.command_line_config.Global.profile
217 except AttributeError:
218 self.profile = self.default_config.Global.profile
219 cluster_dir_name = 'cluster_' + self.profile
220 try_this = os.path.join(os.getcwd(), cluster_dir_name)
221 if os.path.isdir(try_this):
222 self.cluster_dir = try_this
223 else:
224 self.cluster_dir = os.path.join(self.ipythondir, cluster_dir_name)
225 # These have to be set because they could be different from the one
226 # that we just computed. Because command line has the highest
227 # priority, this will always end up in the master_config.
228 self.default_config.Global.cluster_dir = self.cluster_dir
229 self.command_line_config.Global.cluster_dir = self.cluster_dir
230
231 def create_cluster_dir(self):
232 """Make sure that the cluster, security and log dirs exist."""
233 if not os.path.isdir(self.cluster_dir):
234 os.makedirs(self.cluster_dir, mode=0777)
235
236 def find_config_file_paths(self):
237 """Set the search paths for resolving the config file."""
238 self.config_file_paths = (self.cluster_dir,)
239
185
240 def pre_construct(self):
186 def pre_construct(self):
241 # Now set the security_dir and log_dir and create them. We use
187 # Now set the security_dir and log_dir and create them. We use
242 # the names an construct the absolute paths.
188 # the names an construct the absolute paths.
243 security_dir = os.path.join(self.master_config.Global.cluster_dir,
189 security_dir = os.path.join(self.master_config.Global.app_dir,
244 self.master_config.Global.security_dir_name)
190 self.master_config.Global.security_dir_name)
245 log_dir = os.path.join(self.master_config.Global.cluster_dir,
191 log_dir = os.path.join(self.master_config.Global.app_dir,
246 self.master_config.Global.log_dir_name)
192 self.master_config.Global.log_dir_name)
247 if not os.path.isdir(security_dir):
193 if not os.path.isdir(security_dir):
248 os.mkdir(security_dir, 0700)
194 os.mkdir(security_dir, 0700)
@@ -255,7 +201,7 b' class IPControllerApp(Application):'
255 self.log_dir = self.master_config.Global.log_dir = log_dir
201 self.log_dir = self.master_config.Global.log_dir = log_dir
256
202
257 # Now setup reuse_furls
203 # Now setup reuse_furls
258 if hasattr(self.master_config.Global.reuse_furls):
204 if hasattr(self.master_config.Global, 'reuse_furls'):
259 self.master_config.FCClientServiceFactory.reuse_furls = \
205 self.master_config.FCClientServiceFactory.reuse_furls = \
260 self.master_config.Global.reuse_furls
206 self.master_config.Global.reuse_furls
261 self.master_config.FCEngineServiceFactory.reuse_furls = \
207 self.master_config.FCEngineServiceFactory.reuse_furls = \
@@ -305,6 +251,8 b' class IPControllerApp(Application):'
305 self.main_service.startService()
251 self.main_service.startService()
306 reactor.run()
252 reactor.run()
307
253
308 if __name__ == '__main__':
254
255 def launch_new_instance():
256 """Create and run the IPython controller"""
309 app = IPControllerApp()
257 app = IPControllerApp()
310 app.start()
258 app.start()
@@ -1,20 +1,18 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3
3
4 __docformat__ = "restructuredtext en"
4 #-----------------------------------------------------------------------------
5
5 # Copyright (C) 2008-2009 The IPython Development Team
6 #-------------------------------------------------------------------------------
7 # Copyright (C) 2008 The IPython Development Team
8 #
6 #
9 # Distributed under the terms of the BSD License. The full license is in
7 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
8 # the file COPYING, distributed as part of this software.
11 #-------------------------------------------------------------------------------
9 #-----------------------------------------------------------------------------
12
10
13 #-------------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
14 # Imports
12 # Imports
15 #-------------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
16
15
17 if __name__ == '__main__':
16 from IPython.kernel.ipcontrollerapp import launch_new_instance
18 from IPython.kernel.scripts import ipcontroller
19 ipcontroller.main()
20
17
18 launch_new_instance()
@@ -169,7 +169,7 b" if 'setuptools' in sys.modules:"
169 'console_scripts': [
169 'console_scripts': [
170 'ipython = IPython.core.ipapp:launch_new_instance',
170 'ipython = IPython.core.ipapp:launch_new_instance',
171 'pycolor = IPython.utils.PyColorize:main',
171 'pycolor = IPython.utils.PyColorize:main',
172 'ipcontroller = IPython.kernel.scripts.ipcontroller:main',
172 'ipcontroller = IPython.kernel.ipcontrollerapp:launch_new_instance',
173 'ipengine = IPython.kernel.scripts.ipengine:main',
173 'ipengine = IPython.kernel.scripts.ipengine:main',
174 'ipcluster = IPython.kernel.scripts.ipcluster:main',
174 'ipcluster = IPython.kernel.scripts.ipcluster:main',
175 'ipythonx = IPython.frontend.wx.ipythonx:main',
175 'ipythonx = IPython.frontend.wx.ipythonx:main',
General Comments 0
You need to be logged in to leave comments. Login now