def get_app(hostname, port, sshhost, sshport, config, active_callback=None): """ :param hostname: the hostname on which the web app will be bound :param port: the port on which the web app will be bound :param sshport: the port on which remote container debugging clients will connect :param config: the configuration dict :param active_callback: a callback without arguments that will be called when the app is fully initialized :return: A new app """ config = _put_configuration_defaults(config) if config.get("maintenance", False): appli = web.application(urls_maintenance, globals(), autoreload=False) return appli task_directory = config["tasks_directory"] default_allowed_file_extensions = config['allowed_file_extensions'] default_max_file_size = config['max_file_size'] appli = web.application((), globals(), autoreload=False) # Init the different parts of the app plugin_manager = PluginManager() mongo_client = MongoClient(host=config.get('mongo_opt', {}).get('host', 'localhost')) database = mongo_client[config.get('mongo_opt', {}).get('database', 'INGInious')] gridfs = GridFS(database) course_factory, task_factory = create_factories(task_directory, plugin_manager, WebAppCourse, WebAppTask) user_manager = UserManager(web.session.Session(appli, MongoStore(database, 'sessions')), database, config.get('superadmins', [])) backend_interface.update_pending_jobs(database) job_manager = backend_interface.create_job_manager(config, plugin_manager, task_directory, course_factory, task_factory) remote_ssh_manager = RemoteSSHManager(sshhost, sshport, database, job_manager) if config.get("remote_debugging_active", True) and job_manager.is_remote_debug_active(): if sshhost is None: print "You have to set the --sshhost arg to start the remote debugging manager. Remote debugging is then deactivated" else: remote_ssh_manager.start() submission_manager = WebAppSubmissionManager(job_manager, user_manager, database, gridfs, plugin_manager) batch_manager = BatchManager(job_manager, database, gridfs, submission_manager, user_manager, task_directory, config.get('batch_containers', [])) template_helper = TemplateHelper(plugin_manager, 'frontend/webapp/templates', 'layout', config.get('use_minified_js', True)) # Init web mail smtp_conf = config.get('smtp', None) if smtp_conf is not None: web.config.smtp_server = smtp_conf["host"] web.config.smtp_port = int(smtp_conf["port"]) web.config.smtp_starttls = bool(smtp_conf.get("starttls", False)) web.config.smtp_username = smtp_conf.get("username", "") web.config.smtp_password = smtp_conf.get("password", "") web.config.smtp_sendername = smtp_conf.get("sendername", "*****@*****.**") # Update the database update_database(database, gridfs, course_factory, user_manager) # Add some helpers for the templates template_helper.add_to_template_globals("user_manager", user_manager) template_helper.add_to_template_globals("default_allowed_file_extensions", default_allowed_file_extensions) template_helper.add_to_template_globals("default_max_file_size", default_max_file_size) template_helper.add_other("course_admin_menu", lambda course, current: course_admin_utils.get_menu(course, current, template_helper.get_renderer(False), plugin_manager, user_manager)) # Not found page appli.notfound = lambda: web.notfound(template_helper.get_renderer().notfound('Page not found')) # Init the mapping of the app appli.init_mapping(WebPyCustomMapping(dict(urls), plugin_manager, course_factory, task_factory, submission_manager, batch_manager, user_manager, remote_ssh_manager, template_helper, database, gridfs, default_allowed_file_extensions, default_max_file_size, config.get("backup_directory", './backup'), config["containers"].keys())) # Active hook if active_callback is not None: _handle_active_hook(job_manager, plugin_manager, active_callback) # Loads plugins plugin_manager.load(job_manager, appli, course_factory, task_factory, database, user_manager, config.get("plugins", [])) # Start the inginious.backend job_manager.start() return appli, lambda: _close_app(appli, mongo_client, job_manager, remote_ssh_manager)
def get_app(config): """ :param config: the configuration dict :return: A new app """ config = _put_configuration_defaults(config) appli = web.application((), globals(), autoreload=False) if config.get("maintenance", False): template_helper = TemplateHelper(PluginManager(), 'frontend/webapp/templates', 'frontend/webapp/templates/layout', config.get('use_minified_js', True)) template_helper.add_to_template_globals("get_homepath", lambda: web.ctx.homepath) appli.template_helper = template_helper appli.init_mapping(urls_maintenance) return appli.wsgifunc(), appli.stop task_directory = config["tasks_directory"] default_allowed_file_extensions = config['allowed_file_extensions'] default_max_file_size = config['max_file_size'] zmq_context, _ = start_asyncio_and_zmq() # Init the different parts of the app plugin_manager = PluginManager() mongo_client = MongoClient( host=config.get('mongo_opt', {}).get('host', 'localhost')) database = mongo_client[config.get('mongo_opt', {}).get('database', 'INGInious')] gridfs = GridFS(database) course_factory, task_factory = create_factories(task_directory, plugin_manager, WebAppCourse, WebAppTask) user_manager = UserManager( web.session.Session(appli, MongoStore(database, 'sessions')), database, config.get('superadmins', [])) update_pending_jobs(database) client = create_arch(config, task_directory, zmq_context) submission_manager = WebAppSubmissionManager(client, user_manager, database, gridfs, plugin_manager) batch_manager = BatchManager(client, database, gridfs, submission_manager, user_manager, task_directory) template_helper = TemplateHelper(plugin_manager, 'frontend/webapp/templates', 'frontend/webapp/templates/layout', config.get('use_minified_js', True)) # Init web mail smtp_conf = config.get('smtp', None) if smtp_conf is not None: web.config.smtp_server = smtp_conf["host"] web.config.smtp_port = int(smtp_conf["port"]) web.config.smtp_starttls = bool(smtp_conf.get("starttls", False)) web.config.smtp_username = smtp_conf.get("username", "") web.config.smtp_password = smtp_conf.get("password", "") web.config.smtp_sendername = smtp_conf.get("sendername", "*****@*****.**") # Update the database update_database(database, gridfs, course_factory, user_manager) # Add some helpers for the templates template_helper.add_to_template_globals("get_homepath", lambda: web.ctx.homepath) template_helper.add_to_template_globals("user_manager", user_manager) template_helper.add_to_template_globals("default_allowed_file_extensions", default_allowed_file_extensions) template_helper.add_to_template_globals("default_max_file_size", default_max_file_size) template_helper.add_other( "course_admin_menu", lambda course, current: course_admin_utils.get_menu( course, current, template_helper.get_renderer(False), plugin_manager, user_manager)) # Not found page appli.notfound = lambda: web.notfound(template_helper.get_renderer(). notfound('Page not found')) # Enable stacktrace display if logging is at level DEBUG if config.get('log_level', 'INFO') == 'DEBUG': appli.internalerror = debugerror # Insert the needed singletons into the application, to allow pages to call them appli.plugin_manager = plugin_manager appli.course_factory = course_factory appli.task_factory = task_factory appli.submission_manager = submission_manager appli.batch_manager = batch_manager appli.user_manager = user_manager appli.template_helper = template_helper appli.database = database appli.gridfs = gridfs appli.default_allowed_file_extensions = default_allowed_file_extensions appli.default_max_file_size = default_max_file_size appli.backup_dir = config.get("backup_directory", './backup') appli.webterm_link = config.get("webterm", None) # Init the mapping of the app appli.init_mapping(urls) # Loads plugins plugin_manager.load(client, appli, course_factory, task_factory, database, user_manager, submission_manager, config.get("plugins", [])) # Start the inginious.backend client.start() return appli.wsgifunc(), lambda: _close_app(appli, mongo_client, client)