Пример #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
    )
Пример #2
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
  )
Пример #3
0
def convert_graph_prog(request, webargs):
    if (request.method == 'POST' and webargs):
        split_webargs = webargs.split("/")
        link_only = False
        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")

            out_graph_format = list(set(split_webargs[2].split(",")))
            if not out_graph_format:
                return HttpResponse(
                    "ERROR: No output formats to compute provided")

            if len(split_webargs) == 4:
                if split_webargs[3] != "l":
                    return HttpResponse(
                        "ERROR: Final parameter '{0}', expected 'l'".format(
                            split_webargs[3]))
                else:
                    link_only = True
        except:
            return HttpResponse(
                "ERROR: Error with input graph format OR invariants chosen")

        save_dir, convert_file_save_loc = getworkdirs()
        uploaded_files = writeBodyToDisk(
            request.body, save_dir)  # can only be one file # TODO: Check me

        # Check for zip
        if os.path.splitext(uploaded_files[0])[1].strip() == '.zip':
            unzip(uploaded_files[0], save_dir)
            # Delete zip so its not included in the graphs we uploaded
            os.remove(uploaded_files[0])
            uploaded_files = glob(os.path.join(
                save_dir, "*"))  # get the uploaded file names

        task_convert.delay(settings.MEDIA_ROOT, uploaded_files,
                           convert_file_save_loc, in_graph_format,
                           out_graph_format, to_email)

        if link_only:
            return HttpResponse(get_download_path(convert_file_save_loc))

        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))
Пример #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))
Пример #5
0
def convert_graph_prog(request, webargs):
  if(request.method == 'POST' and webargs):
    split_webargs = webargs.split("/")
    link_only = False
    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")

      out_graph_format = list(set(split_webargs[2].split(",")))
      if not out_graph_format: 
        return HttpResponse("ERROR: No output formats to compute provided")

      if len(split_webargs) == 4:
        if split_webargs[3] != "l":
          return HttpResponse("ERROR: Final parameter '{0}', expected 'l'".format(split_webargs[3]))
        else:
          link_only = True
    except:
      return HttpResponse("ERROR: Error with input graph format OR invariants chosen")


    save_dir, convert_file_save_loc = getworkdirs()
    uploaded_files = writeBodyToDisk(request.body, save_dir)# can only be one file # TODO: Check me

    # Check for zip
    if os.path.splitext(uploaded_files[0])[1].strip() == '.zip':
      unzip(uploaded_files[0], save_dir)
      # Delete zip so its not included in the graphs we uploaded
      os.remove(uploaded_files[0])
      uploaded_files = glob(os.path.join(save_dir, "*")) # get the uploaded file names

    task_convert.delay(settings.MEDIA_ROOT, uploaded_files, convert_file_save_loc,
    in_graph_format, out_graph_format, to_email)

    if link_only:
      return HttpResponse(get_download_path(convert_file_save_loc))

    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))
Пример #6
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))
Пример #7
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))