Beispiel #1
0
def graphLoadInv(request):
    ''' Form '''
    if request.method == 'POST':
        form = GraphUploadForm(request.POST,
                               request.FILES)  # instantiating form
        if form.is_valid():

            data = form.files['fileObj']  # get data
            invariants = form.cleaned_data[
                'Select_Invariants_you_want_computed']

            data_dir = os.path.join(
                settings.MEDIA_ROOT, 'public',
                strftime("projectStamp%a%d%b%Y_%H.%M.%S/", localtime()))
            invariants_path = os.path.join(data_dir, 'graphInvariants')

            makeDirIfNone([data_dir])

            # We got a zip
            if os.path.splitext(data.name)[1] == '.zip':
                writeBodyToDisk(data.read(), data_dir)
                graphs = glob(os.path.join(data_dir, '*'))

            else:  # View only accepts a subset of file formats as regulated by template Validate func
                graphs = [os.path.join(data_dir, data.name)]
                saveFileToDisk(data, graphs[0])

            request.session['graph_format'] = form.cleaned_data['graph_format']
            request.session['email'] = form.cleaned_data['email']

            # Launch thread for graphs & email user
            sendJobBeginEmail(request.session['email'],
                              invariants,
                              genGraph=False)

            for graph_fn in graphs:
                task_invariant_compute.delay(invariants, graph_fn,
                                             invariants_path, data_dir,
                                             form.cleaned_data['graph_format'],
                                             request.session['email'])

            request.session['success_msg'] = \
      """
Your job successfully launched. You should receive an email when your job begins and another one when it completes.<br/>
The process may take several hours (dependent on graph size) if you selected to compute all invariants.<br/>
If you do not see an email in your <i>Inbox</i> check the <i>Spam</i> folder and add <code>[email protected]</code> 
to your safe list.
"""
            return HttpResponseRedirect(get_script_prefix() + 'success')
    else:
        form = GraphUploadForm()  # An empty, unbound form

    # Render the form
    return render_to_response(
        'graphupload.html',
        {'graphUploadForm': form},
        context_instance=RequestContext(
            request
        )  # Some failure to input data & returns a key signaling what is requested
    )
Beispiel #2
0
def graph_load_inv_prog(request, webargs):
    if request.method == 'POST' and webargs:

        split_webargs = webargs.split("/")
        to_email = split_webargs[0]
        if (not check_email(to_email)):
            return HttpResponse("ERROR: Incorrect email address format")

        try:
            in_graph_format = split_webargs[1]
            if in_graph_format not in ("graphml", "ncol", "edgelist", "lgl",
                                       "pajek", "graphdb", "numpy", "mat"):
                return HttpResponse("ERROR: Unknown graph input format")
            invariants = split_webargs[2:]
            for inv in invariants:
                if inv not in settings.VALID_FILE_TYPES:
                    return HttpResponse(
                        "ERROR: Invariant '{0}' unknown!".format(inv))

            if not invariants:
                return HttpResponse("ERROR: No invariants to compute provided")
        except:
            return HttpResponse(
                "ERROR: Opaque Error with input graph format OR invariants chosen"
            )

        data_dir = os.path.join(
            settings.MEDIA_ROOT, 'public',
            strftime("UploadGraph%a%d%b%Y_%H.%M.%S/", localtime()))
        makeDirIfNone([data_dir])
        uploadedZip = writeBodyToDisk(request.body,
                                      data_dir)[0]  # Not necessarily a zip

        try:  # Assume its a zip first
            unzip(uploadedZip, data_dir)  # Unzip the zip
            os.remove(uploadedZip)  # Delete the zip
        except:
            print "Non-zip file uploaded ..."

        graph_invariants_loc = os.path.join(data_dir, 'graphInvariants')
        makeDirIfNone([graph_invariants_loc])

        task_invariant_compute.delay(invariants, uploadedZip,
                                     graph_invariants_loc, data_dir,
                                     in_graph_format, to_email)

        sendJobBeginEmail(to_email, invariants)

        return HttpResponse("Successful job submission, please " \
                              "await reception & completion emails at {0}".format(to_email))
    else:
        return HttpResponse("There was an error! If you believe it " \
                              "is on our end please email: {0}".format(settings.DEFAULT_FROM_EMAIL))
Beispiel #3
0
def graphLoadInv(request):
  ''' Form '''
  if request.method == 'POST':
    form = GraphUploadForm(request.POST, request.FILES) # instantiating form
    if form.is_valid():

      data = form.files['fileObj'] # get data
      invariants = form.cleaned_data['Select_Invariants_you_want_computed']

      data_dir = os.path.join(settings.MEDIA_ROOT, 'public', 
              strftime("projectStamp%a%d%b%Y_%H.%M.%S/", localtime()))
      invariants_path = os.path.join(data_dir, 'graphInvariants')

      makeDirIfNone([data_dir])

      # We got a zip
      if os.path.splitext(data.name)[1] == '.zip':
        writeBodyToDisk(data.read(), data_dir)
        graphs = glob(os.path.join(data_dir,'*')) 

      else: # View only accepts a subset of file formats as regulated by template Validate func
        graphs = [os.path.join(data_dir, data.name)]
        saveFileToDisk(data, graphs[0])

      request.session['graph_format'] = form.cleaned_data['graph_format']
      request.session['email'] = form.cleaned_data['email']

      # Launch thread for graphs & email user
      sendJobBeginEmail(request.session['email'], invariants, genGraph=False)

      for graph_fn in graphs:
        task_invariant_compute.delay(invariants, graph_fn, invariants_path, 
                data_dir, form.cleaned_data['graph_format'], request.session['email'])

      request.session['success_msg'] = \
"""
Your job successfully launched. You should receive an email when your job begins and another one when it completes.<br/>
The process may take several hours (dependent on graph size) if you selected to compute all invariants.<br/>
If you do not see an email in your <i>Inbox</i> check the <i>Spam</i> folder and add <code>[email protected]</code> 
to your safe list.
"""
      return HttpResponseRedirect(get_script_prefix()+'success')
  else:
    form = GraphUploadForm() # An empty, unbound form

  # Render the form
  return render_to_response(
      'graphupload.html',
      {'graphUploadForm': form},
      context_instance=RequestContext(request) # Some failure to input data & returns a key signaling what is requested
  )
Beispiel #4
0
def graph_load_inv_prog(request, webargs):
  if request.method == 'POST' and webargs:

    split_webargs = webargs.split("/")
    to_email = split_webargs[0]
    if (not check_email(to_email)):
      return HttpResponse("ERROR: Incorrect email address format")

    try:
      in_graph_format = split_webargs[1]
      if in_graph_format not in ("graphml", "ncol", "edgelist", "lgl", "pajek", "graphdb", "numpy", "mat"):
        return HttpResponse("ERROR: Unknown graph input format")
      invariants = split_webargs[2:]
      for inv in invariants:
        if inv not in settings.VALID_FILE_TYPES:
          return HttpResponse("ERROR: Invariant '{0}' unknown!".format(inv))

      if not invariants: 
        return HttpResponse("ERROR: No invariants to compute provided")
    except:
      return HttpResponse("ERROR: Opaque Error with input graph format OR invariants chosen")

    data_dir = os.path.join(settings.MEDIA_ROOT, 'public', strftime("UploadGraph%a%d%b%Y_%H.%M.%S/", localtime()))
    makeDirIfNone([data_dir])
    uploadedZip = writeBodyToDisk(request.body, data_dir)[0] # Not necessarily a zip

    try: # Assume its a zip first
      unzip(uploadedZip, data_dir) # Unzip the zip
      os.remove(uploadedZip) # Delete the zip
    except:
      print "Non-zip file uploaded ..."

    graph_invariants_loc = os.path.join(data_dir, 'graphInvariants')
    makeDirIfNone([graph_invariants_loc])

    task_invariant_compute.delay(invariants, uploadedZip, graph_invariants_loc, 
        data_dir, in_graph_format, to_email)

    sendJobBeginEmail(to_email, invariants)

    return HttpResponse("Successful job submission, please " \
                          "await reception & completion emails at {0}".format(to_email))
  else:
    return HttpResponse("There was an error! If you believe it " \
                          "is on our end please email: {0}".format(settings.DEFAULT_FROM_EMAIL))
Beispiel #5
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))
Beispiel #6
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))
Beispiel #7
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) 
  )