home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1885 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.5 KB  |  110 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __docformat__ = 'restructuredtext en'
  5. import sys
  6. sys.path.insert(0, '')
  7. from optparse import OptionParser
  8. import os
  9. from twisted.application import service
  10. from twisted.internet import reactor
  11. from twisted.python import log
  12. from IPython.kernel.fcutil import Tub, UnauthenticatedTub
  13. from IPython.kernel.core.config import config_manager as core_config_manager
  14. from IPython.config.cutils import import_item
  15. from IPython.kernel.engineservice import EngineService
  16. from IPython.iplib import user_setup
  17. from IPython.genutils import get_ipython_dir, get_log_dir, get_security_dir
  18. if os.name == 'posix':
  19.     rc_suffix = ''
  20. else:
  21.     rc_suffix = '.ini'
  22. user_setup(get_ipython_dir(), rc_suffix, mode = 'install', interactive = False)
  23. get_log_dir()
  24. get_security_dir()
  25. from IPython.kernel.config import config_manager as kernel_config_manager
  26. from IPython.kernel.engineconnector import EngineConnector
  27.  
  28. def start_engine():
  29.     global mpi, mpi
  30.     kernel_config = kernel_config_manager.get_config_obj()
  31.     core_config = core_config_manager.get_config_obj()
  32.     mpikey = kernel_config['mpi']['default']
  33.     mpi_import_statement = kernel_config['mpi'].get(mpikey, None)
  34.     if mpi_import_statement is not None:
  35.         
  36.         try:
  37.             exec mpi_import_statement in globals()
  38.         mpi = None
  39.  
  40.     else:
  41.         mpi = None
  42.     logfile = kernel_config['engine']['logfile']
  43.     if logfile:
  44.         logfile = logfile + str(os.getpid()) + '.log'
  45.         
  46.         try:
  47.             openLogFile = open(logfile, 'w')
  48.         openLogFile = sys.stdout
  49.  
  50.     else:
  51.         openLogFile = sys.stdout
  52.     log.startLogging(openLogFile)
  53.     shell_class = import_item(core_config['shell']['shell_class'])
  54.     engine_service = EngineService(shell_class, mpi = mpi)
  55.     shell_import_statement = core_config['shell']['import_statement']
  56.     if shell_import_statement:
  57.         
  58.         try:
  59.             engine_service.execute(shell_import_statement)
  60.         log.msg('Error running import_statement: %s' % shell_import_statement)
  61.  
  62.     
  63.     main_service = service.MultiService()
  64.     engine_service.setServiceParent(main_service)
  65.     tub_service = Tub()
  66.     tub_service.setServiceParent(main_service)
  67.     main_service.startService()
  68.     engine_connector = EngineConnector(tub_service)
  69.     furl_file = kernel_config['engine']['furl_file']
  70.     log.msg('Using furl file: %s' % furl_file)
  71.     
  72.     def call_connect(engine_service, furl_file):
  73.         d = engine_connector.connect_to_controller(engine_service, furl_file)
  74.         
  75.         def handle_error(f):
  76.             print 'error connecting to controller:', f.getErrorMessage()
  77.             reactor.callLater(0.1, reactor.stop)
  78.  
  79.         d.addErrback(handle_error)
  80.  
  81.     reactor.callWhenRunning(call_connect, engine_service, furl_file)
  82.     reactor.run()
  83.  
  84.  
  85. def init_config():
  86.     parser = OptionParser('ipengine [options]\n\nStart an IPython engine.\n\nUse the IPYTHONDIR environment variable to change your IPython directory \nfrom the default of .ipython or _ipython.  The log and security \nsubdirectories of your IPython directory will be used by this script \nfor log files and security files.')
  87.     parser.add_option('--furl-file', type = 'string', dest = 'furl_file', help = 'The filename containing the FURL of the controller')
  88.     parser.add_option('--mpi', type = 'string', dest = 'mpi', help = 'How to enable MPI (mpi4py, pytrilinos, or empty string to disable)')
  89.     parser.add_option('-l', '--logfile', type = 'string', dest = 'logfile', help = 'log file name (default is stdout)')
  90.     (options, args) = parser.parse_args()
  91.     kernel_config = kernel_config_manager.get_config_obj()
  92.     if options.furl_file is not None:
  93.         kernel_config['engine']['furl_file'] = options.furl_file
  94.     
  95.     if options.logfile is not None:
  96.         kernel_config['engine']['logfile'] = options.logfile
  97.     
  98.     if options.mpi is not None:
  99.         kernel_config['mpi']['default'] = options.mpi
  100.     
  101.  
  102.  
  103. def main():
  104.     init_config()
  105.     start_engine()
  106.  
  107. if __name__ == '__main__':
  108.     main()
  109.  
  110.