예제 #1
0
def getTeamResults(req, courseId, assignmentId, teamname=None, locale=websutil.DEFAULT_LOCALE):
    """Get the results for a given team name.
       If the team name is empty, get the results of the current user's team."""

    websutil.install_i18n(websutil.sanityCheckLocale(locale))

    websutil.sanityCheckAssignmentId(assignmentId)
    websutil.sanityCheckCourseId(courseId)
    if teamname != None:
        websutil.sanityCheckUsername(teamname)

    req.content_type = 'text/html'
    strout = websutil.OutputString()

    # Check permission
    s = Session.Session(req)
    if s.is_new():
        s.invalidate()
        return json.dumps({'errorType':websutil.ERR_AUTH,
                'errorMessage':"",
                'errorTrace':""})

    try:
        s.load()
        current_user = s['username']
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType' : websutil.ERR_EXCEPTION,
                           'errorMessage' : "",
                           'errorTrace' : strout.get()})

    (hasTeam, current_team) = websutil.getAssignmentAccountName(courseId, assignmentId, current_user, strout)
    if teamname == None:
        if not hasTeam:
            # User is not part of any team for the assignment
            return json.dumps({'errorType' : websutil.ERR_OTHER,
                               'errorMessage' : "User is not part of any team for this assignment",
                               'errorTrace' : ""})
        teamname = current_team

    # Reset the timeout
    s.save()
    return websutil.getResultsHelper(courseId,
                                     assignmentId,
                                     current_user,
                                     strout,
                                     teamname = teamname,
                                     currentTeam = current_team)
예제 #2
0
def uploadedFile(req,
                 courseId,
                 assignmentId,
                 tmpname,
                 locale=websutil.DEFAULT_LOCALE):
    """ Saves a temp file of the uploaded archive and calls
        vmchecker.submit.submit method to put the homework in
        the testing queue"""

    websutil.install_i18n(websutil.sanityCheckLocale(locale))

    websutil.sanityCheckAssignmentId(assignmentId)
    websutil.sanityCheckCourseId(courseId)
    # TODO a better check is needed for tmpname
    websutil.sanityCheckDotDot(tmpname)

    # Check permission
    req.content_type = 'text/html'
    s = Session.Session(req)
    if s.is_new():
        s.invalidate()
        return json.dumps({
            'errorType': websutil.ERR_AUTH,
            'errorMessage': "",
            'errorTrace': ""
        })

    strout = websutil.OutputString()
    try:
        s.load()
        username = s['username']
    except:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType': websutil.ERR_EXCEPTION,
            'errorMessage': "",
            'errorTrace': strout.get()
        })

    # Reset the timeout
    s.save()

    # Call submit.py
    ## Redirect stdout to catch logging messages from submit
    sys.stdout = strout
    (hasTeam,
     account) = websutil.getAssignmentAccountName(courseId, assignmentId,
                                                  username, strout)
    try:
        if hasTeam:
            submit.submit(tmpname,
                          assignmentId,
                          account,
                          courseId,
                          user=username)
        else:
            submit.submit(tmpname, assignmentId, account, courseId)
        update_db.update_grades(courseId, account, assignment=assignmentId)
    except submit.SubmittedTooSoonError:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType': websutil.ERR_EXCEPTION,
            'errorMessage': _("Sent too fast"),
            'errorTrace': strout.get()
        })
    except submit.SubmittedTooLateError:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType':
            websutil.ERR_EXCEPTION,
            'errorMessage':
            _("The assignment was submitted too late"),
            'errorTrace':
            strout.get()
        })
    except:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType': websutil.ERR_EXCEPTION,
            'errorMessage': "",
            'errorTrace': strout.get()
        })

    return json.dumps({'status': True, 'dumpLog': strout.get()})
예제 #3
0
def beginEvaluation(req,
                    courseId,
                    assignmentId,
                    archiveFileName,
                    locale=websutil.DEFAULT_LOCALE):
    """ Saves a temp file of the uploaded archive and calls
        vmchecker.submit.submit method to put the homework in
        the testing queue"""

    websutil.install_i18n(websutil.sanityCheckLocale(locale))

    websutil.sanityCheckAssignmentId(assignmentId)
    websutil.sanityCheckCourseId(courseId)
    # TODO archiveFileName
    websutil.sanityCheckDotDot(archiveFileName)

    # Check permission
    req.content_type = 'text/html'
    s = Session.Session(req)
    if s.is_new():
        s.invalidate()
        return json.dumps({
            'errorType': websutil.ERR_AUTH,
            'errorMessage': "",
            'errorTrace': ""
        })

    strout = websutil.OutputString()
    try:
        s.load()
        username = s['username']
    except:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType': websutil.ERR_EXCEPTION,
            'errorMessage': "",
            'errorTrace': strout.get()
        })

    # Reset the timeout
    s.save()

    (_, account) = websutil.getAssignmentAccountName(courseId, assignmentId,
                                                     username, strout)
    archiveValidationResult = websutil.validate_md5_submission(
        courseId, assignmentId, account, archiveFileName)
    if not (archiveValidationResult[0]):
        return json.dumps({
            'status': False,
            'error': archiveValidationResult[1]
        })

    # Call submit.py
    ## Redirect stdout to catch logging messages from submit
    sys.stdout = strout

    try:
        submit.evaluate_large_submission(archiveFileName, assignmentId,
                                         account, courseId)
    except submit.SubmittedTooSoonError:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType':
            websutil.ERR_EXCEPTION,
            'errorMessage':
            _("The assignment was submitted too soon"),
            'errorTrace':
            strout.get()
        })
    except submit.SubmittedTooLateError:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType':
            websutil.ERR_EXCEPTION,
            'errorMessage':
            _("The assignment was submitted too late"),
            'errorTrace':
            strout.get()
        })
    except:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType': websutil.ERR_EXCEPTION,
            'errorMessage': "",
            'errorTrace': strout.get()
        })

    # Reset the timeout
    s.save()

    return json.dumps({'status': True, 'dumpLog': strout.get()})
예제 #4
0
def uploadAssignment(req,
                     courseId,
                     assignmentId,
                     archiveFile,
                     locale=websutil.DEFAULT_LOCALE):
    """ Saves a temp file of the uploaded archive and calls
        vmchecker.submit.submit method to put the homework in
        the testing queue"""

    websutil.install_i18n(websutil.sanityCheckLocale(locale))

    websutil.sanityCheckAssignmentId(assignmentId)
    websutil.sanityCheckCourseId(courseId)

    # Check permission
    req.content_type = 'text/html'
    s = Session.Session(req)
    if s.is_new():
        s.invalidate()
        return json.dumps({
            'errorType': websutil.ERR_AUTH,
            'errorMessage': "",
            'errorTrace': ""
        })

    strout = websutil.OutputString()
    try:
        s.load()
        username = s['username']
    except:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType': websutil.ERR_EXCEPTION,
            'errorMessage': "",
            'errorTrace': strout.get()
        })

    # Reset the timeout
    s.save()

    if archiveFile.filename == None:
        return json.dumps({
            'errorType': websutil.ERR_OTHER,
            'errorMessage': _("File not uploaded."),
            'errorTrace': ""
        })

    #  Save file in a temp location
    with tempfile.NamedTemporaryFile(
            suffix='.zip', bufsize=websutil.FILE_BUF_SIZE) as tmpfile:
        shutil.copyfileobj(archiveFile.file, tmpfile, websutil.FILE_BUF_SIZE)
        tmpfile.flush()

        # Call submit.py
        ## Redirect stdout to catch logging messages from submit
        sys.stdout = strout
        (hasTeam,
         account) = websutil.getAssignmentAccountName(courseId, assignmentId,
                                                      username, strout)
        try:
            if hasTeam:
                submit.submit(tmpfile.name,
                              assignmentId,
                              account,
                              courseId,
                              user=username)
            else:
                submit.submit(tmpfile.name, assignmentId, account, courseId)
            update_db.update_grades(courseId, account, assignment=assignmentId)
        except submit.SubmittedTooSoonError:
            traceback.print_exc(file=strout)
            return json.dumps({
                'errorType':
                websutil.ERR_EXCEPTION,
                'errorMessage':
                _("The assignment was submitted too soon"),
                'errorTrace':
                strout.get()
            })
        except submit.SubmittedTooLateError:
            traceback.print_exc(file=strout)
            return json.dumps({
                'errorType':
                websutil.ERR_EXCEPTION,
                'errorMessage':
                _("The assignment was submitted too late"),
                'errorTrace':
                strout.get()
            })
        except:
            traceback.print_exc(file=strout)
            return json.dumps({
                'errorType': websutil.ERR_EXCEPTION,
                'errorMessage': "",
                'errorTrace': strout.get()
            })

        return json.dumps({
            'status': True,
            'dumpLog': strout.get(),
            'file': tmpfile.name
        })
예제 #5
0
def uploadAssignment(req, courseId, assignmentId, archiveFile, locale=websutil.DEFAULT_LOCALE):
    """ Saves a temp file of the uploaded archive and calls
        vmchecker.submit.submit method to put the homework in
        the testing queue"""

    websutil.install_i18n(websutil.sanityCheckLocale(locale))
	
    websutil.sanityCheckAssignmentId(assignmentId)
    websutil.sanityCheckCourseId(courseId)

    # Check permission
    req.content_type = 'text/html'
    s = Session.Session(req)
    if s.is_new():
        s.invalidate()
        return json.dumps({'errorType':websutil.ERR_AUTH,
                'errorMessage':"",
                'errorTrace':""})

    strout = websutil.OutputString()
    try:
        s.load()
        username = s['username']
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':"",
            'errorTrace':strout.get()})  	
	
    # Reset the timeout
    s.save()

    if archiveFile.filename == None:
        return  json.dumps({'errorType':websutil.ERR_OTHER,
                    'errorMessage':_("File not uploaded."),
                    'errorTrace':""})

    #  Save file in a temp
    (fd, tmpname) = tempfile.mkstemp('.zip')
    f = open(tmpname, 'wb', 10000)
    ## Read the file in chunks
    for chunk in websutil.fbuffer(archiveFile.file):
        f.write(chunk)
    f.close()
    os.close(fd)

    # Call submit.py
    ## Redirect stdout to catch logging messages from submit
    sys.stdout = strout
    (hasTeam, account) = websutil.getAssignmentAccountName(courseId, assignmentId, username, strout)
    try:
        if hasTeam:
            submit.submit(tmpname, assignmentId, account, courseId, user = username)
        else:
            submit.submit(tmpname, assignmentId, account, courseId)
        update_db.update_grades(courseId, account, assignment = assignmentId)
    except submit.SubmittedTooSoonError:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':_("The assignment was submitted too soon"),
            'errorTrace':strout.get()})
    except submit.SubmittedTooLateError:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':_("The assignment was submitted too late"),
            'errorTrace':strout.get()})
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':"",
            'errorTrace':strout.get()})
	
    return json.dumps({'status':True,
                       'dumpLog':strout.get(),
                       'file': tmpname}) 
예제 #6
0
def uploadedFile(req, courseId, assignmentId, tmpname, locale=websutil.DEFAULT_LOCALE):
    """ Saves a temp file of the uploaded archive and calls
        vmchecker.submit.submit method to put the homework in
        the testing queue"""

    websutil.install_i18n(websutil.sanityCheckLocale(locale))

    websutil.sanityCheckAssignmentId(assignmentId)
    websutil.sanityCheckCourseId(courseId)
    # TODO a better check is needed for tmpname
    websutil.sanityCheckDotDot(tmpname)

    # Check permission
    req.content_type = 'text/html'
    s = Session.Session(req)
    if s.is_new():
        s.invalidate()
        return json.dumps({'errorType':websutil.ERR_AUTH,
                'errorMessage':"",
                'errorTrace':""})

    strout = websutil.OutputString()
    try:
        s.load()
        username = s['username']
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':"",
            'errorTrace':strout.get()})     
    
    # Reset the timeout
    s.save()

    # Call submit.py
    ## Redirect stdout to catch logging messages from submit
    sys.stdout = strout
    (hasTeam, account) = websutil.getAssignmentAccountName(courseId, assignmentId, username, strout)
    try:
        if hasTeam:
            submit.submit(tmpname, assignmentId, account, courseId, user = username)
        else:
            submit.submit(tmpname, assignmentId, account, courseId)
        update_db.update_grades(courseId, account, assignment = assignmentId)
    except submit.SubmittedTooSoonError:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':_("Sent too fast"),
            'errorTrace':strout.get()})
    except submit.SubmittedTooLateError:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':_("The assignment was submitted too late"),
            'errorTrace':strout.get()})
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':"",
            'errorTrace':strout.get()})
    
    return json.dumps({'status':True,
                       'dumpLog':strout.get()})
예제 #7
0
def beginEvaluation(req, courseId, assignmentId, archiveFileName, locale=websutil.DEFAULT_LOCALE):
    """ Saves a temp file of the uploaded archive and calls
        vmchecker.submit.submit method to put the homework in
        the testing queue"""

    websutil.install_i18n(websutil.sanityCheckLocale(locale))

    websutil.sanityCheckAssignmentId(assignmentId)
    websutil.sanityCheckCourseId(courseId)
    # TODO archiveFileName
    websutil.sanityCheckDotDot(archiveFileName)

    # Check permission
    req.content_type = 'text/html'
    s = Session.Session(req)
    if s.is_new():
        s.invalidate()
        return json.dumps({'errorType':websutil.ERR_AUTH,
                'errorMessage':"",
                'errorTrace':""})

    strout = websutil.OutputString()
    try:
        s.load()
        username = s['username']
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':"",
            'errorTrace':strout.get()})

    # Reset the timeout
    s.save()

    (_, account) = websutil.getAssignmentAccountName(courseId, assignmentId, username, strout)
    archiveValidationResult = websutil.validate_md5_submission(courseId, assignmentId, account, archiveFileName)
    if not(archiveValidationResult[0]):
        return json.dumps({'status' : False, 'error' : archiveValidationResult[1]});

    # Call submit.py
    ## Redirect stdout to catch logging messages from submit
    sys.stdout = strout

    try:
        submit.evaluate_large_submission(archiveFileName, assignmentId, account, courseId)
    except submit.SubmittedTooSoonError:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':_("The assignment was submitted too soon"),
            'errorTrace':strout.get()})
    except submit.SubmittedTooLateError:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':_("The assignment was submitted too late"),
            'errorTrace':strout.get()})
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':websutil.ERR_EXCEPTION,
            'errorMessage':"",
            'errorTrace':strout.get()})

    # Reset the timeout
    s.save()

    return json.dumps({'status':True,
                       'dumpLog':strout.get()})