예제 #1
0
def shared_course_list(ctx):
    courses = Course.all()

    for course in courses:
        print course.id, course.name

    return CHISUBMIT_SUCCESS
예제 #2
0
def admin_course_set_option(ctx, course_id, option_name, option_value):
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)    

    course.set_option(option_name, option_value)
예제 #3
0
파일: course.py 프로젝트: jclmns/chisubmit
def shared_course_list(ctx):
    courses = Course.all()
    
    for course in courses:
        print course.id, course.name

    return CHISUBMIT_SUCCESS
예제 #4
0
def admin_course_remove(ctx, course_id):
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)    
    
    print "NOT IMPLEMENTED"

    return CHISUBMIT_SUCCESS
예제 #5
0
파일: common.py 프로젝트: jclmns/chisubmit
    def new_func(ctx, *args, **kwargs):
        course_id = ctx.obj["course_id"]
        course_specified = ctx.obj["course_specified"]

        if course_specified:
            course_obj = Course.from_id(course_id)
        else:
            if course_id is None:
                raise click.UsageError("No course specified with --course and there is no default course")
            else:
                course_obj = Course.from_id(course_id)

        if course_obj is None:
            raise click.BadParameter("Course '%s' does not exist" % course_id)

        ctx.obj["course_obj"] = course_obj

        return ctx.invoke(f, ctx.obj["course_obj"], *args, **kwargs)
예제 #6
0
    def test_get_course(self):

        self.get_test_client({"id": "admin", "api_key": "admin"})

        course = Course.from_id("cmsc40100")
        self.assertEquals(course.name, "Introduction to Software Testing")

        students = course.students

        self.assertEquals(len(students), 4)
예제 #7
0
파일: common.py 프로젝트: jclmns/chisubmit
    def new_func(ctx, *args, **kwargs):
        course_id = ctx.obj["course_id"]
        course_specified = ctx.obj["course_specified"]

        if course_specified:
            course_obj = Course.from_id(course_id)
        else:
            if course_id is None:
                raise click.UsageError(
                    "No course specified with --course and there is no default course"
                )
            else:
                course_obj = Course.from_id(course_id)

        if course_obj is None:
            raise click.BadParameter("Course '%s' does not exist" % course_id)

        ctx.obj["course_obj"] = course_obj

        return ctx.invoke(f, ctx.obj["course_obj"], *args, **kwargs)
예제 #8
0
def admin_course_create_repos(ctx, course_id, staging):
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)    

    teams = course.get_teams()

    if len(teams) == 0:
        print "Course %s has no teams. No repositories to create." % course_id
        ctx.exit(CHISUBMIT_FAIL)  

    max_len = max([len(t.id) for t in teams])

    conn = create_connection(course, ctx.obj['config'], staging)
    
    if conn is None:
        print "Could not connect to git server."
        ctx.exit(CHISUBMIT_FAIL)
    
    v = ctx.obj["verbose"]
    already_has_repository = 0
    warning = 0
    created = 0
    for team in sorted(teams, key=operator.attrgetter("id")):
        if not team.is_complete():
            warning += 1
            print "%-*s  WARNING. Team registration is incomplete." % (max_len, team.id)
            continue
        
        if conn.exists_team_repository(course, team):
            already_has_repository += 1
            if v: print "%-*s  SKIPPING. Already has a repository." % (max_len, team.id)
            continue

        if not staging:        
            students = [s for s in course.students if s.user.id in [ts.user.id for ts in team.students]]
                
            missing = []
            for s in students:
                if not hasattr(s, "repo_info") or s.repo_info is None or not s.repo_info.has_key("git-username"):
                    missing.append(s.user.id)
                    
            if len(missing) > 0:
                warning += 1
                print "%-20s WARNING. These students haven't set their git usernames: %s" % (team.id, ",".join(missing))
                continue
        
        try:
            conn.create_team_repository(course, team)
            created += 1
            print "%-20s CREATED" % team.id
        except Exception, e:
            print "%-20s Unexpected exception %s: %s" % (team.id, e.__class__.__name__, e.message)
예제 #9
0
def admin_course_add_student(ctx, course_id, user_id):
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)    

    user = User.from_id(user_id)
    if course is None:
        print "User %s does not exist" % user_id
        ctx.exit(CHISUBMIT_FAIL)    
    
    course.add_student(user)  
예제 #10
0
def admin_course_update_repo_access(ctx, course_id, staging):
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)    
    
    conn = create_connection(course, ctx.obj['config'], staging)
    
    if conn is None:
        print "Could not connect to git server."
        ctx.exit(CHISUBMIT_FAIL)
    
    conn.update_instructors(course)
    conn.update_graders(course)
예제 #11
0
    def test_get_course(self):
        
        self.get_test_client({"id":"admin", "api_key":"admin"})
        
        course = Course.from_id("cmsc40100")
        self.assertEquals(course.name, "Introduction to Software Testing")
        
        students = course.students
        
        self.assertEquals(len(students), 4)

            
        
                
예제 #12
0
def admin_course_unsetup_repo(ctx, course_id, staging):
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)    

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

    conn.deinit_course(course)

    return CHISUBMIT_SUCCESS
예제 #13
0
def admin_course_load_students(ctx, course_id, csv_file, csv_userid_column, csv_fname_column, csv_lname_column, csv_email_column, dry_run, id_from_email):   
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)   
                
    csvf = csv.DictReader(csv_file)
            
    for col in (csv_userid_column, csv_fname_column, csv_lname_column, csv_email_column):
        if col not in csvf.fieldnames:
            print "CSV file %s does not have a '%s' column" % (csv_file, col)
            ctx.exit(CHISUBMIT_FAIL)
        
    for entry in csvf:
        user_id = entry[csv_userid_column]
        if id_from_email:
            user_id = user_id.split("@")[0].strip()
        
        first_name = entry[csv_fname_column]
        last_name = entry[csv_lname_column]
        email = entry[csv_email_column]

        print "Processing %s (%s, %s)" % (user_id, last_name, first_name)

        user = User.from_id(user_id)
    
        if user is not None:
            print "- User %s already exists." % user_id
        else:
            print "- Creating user %s" % user_id
            if not dry_run:
                user = User(id = user_id,
                            first_name = first_name,
                            last_name = last_name,
                            email = email)
        
        student = course.get_student(user_id)
        if student is not None:
            print "- User %s is already a student in %s" % (user_id, course_id)
        else:
            print "- Adding %s to %s" % (user_id, course_id)
            if not dry_run:
                course.add_student(user)
        
        print 
예제 #14
0
def admin_course_show(ctx, course_id, include_users, include_assignments):
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)    
    
    print course.id, course.name
    if len(course.options) == 0:
        print "No options"
    else:
        print "Options"
        for name, value in course.options.items():
            print "  %s: %s" % (name, value)
    print

    if include_users:
        print "INSTRUCTORS"
        print "-----------"
        for i in course.instructors:
            print "%s: %s, %s <%s>" % (i.user.id, i.user.last_name, i.user.first_name, i.user.email)
        print
            
        print "GRADERS"
        print "-------"
        for g in course.graders:
            print "%s: %s, %s <%s>" % (g.user.id, g.user.last_name, g.user.first_name, g.user.email)
        print
        
        print "STUDENTS"
        print "--------"
        for s in course.students:
            print "%s: %s, %s <%s>" % (s.user.id, s.user.last_name, s.user.first_name, s.user.email)
        print

    if include_assignments:
        print "ASSIGNMENTS"
        print "-----------"
        for a in course.assignments:
            print "%s: %s (Due: %s)" % (a.id, a.name, a.deadline)
        print

    
    return CHISUBMIT_SUCCESS
예제 #15
0
def admin_course_team_repo_update(ctx, course_id, team_id):
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)    

    team = course.get_team(team_id)
    if team is None:
        print "Team %s does not exist" % team_id
        ctx.exit(CHISUBMIT_FAIL)

    #if team.github_repo is None:
    #    print "Team %s does not have a repository." % team.id
    #    return CHISUBMIT_FAIL

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

    conn.update_team_repository(course, team)
    return CHISUBMIT_SUCCESS
예제 #16
0
def admin_course_team_repo_remove(ctx, course_id, team_id, ignore_non_existing, staging):
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)    

    team = course.get_team(team_id)
    if team is None:
        print "Team %s does not exist" % team_id
        ctx.exit(CHISUBMIT_FAIL)

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

    if not conn.exists_team_repository(course, team) and not ignore_non_existing:
        print "WARNING: Cannot delete repository because it doesn't exist"
        ctx.exit(CHISUBMIT_FAIL)
    else:
        conn.delete_team_repository(course, team, fail_if_not_exists = not ignore_non_existing)

    return CHISUBMIT_SUCCESS
예제 #17
0
def admin_course_team_repo_create(ctx, course_id, team_id, ignore_existing, public, staging):
    course = Course.from_id(course_id)
    if course is None:
        print "Course %s does not exist" % course_id
        ctx.exit(CHISUBMIT_FAIL)    

    team = course.get_team(team_id)
    if team is None:
        print "Team %s does not exist" % team_id
        ctx.exit(CHISUBMIT_FAIL)

    conn = create_connection(course, ctx.obj['config'], staging)
    
    if conn is None:
        print "Could not connect to git server."
        ctx.exit(CHISUBMIT_FAIL)
    
    if conn.exists_team_repository(course, team) and not ignore_existing:
        print "Team %s already has a repository" % team_id
        ctx.exit(CHISUBMIT_FAIL)
    else:
        conn.create_team_repository(course, team, fail_if_exists = not ignore_existing, private = not public)

    return CHISUBMIT_SUCCESS
예제 #18
0
def admin_course_add(ctx, course_id, name):
    course = Course(id = course_id,
                    name = name)
    
    return CHISUBMIT_SUCCESS