示例#1
0
class App(web.Application):
    ''' openmdao web application
        extends tornado web app with URL mappings, settings and server manager
    '''

    def __init__(self, secret=None):
        from openmdao.gui.handlers import LoginHandler, LogoutHandler, ExitHandler
        handlers = [
            web.url(r'/login',  LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit',   ExitHandler),
            web.url(r'/',       web.RedirectHandler, {'url':'/projects', 'permanent':False}),           
        ]        
        
        import openmdao.gui.handlers_projectdb as proj
        handlers.extend(proj.handlers)
        
        import openmdao.gui.handlers_workspace as wksp
        handlers.extend(wksp.handlers)
        
        if secret is None:
            secret = os.urandom(1024)
            
        app_path     = os.path.dirname(os.path.abspath(__file__))
        app_settings = { 
            'login_url':         '/login',
            'static_path':       os.path.join(app_path, 'static'),
            'template_path':     os.path.join(app_path, 'templates'),
            'cookie_secret':     secret,
            'debug':             True,
        }
        
        user_dir = get_user_dir()
        
        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)
        
        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)
            
        self.session_manager = TornadoSessionManager(secret,session_dir)
        self.server_manager  = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer')
        
        super(App, self).__init__(handlers, **app_settings)

    def exit(self):
        self.server_manager.cleanup()
        DEBUG('Exit requested, shutting down....\n')
        ioloop.IOLoop.instance().add_timeout(time.time()+5, sys.exit) 
示例#2
0
class App(web.Application):
    ''' Openmdao web application.
        Extends tornado web app with URL mappings, settings and server manager.
    '''
    def __init__(self, secret=None, external=False):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            docpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
        else:
            import openmdao.main
            docpath = os.path.join(os.path.dirname(openmdao.main.__file__),
                                   'docs')

        handlers = [
            web.url(r'/', web.RedirectHandler, {
                'url': '/projects',
                'permanent': False
            }),
            web.url(r'/login', LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit', ExitHandler),
            web.url(r'/docs/plugins/(.*)', PluginDocsHandler,
                    {'route': '/docs/plugins/'}),
            web.url(r'/docs/(.*)', web.StaticFileHandler, {
                'path': docpath,
                'default_filename': 'index.html'
            })
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url': '/login',
            'static_path': os.path.join(app_path, 'static'),
            'template_path': os.path.join(app_path, 'templates'),
            'cookie_secret': secret,
            'debug': True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager = ZMQServerManager(
            'openmdao.gui.consoleserver.ConsoleServer', external)

        # External termination normally only used during GUI testing.
        if sys.platform == 'win32':
            # Fake SIGTERM by polling for a .sigterm file.
            self._exit_requested = False
            self._poller = threading.Thread(target=self._sigterm_poller,
                                            name='SIGTERM poller')
            self._poller.daemon = True
            self._poller.start()
        else:
            signal.signal(signal.SIGTERM, self._sigterm_handler)

        super(App, self).__init__(handlers, **app_settings)

    def _sigterm_poller(self):
        """ On Windows, poll for an external termination request file. """
        sigfile = os.path.join(os.getcwd(), 'SIGTERM.txt')
        while not self._exit_requested:
            time.sleep(1)
            if os.path.exists(sigfile):
                DEBUG('Detected SIGTERM, shutting down...')
                self._shutdown()
                break

    def _sigterm_handler(self, signum, frame):
        """ On Linux/OS X, handle SIGTERM signal. """
        DEBUG('Received SIGTERM, shutting down...')
        self._shutdown()

    def exit(self):
        """ Shutdown. """
        DEBUG('Exit requested, shutting down...')
        if sys.platform == 'win32':
            self._exit_requested = True
            self._poller.join(3)
        self._shutdown()

    def _shutdown(self):
        """ Stop all subprocesses and exit. """
        self.server_manager.cleanup()
        ioloop.IOLoop.instance().add_timeout(time.time() + 5, sys.exit)
示例#3
0
class App(web.Application):
    ''' Openmdao web application.
        Extends tornado web app with URL mappings, settings and server manager.
    '''

    def __init__(self, secret=None, external=False):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            docpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
        else:
            import openmdao.main
            docpath = os.path.join(os.path.dirname(openmdao.main.__file__), 'docs')

        handlers = [
            web.url(r'/',       web.RedirectHandler, {'url': '/projects', 'permanent': False}),
            web.url(r'/login',  LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit',   ExitHandler),
            web.url(r'/docs/plugins/(.*)', PluginDocsHandler, {'route': '/docs/plugins/'}),
            web.url(r'/docs/(.*)', web.StaticFileHandler, {'path': docpath, 'default_filename': 'index.html'}),
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path     = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url':         '/login',
            'static_path':       os.path.join(app_path, 'static'),
            'template_path':     os.path.join(app_path, 'templates'),
            'cookie_secret':     secret,
            'debug':             True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager  = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer', external)

        # External termination normally only used during GUI testing.
        if sys.platform == 'win32':
            # Fake SIGTERM by polling for a .sigterm file.
            self._exit_requested = False
            self._poller = threading.Thread(target=self._sigterm_poller,
                                            name='SIGTERM poller')
            self._poller.daemon = True
            self._poller.start()
        else:
            signal.signal(signal.SIGTERM, self._sigterm_handler)

        super(App, self).__init__(handlers, **app_settings)

    def _sigterm_poller(self):
        """ On Windows, poll for an external termination request file. """
        sigfile = os.path.join(os.getcwd(), 'SIGTERM.txt')
        while not self._exit_requested:
            time.sleep(1)
            if os.path.exists(sigfile):
                DEBUG('Detected SIGTERM, shutting down...')
                self._shutdown()
                break

    def _sigterm_handler(self, signum, frame):
        """ On Linux/OS X, handle SIGTERM signal. """
        DEBUG('Received SIGTERM, shutting down...')
        self._shutdown()

    def exit(self):
        """ Shutdown. """
        DEBUG('Exit requested, shutting down...')
        if sys.platform == 'win32':
            self._exit_requested = True
            self._poller.join(3)
        self._shutdown()

    def _shutdown(self):
        """ Stop all subprocesses and exit. """
        self.server_manager.cleanup()
        ioloop.IOLoop.instance().add_timeout(time.time() + 5, sys.exit)
示例#4
0
class App(web.Application):
    ''' openmdao web application
        extends tornado web app with URL mappings, settings and server manager
    '''
    def __init__(self, secret=None):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            idxpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
            doc_handler = web.StaticFileHandler
            doc_handler_options = {
                'path': idxpath,
                'default_filename': 'index.html'
            }
        else:
            # look for docs online
            import openmdao.util.releaseinfo
            version = openmdao.util.releaseinfo.__version__
            idxpath = 'http://openmdao.org/releases/%s/docs/index.html' % version
            doc_handler = web.RedirectHandler
            doc_handler_options = {'url': idxpath, 'permanent': False}

        handlers = [
            web.url(r'/login', LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit', ExitHandler),
            web.url(r'/docs/plugins/(.*)', PluginDocsHandler,
                    {'route': '/docs/plugins/'}),
            web.url(r'/docs/(.*)', doc_handler, doc_handler_options),
            web.url(r'/', web.RedirectHandler, {
                'url': '/projects',
                'permanent': False
            })
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url': '/login',
            'static_path': os.path.join(app_path, 'static'),
            'template_path': os.path.join(app_path, 'templates'),
            'cookie_secret': secret,
            'debug': True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager = ZMQServerManager(
            'openmdao.gui.consoleserver.ConsoleServer')

        global _MGR
        _MGR = self.server_manager
        signal.signal(signal.SIGTERM, self._sigterm_handler)
        super(App, self).__init__(handlers, **app_settings)

    def _sigterm_handler(self, signum, frame):
        DEBUG('Received SIGTERM, shutting down....\n')
        _MGR.cleanup()
        ioloop.IOLoop.instance().add_timeout(time.time() + 5, sys.exit)

    def exit(self):
        self.server_manager.cleanup()
        DEBUG('Exit requested, shutting down....\n')
        ioloop.IOLoop.instance().add_timeout(time.time() + 5, sys.exit)
示例#5
0
class App(web.Application):
    ''' openmdao web application
        extends tornado web app with URL mappings, settings and server manager
    '''

    def __init__(self, secret=None):
        # locate the docs, so that the /docs url will point to the appropriate
        # docs, either for the current release or the current development build
        if is_dev_build():
            idxpath = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs',
                                   '_build', 'html')
            doc_handler = web.StaticFileHandler
            doc_handler_options = { 'path': idxpath, 'default_filename': 'index.html' }
        else:
            # look for docs online
            import openmdao.util.releaseinfo
            version = openmdao.util.releaseinfo.__version__
            idxpath = 'http://openmdao.org/releases/%s/docs/index.html' % version
            doc_handler = web.RedirectHandler
            doc_handler_options = { 'url': idxpath, 'permanent': False }
            
        handlers = [
            web.url(r'/login',  LoginHandler),
            web.url(r'/logout', LogoutHandler),
            web.url(r'/exit',   ExitHandler),
            web.url(r'/docs/plugins/(.*)',  PluginDocsHandler, { 'route': '/docs/plugins/' }),
            web.url(r'/docs/(.*)',  doc_handler, doc_handler_options ),
            web.url(r'/',       web.RedirectHandler, { 'url':'/projects', 'permanent':False })
        ]
        handlers.extend(proj.handlers)
        handlers.extend(wksp.handlers)

        if secret is None:
            secret = os.urandom(1024)

        app_path     = os.path.dirname(os.path.abspath(__file__))
        app_settings = {
            'login_url':         '/login',
            'static_path':       os.path.join(app_path, 'static'),
            'template_path':     os.path.join(app_path, 'templates'),
            'cookie_secret':     secret,
            'debug':             True,
        }

        user_dir = get_user_dir()

        self.project_dir = os.path.join(user_dir, 'projects')
        ensure_dir(self.project_dir)

        session_dir = os.path.join(user_dir, 'sessions')
        ensure_dir(session_dir)

        self.session_manager = TornadoSessionManager(secret, session_dir)
        self.server_manager  = ZMQServerManager('openmdao.gui.consoleserver.ConsoleServer')

        global _MGR
        _MGR = self.server_manager
        signal.signal(signal.SIGTERM, self._sigterm_handler)
        super(App, self).__init__(handlers, **app_settings)

    def _sigterm_handler(self, signum, frame):
        DEBUG('Received SIGTERM, shutting down....\n')
        _MGR.cleanup()
        ioloop.IOLoop.instance().add_timeout(time.time()+5, sys.exit)
        
    def exit(self):
        self.server_manager.cleanup()
        DEBUG('Exit requested, shutting down....\n')
        ioloop.IOLoop.instance().add_timeout(time.time()+5, sys.exit)