Exemplo n.º 1
0
def processInputData(request):
  '''
  Extract File name & determine what file corresponds to what for gengraph
  @param request: the request object
  '''
  filesInUploadDir = os.listdir(request.session['derivatives'])

  roi_xml_fn, fiber_fn, roi_raw_fn = checkFileExtGengraph(filesInUploadDir) # Check & sort files

  ''' Fully qualify file names '''
  fiber_fn = os.path.join(request.session['derivatives'], fiber_fn)
  roi_raw_fn = os.path.join(request.session['derivatives'], roi_raw_fn)
  roi_xml_fn = os.path.join(request.session['derivatives'], roi_xml_fn)

  try:
    request.session['Gfn']= call_gengraph(fiber_fn, roi_xml_fn, roi_raw_fn, \
                              request.session['graphs'], request.session['graphInvariants'],\
                              request.session['graphsize'], True)
  except:
    if request.session['graphsize'] == 'big':
      msg = "Hello,\n\nYour most recent job failed either because your fiber streamline file or ROI mask was incorrectly formatted."
      msg += " Please check both and try again.%s\n\n" % (" "*randint(0,10))
      sendJobFailureEmail(request.session['email'], msg)
    return HttpResponseRedirect(get_script_prefix()+"jobfailure")

  # Run ivariants here
  if len(request.session['invariants']) > 0:
    print "Computing invariants ..."

    request.session['invariant_fns'] = runInvariants(request.session['invariants'],\
                                request.session['Gfn'], request.session['graphInvariants'])

  if request.session['graphsize'] == 'big':
    dwnldLoc = request.META['wsgi.url_scheme'] + '://' + \
                    request.META['HTTP_HOST'] + request.session['usrDefProjDir'].replace(' ','%20')
    sendJobCompleteEmail(request.session['email'], dwnldLoc)

  return HttpResponseRedirect(get_script_prefix()+'confirmdownload')
Exemplo n.º 2
0
def upload(request, webargs=None):
  """
  Programmatic interface for uploading data
  @param request: the request object

  @param webargs: POST data with userDefProjectName, site, subject, session, scanId, graphsize, [list of invariants to compute] info
  """
  if (webargs and request.method == 'POST'):
    # Check for malformatted input
    webargs = webargs[1:] if webargs.startswith('/') else webargs
    webargs = webargs[:-1] if webargs.endswith('/') else webargs

    if len(webargs.split('/')) == 7:
      [userDefProjectName, site, subject, session, scanId, graphsize, request.session['invariants']] = webargs.split('/')

      request.session['invariants'] = request.session['invariants'].split(',')
    elif len(webargs.split('/')) == 6:
      [userDefProjectName, site, subject, session, scanId, graphsize] = webargs.split('/')
    else:
      # Some sort of error
      return HttpResponseBadRequest ("Malformatted programmatic request. Check format of url and data requests")

    userDefProjectDir = adaptProjNameIfReq(os.path.join(settings.MEDIA_ROOT, 'public', userDefProjectName, site, subject, session, scanId))

    ''' Define data directory paths '''
    derivatives, graphs, request.session['graphInvariants'] = defDataDirs(userDefProjectDir)

    ''' Make appropriate dirs if they dont already exist '''
    create_dir_struct([derivatives, graphs,request.session["graphInvariants"]])
    print 'Directory structure created...'

    uploadFiles =  writeBodyToDisk(request.body, derivatives)

    # Check which file is which
    roi_xml_fn, fiber_fn, roi_raw_fn = checkFileExtGengraph(uploadFiles) # Check & sort files

    ''' Data Processing '''
    if graphsize:
      request.session['Gfn']= call_gengraph(fiber_fn, roi_xml_fn, roi_raw_fn, \
                              graphs, request.session['graphInvariants'],\
                              graphsize, run=True)

    else:
      return HttpResponseBadRequest ("Missing graph size. You must specify big or small")


    # Run invariants
    if request.session.has_key('invariants'):
      print "Computing invariants ..."

      invariant_fns = runInvariants(request.session['invariants'],\
                      request.session['Gfn'], request.session['graphInvariants'])

    dwnldLoc = request.META['wsgi.url_scheme'] + '://' + \
                    request.META['HTTP_HOST'] + userDefProjectDir.replace(' ','%20')

    return HttpResponse ( "Files available for download at " + dwnldLoc) # change to render of a page with a link to data result

  elif(not webargs):
    return HttpResponseBadRequest ("Expected web arguments to direct project correctly")

  else:
    return HttpResponseBadRequest ("Expected POST data, but none given")