Esempio n. 1
0
def buildGraph(request):

    error_msg = ""

    if request.method == "POST":
        form = BuildGraphForm(request.POST,
                              request.FILES)  # instantiating form
        if form.is_valid():

            # Acquire proj names
            proj_dir = form.cleaned_data["UserDefprojectName"]
            site = form.cleaned_data["site"]
            subject = form.cleaned_data["subject"]
            session = form.cleaned_data["session"]
            scanId = form.cleaned_data["scanId"]
            """
      # Private project error checking
      if (form.cleaned_data["Project_Type"] == "private"):
        if not request.user.is_authenticated():
          error_msg = "You must be logged in to make/alter a private project! \
              Please Login or make/alter a public project."

        # Untested TODO: Add join to ensure it a private project
        elif BuildGraphModel.objects.filter(owner=request.user, \
            project_name=proj_dir, site=site, subject=subject, \
            session=session, scanId=scanId).exists():

           error_msg = "The scanID you requested to create already \
               exists in this project path. Please change any of the form values."
      """
            if error_msg:
                return render_to_response(
                    "buildgraph.html", {
                        "buildGraphform": form,
                        "error_msg": error_msg
                    },
                    context_instance=RequestContext(request))
            """
      # If a user is logged in associate the project with thier directory
      if form.cleaned_data["Project_Type"] == "private":
        proj_dir = os.path.join(request.user.username, proj_dir)
      else:
      """
            proj_dir = os.path.join("public", proj_dir)

            # Adapt project name if necesary on disk
            proj_dir = adaptProjNameIfReq(
                os.path.join(
                    settings.MEDIA_ROOT,
                    proj_dir))  # Fully qualify AND handle identical projects

            usrDefProjDir = os.path.join(proj_dir, site, subject, session,
                                         scanId)
            """ Define data directory paths """
            derivatives, graphs = defDataDirs(usrDefProjDir)

            # Create a model object to save data to DB

            grModObj = BuildGraphModel(
                project_name=form.cleaned_data["UserDefprojectName"])
            grModObj.location = usrDefProjDir  # The particular scan location

            grModObj.site = site
            grModObj.subject = subject
            grModObj.session = session
            grModObj.scanId = scanId

            if request.user.is_authenticated():
                grModObj.owner = request.user  # Who created the project

            invariants = form.cleaned_data["invariants"]
            graph_size = form.cleaned_data["graph_size"]
            email = form.cleaned_data["email"]

            if graph_size == "big" and not email:
                return render_to_response(
                    "buildgraph.html", {
                        "buildGraphform":
                        form,
                        "error_msg":
                        "Email address must be \
              provided when processing big graphs due to http timeout's possibly occurring."
                    },
                    context_instance=RequestContext(request))
            """ Acquire fileNames """
            fiber_fn = form.cleaned_data[
                "fiber_file"].name  # get the name of the file input by user
            if form.cleaned_data["data_atlas_file"]:
                data_atlas_fn = form.cleaned_data["data_atlas_file"].name
                print "Storing data atlas ..."
                saveFileToDisk(form.cleaned_data["data_atlas_file"],
                               os.path.join(derivatives, data_atlas_fn))

            print "Storing fibers ..."
            """ Save files in appropriate location """
            saveFileToDisk(form.cleaned_data["fiber_file"],
                           os.path.join(derivatives, fiber_fn))
            grModObj.save()  # Save project data to DB after file upload

            # add entry to owned project
            if request.user.is_authenticated():
                ownedProjModObj = OwnedProjects(project_name=grModObj.project_name, \
                  owner=grModObj.owner, is_private=form.cleaned_data["Project_Type"] == "private")
                ownedProjModObj.save()

            print "\nSaving all files complete..."

            # Make appropriate dirs if they dont already exist
            create_dir_struct([derivatives, graphs])

            # TEST #
            """
      derivatives = "/home/disa/test/build_test"
      graphs = derivatives
      proj_dir = derivatives
      invariant_loc = derivatives 
      # END TEST #
      """

            sendJobBeginEmail(email, invariants)
            task_build.delay(derivatives, graphs, graph_size, invariants,
                             derivatives, email)
            request.session["success_msg"] =\
      """
Your job successfully launched. You should receive an email to confirm launch
and another when it upon job completion. <br/>
<i>The process may take several hours</i> if you selected to compute all invariants.
"""
            return HttpResponseRedirect(get_script_prefix() + "success")

    else:
        form = BuildGraphForm()  # An empty, unbound form

    # Render the form
    return render_to_response("buildgraph.html", {"buildGraphform": form},
                              context_instance=RequestContext(request))
Esempio n. 2
0
def build_graph_prog(request, webargs):
    if request.method == "POST" and webargs:

        webargs = webargs.split("/")
        proj_dir, site, subject, session, scanId = webargs[:5]
        email = webargs[6]
        if (not check_email(email)):
            return HttpResponse("ERROR: Incorrect email address format")

        invariants = webargs[7:]

        proj_dir = os.path.join("public", proj_dir)

        # Adapt project name if necesary on disk
        proj_dir = adaptProjNameIfReq(
            os.path.join(
                settings.MEDIA_ROOT,
                proj_dir))  # Fully qualify AND handle identical projects

        usrDefProjDir = os.path.join(proj_dir, site, subject, session, scanId)
        """ Define data directory paths """
        derivatives, graphs = defDataDirs(usrDefProjDir)

        # Create a model object to save data to DB
        grModObj = BuildGraphModel(project_name=webargs[0])
        grModObj.location = usrDefProjDir  # The particular scan location

        grModObj.site = site
        grModObj.subject = subject
        grModObj.session = session
        grModObj.scanId = scanId
        grModObj.save()  # Save project data to DB after file upload

        graph_size = webargs[5]
        save_dir = getworkdir()
        uploaded_files = writeBodyToDisk(request.body, save_dir)
        graph_loc = os.path.join(save_dir, "graphs")
        if not os.path.exists(graph_loc): os.makedirs(graph_loc)

        # add entry to owned project
        if request.user.is_authenticated():
            ownedProjModObj = OwnedProjects(project_name=grModObj.project_name, \
              owner=grModObj.owner, is_private=form.cleaned_data["Project_Type"] == "private")
            ownedProjModObj.save()

        print "\nSaving all files complete..."

        # TEST #
        """
    derivatives = "/home/disa/test/build_test"
    graphs = derivatives
    # END TEST #
    """

        sendJobBeginEmail(email, invariants)
        task_build.delay(save_dir, graph_loc, graph_size, invariants, save_dir,
                         email)
        return HttpResponse("Successful job submission, please " \
                              "await reception & completion emails at {0}".format(email))
    else:
        return HttpResponse("There was an error! If you believe it " \
                              "is on our end please email: {0}".format(settings.DEFAULT_FROM_EMAIL))
Esempio n. 3
0
def buildGraph(request):

  error_msg = ""

  if request.method == "POST":
    form = BuildGraphForm(request.POST, request.FILES) # instantiating form
    if form.is_valid():

      # Acquire proj names
      proj_dir = form.cleaned_data["UserDefprojectName"]
      site = form.cleaned_data["site"]
      subject = form.cleaned_data["subject"]
      session = form.cleaned_data["session"]
      scanId = form.cleaned_data["scanId"]

      """
      # Private project error checking
      if (form.cleaned_data["Project_Type"] == "private"):
        if not request.user.is_authenticated():
          error_msg = "You must be logged in to make/alter a private project! \
              Please Login or make/alter a public project."

        # Untested TODO: Add join to ensure it a private project
        elif BuildGraphModel.objects.filter(owner=request.user, \
            project_name=proj_dir, site=site, subject=subject, \
            session=session, scanId=scanId).exists():

           error_msg = "The scanID you requested to create already \
               exists in this project path. Please change any of the form values."
      """
      if error_msg:
        return render_to_response(
          "buildgraph.html",
          {"buildGraphform": form, "error_msg": error_msg},
          context_instance=RequestContext(request)
          )

      """
      # If a user is logged in associate the project with thier directory
      if form.cleaned_data["Project_Type"] == "private":
        proj_dir = os.path.join(request.user.username, proj_dir)
      else:
      """
      proj_dir = os.path.join("public", proj_dir)

      # Adapt project name if necesary on disk
      proj_dir = adaptProjNameIfReq(os.path.join(
          settings.MEDIA_ROOT, proj_dir)) # Fully qualify AND handle identical projects

      usrDefProjDir = os.path.join(proj_dir, site, subject, session, scanId)
      """ Define data directory paths """
      derivatives, graphs = defDataDirs(usrDefProjDir)

      # Create a model object to save data to DB

      grModObj = BuildGraphModel(project_name = form.cleaned_data["UserDefprojectName"])
      grModObj.location = usrDefProjDir # The particular scan location

      grModObj.site = site
      grModObj.subject = subject
      grModObj.session = session
      grModObj.scanId = scanId

      if request.user.is_authenticated():
        grModObj.owner = request.user # Who created the project

      invariants = form.cleaned_data["invariants"]
      graph_size = form.cleaned_data["graph_size"]
      email = form.cleaned_data["email"]

      if graph_size == "big" and not email:
        return render_to_response(
          "buildgraph.html",
          {"buildGraphform": form, "error_msg": "Email address must be \
              provided when processing big graphs due to http timeout's possibly occurring."},
          context_instance=RequestContext(request)
          )

      """ Acquire fileNames """
      fiber_fn = form.cleaned_data["fiber_file"].name # get the name of the file input by user
      if form.cleaned_data["data_atlas_file"]:
        data_atlas_fn = form.cleaned_data["data_atlas_file"].name
        print "Storing data atlas ..."
        saveFileToDisk(form.cleaned_data["data_atlas_file"], 
            os.path.join(derivatives, data_atlas_fn))

      print "Storing fibers ..."
      """ Save files in appropriate location """
      saveFileToDisk(form.cleaned_data["fiber_file"], 
          os.path.join(derivatives, fiber_fn))
      grModObj.save() # Save project data to DB after file upload

      # add entry to owned project
      if request.user.is_authenticated():
        ownedProjModObj = OwnedProjects(project_name=grModObj.project_name, \
          owner=grModObj.owner, is_private=form.cleaned_data["Project_Type"] == "private")
        ownedProjModObj.save()

      print "\nSaving all files complete..."

      # Make appropriate dirs if they dont already exist
      create_dir_struct([derivatives, graphs])

      # TEST #
      """
      derivatives = "/home/disa/test/build_test"
      graphs = derivatives
      proj_dir = derivatives
      invariant_loc = derivatives 
      # END TEST #
      """

      sendJobBeginEmail(email, invariants)
      task_build.delay(derivatives, graphs, graph_size, invariants, derivatives, email)
      request.session["success_msg"] =\
"""
Your job successfully launched. You should receive an email to confirm launch
and another when it upon job completion. <br/>
<i>The process may take several hours</i> if you selected to compute all invariants.
"""
      return HttpResponseRedirect(get_script_prefix()+"success")

  else:
    form = BuildGraphForm() # An empty, unbound form

  # Render the form
  return render_to_response(
      "buildgraph.html",
      {"buildGraphform": form},
      context_instance=RequestContext(request) 
  )