Beispiel #1
0
def shared_course_set_user_attribute(ctx, course, user_type, username, attr_name, attr_value):
    if user_type == "instructor":
        user = get_instructor_or_exit(ctx, course, username)
    elif user_type == "grader":
        user = get_grader_or_exit(ctx, course, username)
    elif user_type == "student":
        user = get_student_or_exit(ctx, course, username)
    
    api_obj_set_attribute(ctx, user, attr_name, attr_value)
Beispiel #2
0
def shared_course_set_user_attribute(ctx, course, user_type, username,
                                     attr_name, attr_value):
    if user_type == "instructor":
        user = get_instructor_or_exit(ctx, course, username)
    elif user_type == "grader":
        user = get_grader_or_exit(ctx, course, username)
    elif user_type == "student":
        user = get_student_or_exit(ctx, course, username)

    api_obj_set_attribute(ctx, user, attr_name, attr_value)
Beispiel #3
0
def admin_course_set_attribute(ctx, course_id, attr_name, attr_value):
    course = get_course_or_exit(ctx, course_id)
    
    api_obj_set_attribute(ctx, course, attr_name, attr_value)
Beispiel #4
0
def student_course_set_git_username(ctx, course, git_username):
    user = ctx.obj["client"].get_user()
    
    student = get_student_or_exit(ctx, course, user.username)
    
    api_obj_set_attribute(ctx, student, "git_username", git_username)    
Beispiel #5
0
def shared_assignment_set_attribute(ctx, course, assignment_id, attr_name, attr_value):
    assignment = get_assignment_or_exit(ctx, course, assignment_id)
    
    api_obj_set_attribute(ctx, assignment, attr_name, attr_value)
Beispiel #6
0
def admin_course_setup(ctx, config_file, skip_user_creation, skip_repo_creation):
    with open(config_file, "r") as f:
        conf = yaml.load(f)

    config_dir = os.path.dirname(os.path.realpath(config_file))
    
    for field in ("course_id", "course_name", "upstream_repo", "individual_repos",
                  "staging_repos", "git_connstr"):
        if field not in conf:
            print("ERROR: Configuration file is missing '%s' field" % field)
            ctx.exit(CHISUBMIT_FAIL)
    
    staff_file = config_dir + "/" + conf.get("staff_file", "staff.csv")
    students_file = config_dir + "/" + conf.get("students_file", "students.csv")
    
    course_id = conf["course_id"]
    course_name = conf["course_name"]

    # Create the course    
    try:
        course = ctx.obj["client"].get_course(course_id = course_id)
        print("- Course with course_id = %s already exists." % course_id)
    except UnknownObjectException as uoe:
        course = ctx.obj["client"].create_course(course_id = course_id,
                                                 name = course_name)
        print("- Created new course %s" % course_id)
        
    # Set the Git connection string
    api_obj_set_attribute(ctx, course, "git_server_connstr", conf["git_connstr"])
    
    # Setup the Git server
    conn = create_connection(course, ctx.obj['config'], False)
    
    if conn is None:
        print("Could not connect to git server.")
        ctx.exit(CHISUBMIT_FAIL)

    rv = conn.init_course(course, fail_if_exists=False)
    if rv:    
        print("- Git server setup complete")
    else:
        print("- Git server is already setup")
    
    print("- Creating/updating staff users")
    print("===============================")
    print()
    with open(staff_file, "r") as f:
        ctx.invoke(admin_course_load_users, 
                   course_id = course_id,
                   csv_file = f,
                   csv_username_column = "username",
                   csv_fname_column = "fname",
                   csv_lname_column = "lname",
                   csv_email_column = "email",
                   user_type = "column",
                   user_type_column = "type"
                   )
    print()
    print("===============================")
    print("- Staff user creation/update complete.")

    print("- Creating instructor git users")
    print("===============================")
    print()
    ctx.invoke(admin_course_create_git_users, 
               course_id = course_id,
               only_type = "instructor")
    print()
    print("===============================")

    print("- Creating grader git users")
    print("===========================")
    print()
    ctx.invoke(admin_course_create_git_users, 
               course_id = course_id,
               only_type = "grader")
    print()
    print("===========================")
    
    conn.update_instructors(course)
    print("- Updated instructor access privileges on Git server")
    
    # Setup staging Git server
    if conf["staging_repos"] == True:
        git_staging_connstr = conf.get("git_staging_connstr", conf["git_connstr"])
        api_obj_set_attribute(ctx, course, "git_staging_connstr", git_staging_connstr)

        staging_conn = create_connection(course, ctx.obj['config'], True)
    
        if staging_conn is None:
            print("Could not connect to staging git server.")
            ctx.exit(CHISUBMIT_FAIL)

        rv = staging_conn.init_course(course, fail_if_exists=False)        
        
        if rv:    
            print("- Staging Git server setup complete")
        else:
            print("- Staging Git server is already setup")
        
        staging_conn.update_instructors(course)
        staging_conn.update_graders(course)
        print("- Updated instructor/grader access privileges on staging Git server")
    else:
        print("- This course does not need staging repos")

    print("- Creating/updating student users")
    print("=================================")    
    print()
    with open(students_file, "r") as f:
        ctx.invoke(admin_course_load_users, 
                   course_id = course_id,
                   csv_file = f,
                   csv_username_column = "username",
                   csv_fname_column = "fname",
                   csv_lname_column = "lname",
                   csv_email_column = "email",
                   user_type = "student",
                   sync = True
                   )
    print()
    print("===============================")
    print("- Student user creation/update complete.")
    print("- Creating student git users")
    print("===========================")
    print()
    ctx.invoke(admin_course_create_git_users, 
               course_id = course_id,
               only_type = "student")
    print()
    print("===========================")

    if conf["individual_repos"] == True:
        print("- Creating individual teams")
        print("===========================")
        print()
        ctx.invoke(admin_course_create_individual_teams, 
                   course_id = course_id
                   )
        print()
        print("===========================")
        print("- Individual team creation complete.")

    print("- Creating repos")
    print("================")
    print()
    ctx.invoke(admin_course_create_repos, 
               course_id = course_id
               )
    print()
    print("================")
    print("- Repo creation complete.")

    if conf["staging_repos"] == True:
        print("- Creating staging repos")
        print("========================")
        print()
        ctx.invoke(admin_course_create_repos, 
                   course_id = course_id,
                   staging = True
                   )
        print()
        print("========================")
        print("- Repo creation complete.")     
    
    return CHISUBMIT_SUCCESS
Beispiel #7
0
def student_course_set_git_username(ctx, course, git_username):
    user = ctx.obj["client"].get_user()

    student = get_student_or_exit(ctx, course, user.username)

    api_obj_set_attribute(ctx, student, "git_username", git_username)
Beispiel #8
0
def admin_course_setup(ctx, config_file, skip_user_creation,
                       skip_repo_creation):
    with open(config_file, "r") as f:
        conf = yaml.load(f)

    config_dir = os.path.dirname(os.path.realpath(config_file))

    for field in ("course_id", "course_name", "upstream_repo",
                  "individual_repos", "staging_repos", "git_connstr"):
        if field not in conf:
            print("ERROR: Configuration file is missing '%s' field" % field)
            ctx.exit(CHISUBMIT_FAIL)

    staff_file = config_dir + "/" + conf.get("staff_file", "staff.csv")
    students_file = config_dir + "/" + conf.get("students_file",
                                                "students.csv")

    course_id = conf["course_id"]
    course_name = conf["course_name"]

    # Create the course
    try:
        course = ctx.obj["client"].get_course(course_id=course_id)
        print("- Course with course_id = %s already exists." % course_id)
    except UnknownObjectException as uoe:
        course = ctx.obj["client"].create_course(course_id=course_id,
                                                 name=course_name)
        print("- Created new course %s" % course_id)

    # Set the Git connection string
    api_obj_set_attribute(ctx, course, "git_server_connstr",
                          conf["git_connstr"])

    # Setup the Git server
    conn = create_connection(course, ctx.obj['config'], False)

    if conn is None:
        print("Could not connect to git server.")
        ctx.exit(CHISUBMIT_FAIL)

    rv = conn.init_course(course, fail_if_exists=False)
    if rv:
        print("- Git server setup complete")
    else:
        print("- Git server is already setup")

    print("- Creating/updating staff users")
    print("===============================")
    print()
    with open(staff_file, "r") as f:
        ctx.invoke(admin_course_load_users,
                   course_id=course_id,
                   csv_file=f,
                   csv_username_column="username",
                   csv_fname_column="fname",
                   csv_lname_column="lname",
                   csv_email_column="email",
                   user_type="column",
                   user_type_column="type")
    print()
    print("===============================")
    print("- Staff user creation/update complete.")

    print("- Creating instructor git users")
    print("===============================")
    print()
    ctx.invoke(admin_course_create_git_users,
               course_id=course_id,
               only_type="instructor")
    print()
    print("===============================")

    print("- Creating grader git users")
    print("===========================")
    print()
    ctx.invoke(admin_course_create_git_users,
               course_id=course_id,
               only_type="grader")
    print()
    print("===========================")

    conn.update_instructors(course)
    print("- Updated instructor access privileges on Git server")

    # Setup staging Git server
    if conf["staging_repos"] == True:
        git_staging_connstr = conf.get("git_staging_connstr",
                                       conf["git_connstr"])
        api_obj_set_attribute(ctx, course, "git_staging_connstr",
                              git_staging_connstr)

        staging_conn = create_connection(course, ctx.obj['config'], True)

        if staging_conn is None:
            print("Could not connect to staging git server.")
            ctx.exit(CHISUBMIT_FAIL)

        rv = staging_conn.init_course(course, fail_if_exists=False)

        if rv:
            print("- Staging Git server setup complete")
        else:
            print("- Staging Git server is already setup")

        staging_conn.update_instructors(course)
        staging_conn.update_graders(course)
        print(
            "- Updated instructor/grader access privileges on staging Git server"
        )
    else:
        print("- This course does not need staging repos")

    print("- Creating/updating student users")
    print("=================================")
    print()
    with open(students_file, "r") as f:
        ctx.invoke(admin_course_load_users,
                   course_id=course_id,
                   csv_file=f,
                   csv_username_column="username",
                   csv_fname_column="fname",
                   csv_lname_column="lname",
                   csv_email_column="email",
                   user_type="student",
                   sync=True)
    print()
    print("===============================")
    print("- Student user creation/update complete.")
    print("- Creating student git users")
    print("===========================")
    print()
    ctx.invoke(admin_course_create_git_users,
               course_id=course_id,
               only_type="student")
    print()
    print("===========================")

    if conf["individual_repos"] == True:
        print("- Creating individual teams")
        print("===========================")
        print()
        ctx.invoke(admin_course_create_individual_teams, course_id=course_id)
        print()
        print("===========================")
        print("- Individual team creation complete.")

    print("- Creating repos")
    print("================")
    print()
    ctx.invoke(admin_course_create_repos, course_id=course_id)
    print()
    print("================")
    print("- Repo creation complete.")

    if conf["staging_repos"] == True:
        print("- Creating staging repos")
        print("========================")
        print()
        ctx.invoke(admin_course_create_repos,
                   course_id=course_id,
                   staging=True)
        print()
        print("========================")
        print("- Repo creation complete.")

    return CHISUBMIT_SUCCESS
Beispiel #9
0
def admin_course_set_attribute(ctx, course_id, attr_name, attr_value):
    course = get_course_or_exit(ctx, course_id)

    api_obj_set_attribute(ctx, course, attr_name, attr_value)