Beispiel #1
0
def getUserUploadedMd5Helper(courseId, assignmentId, username, strout):
    """Get the current MD5 sum submitted for a given username on a given assignment"""
    try:
        vmcfg = StorerCourseConfig(CourseList().course_config(courseId))
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType' : ERR_EXCEPTION,
                           'errorMessage' : "",
                           'errorTrace' : strout.get()})

    (_, account) = getAssignmentAccountName(courseId, assignmentId, username, strout)
    vmpaths = paths.VmcheckerPaths(vmcfg.root_path())
    submission_dir = vmpaths.dir_cur_submission_root(assignmentId, account)
    md5_fpath = paths.submission_md5_file(submission_dir)

    md5_result = {}
    try:
        if os.path.exists(paths.submission_config_file(submission_dir)) and os.path.isfile(md5_fpath):
            sss = submissions.Submissions(vmpaths)
            upload_time_str = sss.get_upload_time_str(assignmentId, account)
            md5_result['fileExists'] = True

            with open(md5_fpath, 'r') as f:
                md5_result['md5Sum'] = f.read(32)

            md5_result['uploadTime'] = upload_time_str
        else:
            md5_result['fileExists'] = False

        return json.dumps(md5_result)
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType' : ERR_EXCEPTION,
                           'errorMessage' : "",
                           'errorTrace' : strout.get()})
Beispiel #2
0
def submission_upload_info(courseId, user, assignment):
    """Return a string explaining the submission upload time, deadline
    and the late submission penalty
    """
    vmcfg = CourseConfig(CourseList().course_config(courseId))
    vmpaths = paths.VmcheckerPaths(vmcfg.root_path())
    sbroot = vmpaths.dir_cur_submission_root(assignment, user)
    grade_file = paths.submission_results_grade(sbroot)
    sbcfg = paths.submission_config_file(sbroot)
    if not os.path.exists(sbcfg):
        return "Tema nu a fost încă trimisă"

    late_penalty = update_db.compute_late_penalty(assignment, user, vmcfg)
    ta_penalty = update_db.compute_TA_penalty(grade_file)
    deadline_str = vmcfg.assignments().get(assignment, 'Deadline')
    total_points = int(vmcfg.assignments().get(assignment, 'TotalPoints'))
    deadline_struct = time.strptime(
        vmcfg.assignments().get(assignment, 'Deadline'), penalty.DATE_FORMAT)
    sss = submissions.Submissions(vmpaths)
    upload_time_str = sss.get_upload_time_str(assignment, user)
    upload_time_struct = sss.get_upload_time_struct(assignment, user)

    # XXX hack, we should move this
    language = 'ro'
    deadline_explanation = penalty.verbose_time_difference(
        upload_time_struct, deadline_struct, language)

    ret = ""

    if language is 'ro':
        ret += "Data trimiterii temei : " + upload_time_str + "\n"
        ret += "Deadline temă         : " + deadline_str + "\n"
        ret += deadline_explanation + "\n"
        ret += "\n"
        ret += "Depunctare întârziere : " + str(late_penalty) + "\n"
        ret += "Depunctare corectare  : " + str(ta_penalty) + "\n"
        ret += "Total depunctări      : " + str(ta_penalty +
                                                late_penalty) + "\n"
        ret += "-----------------------\n"
        ret += "Nota                  : " + str(total_points + ta_penalty +
                                                late_penalty) + "\n"
    else:
        # another language
        ret += "Submision date           : " + upload_time_str + "\n"
        ret += "Assignment deadline      : " + deadline_str + "\n"
        ret += deadline_explanation + "\n"
        ret += "\n"
        ret += "Penalty (late submission): " + str(late_penalty) + "\n"
        ret += "Penalty (grading)        : " + str(ta_penalty) + "\n"
        ret += "Penalty (total)          : " + str(ta_penalty +
                                                   late_penalty) + "\n"
        ret += "---------------------------\n"
        ret += "Grade                    : " + str(total_points + ta_penalty +
                                                   late_penalty) + "\n"

    ret += "\n"

    return ret
Beispiel #3
0
def submission_upload_info(courseId, user, assignment):
    """Return a string explaining the submission upload time, deadline
    and the late submission penalty
    """
    vmcfg = CourseConfig(CourseList().course_config(courseId))
    vmpaths = paths.VmcheckerPaths(vmcfg.root_path())
    sbroot = vmpaths.dir_cur_submission_root(assignment, user)
    grade_file = paths.submission_results_grade(sbroot)
    sbcfg = paths.submission_config_file(sbroot)
    if not os.path.exists(sbcfg):
        return "Tema nu a fost încă trimisă"

    late_penalty = update_db.compute_late_penalty(assignment, user, vmcfg)
    ta_penalty   = update_db.compute_TA_penalty(grade_file)
    deadline_str = vmcfg.assignments().get(assignment, 'Deadline')
    total_points = int(vmcfg.assignments().get(assignment, 'TotalPoints'))
    deadline_struct = time.strptime(vmcfg.assignments().get(assignment, 'Deadline'),
                                    penalty.DATE_FORMAT)
    sss = submissions.Submissions(vmpaths)
    upload_time_str = sss.get_upload_time_str(assignment, user)
    upload_time_struct = sss.get_upload_time_struct(assignment, user)

    # XXX hack, we should move this
    language = 'ro'
    deadline_explanation = penalty.verbose_time_difference(upload_time_struct, deadline_struct, language)

    ret = ""

    if language is 'ro':
        ret += "Data trimiterii temei : " + upload_time_str + "\n"
        ret += "Deadline temă         : " + deadline_str    + "\n"
        ret += deadline_explanation + "\n"
        ret += "\n"
        ret += "Depunctare întârziere : " + str(late_penalty) + "\n"
        ret += "Depunctare corectare  : " + str(ta_penalty)   + "\n"
        ret += "Total depunctări      : " + str(ta_penalty + late_penalty) + "\n"
        ret += "-----------------------\n"
        ret += "Nota                  : " + str(total_points + ta_penalty + late_penalty) + "\n"
    else:
        # another language
        ret += "Submision date           : " + upload_time_str + "\n"
        ret += "Assignment deadline      : " + deadline_str    + "\n"
        ret += deadline_explanation + "\n"
        ret += "\n"
        ret += "Penalty (late submission): " + str(late_penalty) + "\n"
        ret += "Penalty (grading)        : " + str(ta_penalty)   + "\n"
        ret += "Penalty (total)          : " + str(ta_penalty + late_penalty) + "\n"
        ret += "---------------------------\n"
        ret += "Grade                    : " + str(total_points + ta_penalty + late_penalty) + "\n"

    ret += "\n"

    return ret
Beispiel #4
0
def getUserUploadedMd5(req, courseId, assignmentId, username):
    """Get the current MD5 sum submitted for a given username on a given assignment"""
    req.content_type = 'text/html'
    strout = OutputString()
    try:
        vmcfg = config.CourseConfig(CourseList().course_config(courseId))
    except:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType': ERR_EXCEPTION,
            'errorMessage': "",
            'errorTrace': strout.get()
        })

    vmpaths = paths.VmcheckerPaths(vmcfg.root_path())
    submission_dir = vmpaths.dir_cur_submission_root(assignmentId, username)
    md5_fpath = paths.submission_md5_file(submission_dir)

    strout = OutputString()

    md5_result = {}
    try:
        if os.path.exists(paths.submission_config_file(
                submission_dir)) and os.path.isfile(md5_fpath):
            sss = submissions.Submissions(vmpaths)
            upload_time_str = sss.get_upload_time_str(assignmentId, username)
            md5_result['fileExists'] = True

            with open(md5_fpath, 'r') as f:
                md5_result['md5Sum'] = f.read(32)

            md5_result['uploadTime'] = upload_time_str
        else:
            md5_result['fileExists'] = False

        return json.dumps(md5_result)
    except:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType': ERR_EXCEPTION,
            'errorMessage': "",
            'errorTrace': strout.get()
        })
Beispiel #5
0
def getUserUploadedMd5(req, courseId, assignmentId, username):
    """Get the current MD5 sum submitted for a given username on a given assignment"""
    req.content_type = 'text/html'
    strout = websutil.OutputString()
    try:
        vmcfg = config.CourseConfig(CourseList().course_config(courseId))
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType' : ERR_EXCEPTION,
                           'errorMessage' : "",
                           'errorTrace' : strout.get()})

    vmpaths = paths.VmcheckerPaths(vmcfg.root_path())
    submission_dir = vmpaths.dir_cur_submission_root(assignmentId, username)
    md5_fpath = paths.submission_md5_file(submission_dir)

    strout = websutil.OutputString()

    md5_result = {}
    try:
        if os.path.exists(paths.submission_config_file(submission_dir)) and os.path.isfile(md5_fpath):
            sss = submissions.Submissions(vmpaths)
            upload_time_str = sss.get_upload_time_str(assignmentId, username)
            md5_result['fileExists'] = True

            with open(md5_fpath, 'r') as f:
                md5_result['md5Sum'] = f.read(32)

            md5_result['uploadTime'] = upload_time_str
        else:
            md5_result['fileExists'] = False

        return json.dumps(md5_result)
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType' : ERR_EXCEPTION,
                           'errorMessage' : "",
                           'errorTrace' : strout.get()})
Beispiel #6
0
def submission_upload_info(vmcfg, courseId, assignment, account, isTeamAccount, isGraded):
    """Return a string explaining the submission upload time, deadline
    and the late submission penalty
    """

    vmpaths = paths.VmcheckerPaths(vmcfg.root_path())
    sbroot = vmpaths.dir_cur_submission_root(assignment, account)
    grade_file = paths.submission_results_grade(sbroot)
    sbcfg = paths.submission_config_file(sbroot)
    if not os.path.exists(sbcfg):
        return _("No submission exists for this assignment")

    late_penalty = update_db.compute_late_penalty(assignment, account, vmcfg)
    ta_penalty   = update_db.compute_TA_penalty(grade_file)
    deadline_str = vmcfg.assignments().get(assignment, 'Deadline')
    total_points = int(vmcfg.assignments().get(assignment, 'TotalPoints'))
    deadline_struct = time.strptime(vmcfg.assignments().get(assignment, 'Deadline'),
                                    penalty.DATE_FORMAT)
    sss = submissions.Submissions(vmpaths)
    upload_time_str = sss.get_upload_time_str(assignment, account)
    upload_time_struct = sss.get_upload_time_struct(assignment, account)

    deadline_explanation = penalty.verbose_time_difference(upload_time_struct, deadline_struct)

    submitter_explanation = None
    if isTeamAccount:
        submitting_user = sss.get_submitting_user(assignment, account)
        if submitting_user is not None:
            submitter_explanation = _("Submitted by") + ": " + submitting_user

    max_line_width = 0
    rows_to_print = []

    if submitter_explanation is not None:
        rows_to_print += [
            [ submitter_explanation ],
            [ '' ]
        ]

    rows_to_print += [
        [ _("Submission date"), upload_time_str ],
        [ _("Assignment deadline"), deadline_str ],
        [ deadline_explanation ]
    ]

    if isGraded or not vmcfg.assignments().is_deadline_hard(assignment):
        rows_to_print += [
            [ '' ]
        ]

    if not vmcfg.assignments().is_deadline_hard(assignment):
        rows_to_print += [
            [ _("Penalty (late submission)"), str(late_penalty) ],
        ]

    if isGraded:
        rows_to_print += [
            [ _("Penalty (grading)"), str(ta_penalty) ],
            [ _("Penalty (total)"), str(ta_penalty + late_penalty) ],
            [ '' ],
            [ _("Grade"), str(total_points + ta_penalty + late_penalty) ]
        ]

    for row in rows_to_print:
        row[0] = row[0].decode("utf-8")
        if len(row) == 2 and len(row[0]) > max_line_width:
            max_line_width = len(row[0])

    if isGraded:
        # Put a dashed line just above the 'Grade' line
        rows_to_print[len(rows_to_print) - 2][0] = '-' * max_line_width

    ret = u""
    for row in rows_to_print:
        if len(row) == 1:
            ret += row[0] + "\n"
        elif len(row) == 2:
            ret += unicode("{0[0]:<" + str(max_line_width) + "} : {0[1]}\n").format(row)

    ret += "\n"

    return ret
Beispiel #7
0
def submission_upload_info(vmcfg, courseId, assignment, account, isTeamAccount,
                           isGraded):
    """Return a string explaining the submission upload time, deadline
    and the late submission penalty
    """

    vmpaths = paths.VmcheckerPaths(vmcfg.root_path())
    sbroot = vmpaths.dir_cur_submission_root(assignment, account)
    grade_file = paths.submission_results_grade(sbroot)
    sbcfg = paths.submission_config_file(sbroot)
    if not os.path.exists(sbcfg):
        return _("No submission exists for this assignment")

    late_penalty = update_db.compute_late_penalty(assignment, account, vmcfg)
    ta_penalty = update_db.compute_TA_penalty(grade_file)
    deadline_str = vmcfg.assignments().get(assignment, 'Deadline')
    total_points = int(vmcfg.assignments().get(assignment, 'TotalPoints'))
    deadline_struct = time.strptime(
        vmcfg.assignments().get(assignment, 'Deadline'), penalty.DATE_FORMAT)
    sss = submissions.Submissions(vmpaths)
    upload_time_str = sss.get_upload_time_str(assignment, account)
    upload_time_struct = sss.get_upload_time_struct(assignment, account)

    deadline_explanation = penalty.verbose_time_difference(
        upload_time_struct, deadline_struct)

    submitter_explanation = None
    if isTeamAccount:
        submitting_user = sss.get_submitting_user(assignment, account)
        if submitting_user is not None:
            submitter_explanation = _("Submitted by") + ": " + submitting_user

    max_line_width = 0
    rows_to_print = []

    if submitter_explanation is not None:
        rows_to_print += [[submitter_explanation], ['']]

    rows_to_print += [[_("Submission date"), upload_time_str],
                      [_("Assignment deadline"), deadline_str],
                      [deadline_explanation]]

    if isGraded or not vmcfg.assignments().is_deadline_hard(assignment):
        rows_to_print += [['']]

    if not vmcfg.assignments().is_deadline_hard(assignment):
        rows_to_print += [
            [_("Penalty (late submission)"),
             str(late_penalty)],
        ]

    if isGraded:
        rows_to_print += [
            [_("Penalty (grading)"), str(ta_penalty)],
            [_("Penalty (total)"),
             str(ta_penalty + late_penalty)], [''],
            [_("Grade"),
             str(total_points + ta_penalty + late_penalty)]
        ]

    for row in rows_to_print:
        row[0] = row[0].decode("utf-8")
        if len(row) == 2 and len(row[0]) > max_line_width:
            max_line_width = len(row[0])

    if isGraded:
        # Put a dashed line just above the 'Grade' line
        rows_to_print[len(rows_to_print) - 2][0] = '-' * max_line_width

    ret = u""
    for row in rows_to_print:
        if len(row) == 1:
            ret += row[0] + "\n"
        elif len(row) == 2:
            ret += unicode("{0[0]:<" + str(max_line_width) +
                           "} : {0[1]}\n").format(row)

    ret += "\n"

    return ret