Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
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)