home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyc (Python 2.6) __docformat__ = 'restructuredtext en' import sys sys.path.insert(0, '') from optparse import OptionParser import os import time import tempfile from twisted.application import internet, service from twisted.internet import reactor, error, defer from twisted.python import log from IPython.kernel.fcutil import Tub, UnauthenticatedTub, have_crypto from IPython.kernel.error import SecurityError from IPython.kernel import controllerservice from IPython.kernel.fcutil import check_furl_file_security from IPython.iplib import user_setup from IPython.genutils import get_ipython_dir, get_log_dir, get_security_dir if os.name == 'posix': rc_suffix = '' else: rc_suffix = '.ini' user_setup(get_ipython_dir(), rc_suffix, mode = 'install', interactive = False) get_log_dir() get_security_dir() from IPython.kernel.config import config_manager as kernel_config_manager from IPython.config.cutils import import_item def get_temp_furlfile(filename): return tempfile.mktemp(dir = os.path.dirname(filename), prefix = os.path.basename(filename)) def make_tub(ip, port, secure, cert_file): if secure: if have_crypto: tub = Tub(certFile = cert_file) else: raise SecurityError("\nOpenSSL/pyOpenSSL is not available, so we can't run in secure mode.\nTry running without security using 'ipcontroller -xy'.\n") have_crypto tub = UnauthenticatedTub() if ip == '': strport = 'tcp:%i' % port else: strport = 'tcp:%i:interface=%s' % (port, ip) listener = tub.listenOn(strport) return (tub, listener) def make_client_service(controller_service, config): ip = config['controller']['client_tub']['ip'] port = config['controller']['client_tub'].as_int('port') location = config['controller']['client_tub']['location'] secure = config['controller']['client_tub']['secure'] cert_file = config['controller']['client_tub']['cert_file'] (client_tub, client_listener) = make_tub(ip, port, secure, cert_file) if ip == 'localhost' or ip == '127.0.0.1': location = '127.0.0.1' if not secure: log.msg('WARNING: you are running the controller with no client security') def set_location_and_register(): def register(empty, ref, furl_file): temp_furl_file = get_temp_furlfile(furl_file) client_tub.registerReference(ref, furlFile = temp_furl_file) os.rename(temp_furl_file, furl_file) if location == '': d = client_tub.setLocationAutomatically() else: d = defer.maybeDeferred(client_tub.setLocation, '%s:%i' % (location, client_listener.getPortnum())) for ciname, ci in config['controller']['controller_interfaces'].iteritems(): log.msg('Adapting Controller to interface: %s' % ciname) furl_file = ci['furl_file'] log.msg('Saving furl for interface [%s] to file: %s' % (ciname, furl_file)) check_furl_file_security(furl_file, secure) adapted_controller = import_item(ci['controller_interface'])(controller_service) d.addCallback(register, import_item(ci['fc_interface'])(adapted_controller), furl_file = ci['furl_file']) reactor.callWhenRunning(set_location_and_register) return client_tub def make_engine_service(controller_service, config): ip = config['controller']['engine_tub']['ip'] port = config['controller']['engine_tub'].as_int('port') location = config['controller']['engine_tub']['location'] secure = config['controller']['engine_tub']['secure'] cert_file = config['controller']['engine_tub']['cert_file'] (engine_tub, engine_listener) = make_tub(ip, port, secure, cert_file) if ip == 'localhost' or ip == '127.0.0.1': location = '127.0.0.1' if not secure: log.msg('WARNING: you are running the controller with no engine security') def set_location_and_register(): def register(empty, ref, furl_file): temp_furl_file = get_temp_furlfile(furl_file) engine_tub.registerReference(ref, furlFile = temp_furl_file) os.rename(temp_furl_file, furl_file) if location == '': d = engine_tub.setLocationAutomatically() else: d = defer.maybeDeferred(engine_tub.setLocation, '%s:%i' % (location, engine_listener.getPortnum())) furl_file = config['controller']['engine_furl_file'] engine_fc_interface = import_item(config['controller']['engine_fc_interface']) log.msg('Saving furl for the engine to file: %s' % furl_file) check_furl_file_security(furl_file, secure) fc_controller = engine_fc_interface(controller_service) d.addCallback(register, fc_controller, furl_file = furl_file) reactor.callWhenRunning(set_location_and_register) return engine_tub def start_controller(): config = kernel_config_manager.get_config_obj() logfile = config['controller']['logfile'] if logfile: logfile = logfile + str(os.getpid()) + '.log' try: openLogFile = open(logfile, 'w') openLogFile = sys.stdout else: openLogFile = sys.stdout log.startLogging(openLogFile) cis = config['controller']['import_statement'] if cis: try: exec cis in globals(), locals() log.msg('Error running import_statement: %s' % cis) reuse = config['controller']['reuse_furls'] if not reuse: paths = (config['controller']['engine_furl_file'], config['controller']['controller_interfaces']['task']['furl_file'], config['controller']['controller_interfaces']['multiengine']['furl_file']) for p in paths: if os.path.isfile(p): os.remove(p) continue main_service = service.MultiService() controller_service = controllerservice.ControllerService() controller_service.setServiceParent(main_service) client_service = make_client_service(controller_service, config) client_service.setServiceParent(main_service) engine_service = make_engine_service(controller_service, config) engine_service.setServiceParent(main_service) main_service.startService() reactor.run() def init_config(): parser = OptionParser('ipcontroller [options]\n\nStart an IPython controller.\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.') parser.add_option('--client-ip', type = 'string', dest = 'client_ip', help = 'the IP address or hostname the controller will listen on for client connections') parser.add_option('--client-port', type = 'int', dest = 'client_port', help = 'the port the controller will listen on for client connections') parser.add_option('--client-location', type = 'string', dest = 'client_location', help = 'hostname or ip for clients to connect to') parser.add_option('-x', action = 'store_false', dest = 'client_secure', help = 'turn off all client security') parser.add_option('--client-cert-file', type = 'string', dest = 'client_cert_file', help = 'file to store the client SSL certificate') parser.add_option('--task-furl-file', type = 'string', dest = 'task_furl_file', help = 'file to store the FURL for task clients to connect with') parser.add_option('--multiengine-furl-file', type = 'string', dest = 'multiengine_furl_file', help = 'file to store the FURL for multiengine clients to connect with') parser.add_option('--engine-ip', type = 'string', dest = 'engine_ip', help = 'the IP address or hostname the controller will listen on for engine connections') parser.add_option('--engine-port', type = 'int', dest = 'engine_port', help = 'the port the controller will listen on for engine connections') parser.add_option('--engine-location', type = 'string', dest = 'engine_location', help = 'hostname or ip for engines to connect to') parser.add_option('-y', action = 'store_false', dest = 'engine_secure', help = 'turn off all engine security') parser.add_option('--engine-cert-file', type = 'string', dest = 'engine_cert_file', help = 'file to store the engine SSL certificate') parser.add_option('--engine-furl-file', type = 'string', dest = 'engine_furl_file', help = 'file to store the FURL for engines to connect with') parser.add_option('-l', '--logfile', type = 'string', dest = 'logfile', help = 'log file name (default is stdout)') parser.add_option('-r', action = 'store_true', dest = 'reuse_furls', help = 'try to reuse all furl files') (options, args) = parser.parse_args() config = kernel_config_manager.get_config_obj() if options.client_ip is not None: config['controller']['client_tub']['ip'] = options.client_ip if options.client_port is not None: config['controller']['client_tub']['port'] = options.client_port if options.client_location is not None: config['controller']['client_tub']['location'] = options.client_location if options.client_secure is not None: config['controller']['client_tub']['secure'] = options.client_secure if options.client_cert_file is not None: config['controller']['client_tub']['cert_file'] = options.client_cert_file if options.task_furl_file is not None: config['controller']['controller_interfaces']['task']['furl_file'] = options.task_furl_file if options.multiengine_furl_file is not None: config['controller']['controller_interfaces']['multiengine']['furl_file'] = options.multiengine_furl_file if options.engine_ip is not None: config['controller']['engine_tub']['ip'] = options.engine_ip if options.engine_port is not None: config['controller']['engine_tub']['port'] = options.engine_port if options.engine_location is not None: config['controller']['engine_tub']['location'] = options.engine_location if options.engine_secure is not None: config['controller']['engine_tub']['secure'] = options.engine_secure if options.engine_cert_file is not None: config['controller']['engine_tub']['cert_file'] = options.engine_cert_file if options.engine_furl_file is not None: config['controller']['engine_furl_file'] = options.engine_furl_file if options.reuse_furls is not None: config['controller']['reuse_furls'] = options.reuse_furls if options.logfile is not None: config['controller']['logfile'] = options.logfile kernel_config_manager.update_config_obj(config) def main(): init_config() start_controller() if __name__ == '__main__': main()