Beispiel #1
0
def split_according_to_groups(course, subspath, path):
    if not os.path.isdir(subspath):
        subspath = os.path.join("subs", subspath)
        if not os.path.isdir(subspath):
            raise LookupError("Can't resolve subs directory.")

    subsid = os.path.split(subspath)[1]

    splitpath = os.path.join("splits", subsid)
    mkdir("splits")
    mkdir(splitpath)

    gl = canvas.GroupList(course, path=path)
    teams = gl.uidmap()
    students = canvas.StudentList(searchdir="students")

    for name, uids in teams.items():
        name = normalize_pathname(name)
        namepath = os.path.join(splitpath, name)
        mkdir(namepath)
        for uid in uids:
            if uid not in students:
                continue
            dirname = student_dirname(students[uid])
            subpath = os.path.join(subspath, dirname)
            if os.path.isdir(subpath):
                src = subpath
                tgt = os.path.join(namepath, dirname)
                shutil.copytree(src, tgt, symlinks=True)
Beispiel #2
0
def fetch_subs(course, name, deep=False, metadata=False):
    path = os.path.join("subs", name)
    if os.path.isdir(path):
        assign = canvas.Assignment(course, path=path)
    else:
        assign = canvas.Assignment(course, name=name)
    mkdir("subs")
    mkdir(path)
    assign.cache(path)
    print("Fetched {} as {}.".format(name, path))
    if not deep:
        return

    students = canvas.StudentList(searchdir="students").mapping
    for sub in assign.subs:
        fetch_sub(students, path, sub, metadata)
Beispiel #3
0
def split_by_section(c, name, subspath, path):
    """Split assignments by section of submitting student."""
    if not os.path.isdir(subspath):
        raise LookupError("Submission path %s does not exist" % subspath)

    name = slugify(name)
    splitbase = os.path.join(path, name)
    subbase = os.path.join(subspath, name)

    if os.path.exists(splitbase):
        raise Exception("Split target directory %s already exists."
                        % splitbase)
    splitbase = os.path.abspath(splitbase)

    if not os.path.exists(subbase):
        raise Exception("Submission directory %s not found." % subbase)
    subbase = os.path.abspath(subbase)

    sections = canvas.SectionList(c)
    students = canvas.StudentList(searchdir="students")

    # Create folders for each section
    mkdir(path)
    mkdir(splitbase)
    for sec in sections.sections():
        d = os.path.join(splitbase, sec)
        mkdir(d)

    # Symlink folders from submission directory to destination
    for uid, namelist in sections.sectmap().items():
        dirname = student_dirname(students[uid])
        subpath = os.path.join(subbase, dirname)
        for name in namelist:
            splitpath = os.path.join(splitbase, os.path.join(name, dirname))
            if not os.path.isdir(subpath):
                continue
            os.symlink(subpath, splitpath)