Ejemplo n.º 1
0
def reset(user, request):
    name = request.POST['name']
    program = UserProgram.find(user, name)
    program.reset()
    UserProgram.store(program)
    return HttpResponseRedirect(reverse('mips.views.details',
                                        kwargs={'name':program.name}))
Ejemplo n.º 2
0
def details(user, request, name):
    program = UserProgram.find(user, name)
    code = program.code
    lines = code.splitlines()
    return render_to_response("mips/details.html",
                              {'program' : program,
                               'code_lines' : lines,
                               'logout_url' : logout_url()})
Ejemplo n.º 3
0
def add(user, request):
    name = request.POST['name']
    if not UserProgram.find(user, name):
        UserProgram.create_program(user,name)
        return HttpResponseRedirect(reverse('mips.views.programs'))
    else:
        msg = "Program with name '%s' already exists" % name
        logging.info("EXCEPTION " + msg)
        response = HttpResponseRedirect(reverse('mips.views.programs'))
        response.set_cookie('exception', msg)
        return response
Ejemplo n.º 4
0
def delete(user, request):
    name = request.POST['name']
    prog = UserProgram.find(user, name)
    if prog:
        UserProgram.remove(prog)
        return HttpResponseRedirect(reverse('mips.views.programs'))
    else:
        msg = "Cannot delete program with name '%s'<br /> because it does not exist." % name
        response = HttpResponseRedirect(reverse('mips.views.programs'))
        response.set_cookie('exception', msg)
        return response
Ejemplo n.º 5
0
def run(user, request, name):
    program = UserProgram.find(user, name)
    result = {}

    if not program:
        raise ProgramNotFound("Program not found!")

    if program.is_suspended():
        program.resume()
        state = program.state()
        output = program.output()
        result = mipsrunner.run_with_state(state, output)
    else:
        logging.info("executing program")
        prog_text = mipsrunner.format_user_program(str(program.code))
        result = mipsrunner.run_program(prog_text, [])

    if not result.get('exception'):
        if result['suspended']:
            program.suspend()

        program.set_state(result['state'])
        program.set_output(result['output'])
        UserProgram.store(program)

        registers = program.registers()
        output = helpers.format_output(result['output'])
        json_data = render_to_string("mips/details.json",
                                     {'registers' : registers,
                                      'output' : output})
        return HttpResponse(json_data, mimetype="application/javascript")

    else:
        response = "{'exception': '%s', 'msg_list': %s}" % (
            result['exception'], result['msg_list'])
        return HttpResponse(response, mimetype="application/javascript")