def get_app(config): """ :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) task_directory = config["tasks_directory"] download_directory = config.get("download_directory", "lti_download") default_allowed_file_extensions = config['allowed_file_extensions'] default_max_file_size = config['max_file_size'] appli = web.application((), globals(), autoreload=False) zmq_context, asyncio_thread = 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, FrontendCourse, FrontendTask) # # Allow user config to over-rider the username strong in Mongo. # This is enabled by most LMS's such as Moodle, and the ext_user_username # is the "login name" for the user, which is typically the same as # would be authenticated by logging into the course via ldap # lti_user_name = config.get('lti_user_name', 'user_id') if lti_user_name not in ['user_id', 'ext_user_username']: lti_user_name = 'user_id' user_manager = UserManager( CustomSession(appli, MongoStore(database, 'sessions')), database, lti_user_name) update_pending_jobs(database) client = create_arch(config, task_directory, zmq_context) lis_outcome_manager = LisOutcomeManager(database, user_manager, course_factory, config["lti"]) submission_manager = LTISubmissionManager( client, user_manager, database, gridfs, plugin_manager, config.get('nb_submissions_kept', 5), lis_outcome_manager) template_helper = TemplateHelper(plugin_manager, 'frontend/lti/templates', 'frontend/lti/templates/layout', config.get('use_minified_js', True)) # Update the database update_database(database) # 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) # Not found page appli.notfound = lambda: web.notfound(template_helper.get_renderer(). notfound('Page not found')) # 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.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.consumers = config["lti"] appli.download_directory = download_directory appli.download_status = {} 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 Client client.start() return appli.wsgifunc(), lambda: _close_app(appli, mongo_client, client, lis_outcome_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)
def get_app(config, active_callback=None): """ :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) 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, FrontendCourse, FrontendTask) user_manager = UserManager( CustomSession(appli, MongoStore(database, 'sessions')), database) backend_interface.update_pending_jobs(database) job_manager = backend_interface.create_job_manager(config, plugin_manager, task_directory, course_factory, task_factory) lis_outcome_manager = LisOutcomeManager(database, user_manager, course_factory, config["lti"]) submission_manager = LTISubmissionManager( job_manager, user_manager, database, gridfs, plugin_manager, config.get('nb_submissions_kept', 5), lis_outcome_manager) template_helper = TemplateHelper(plugin_manager, 'frontend/lti/templates', 'layout', config.get('use_minified_js', True)) # Update the database update_database(database) # 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) # 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, user_manager, template_helper, database, gridfs, default_allowed_file_extensions, default_max_file_size, config["containers"].keys(), config["lti"])) # 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, lis_outcome_manager)