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 = filesorter.checkFileExtGengraph(filesInUploadDir) # Check & sort files for fileName in [roi_xml_fn, fiber_fn, roi_raw_fn]: if fileName == "": # Means a file is missing from i/p return render_to_response('pipelineUpload.html', context_instance=RequestContext(request)) # Missing file for processing Gengraph baseName = fiber_fn[:-9] # MAY HAVE TO CHANGE ''' 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['smGrfn'], request.session['bgGrfn'], request.session['lccfn']\ ,request.session['SVDfn'] = processData(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" if (request.session['graphsize'] == 'big'): graph_fn = request.session['bgGrfn'] lcc_fn = request.session['lccfn'] elif (request.session['graphsize'] == 'small'): graph_fn = request.session['smGrfn'] lcc_fn = None request.session['invariant_fns'] = runInvariants(request.session['invariants'],\ graph_fn, request.session['graphInvariants'],\ lcc_fn, request.session['graphsize']) if request.session['graphsize'] == 'big': sendJobCompleteEmail(request.session['email'], 'http://mrbrain.cs.jhu.edu' + request.session['usrDefProjDir'].replace(' ','%20')) return HttpResponseRedirect(get_script_prefix()+'confirmdownload')
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 = filesorter.checkFileExtGengraph( filesInUploadDir) # Check & sort files for fileName in [roi_xml_fn, fiber_fn, roi_raw_fn]: if fileName == "": # Means a file is missing from i/p return render_to_response( 'pipelineUpload.html', context_instance=RequestContext( request)) # Missing file for processing Gengraph baseName = fiber_fn[:-9] # MAY HAVE TO CHANGE ''' 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) request.session['smGrfn'], request.session['bgGrfn'], request.session['lccfn']\ ,request.session['SVDfn'] = processData(fiber_fn, roi_xml_fn, roi_raw_fn, \ request.session['graphs'], request.session['graphInvariants'],\ request.session['graphsize'], True) # Run ivariants here if len(request.session['invariants']) > 0: print "Computing invariants" if (request.session['graphsize'] == 'big'): graph_fn = request.session['bgGrfn'] lcc_fn = request.session['lccfn'] elif (request.session['graphsize'] == 'small'): graph_fn = request.session['smGrfn'] lcc_fn = None request.session['invariant_fns'] = runInvariants(request.session['invariants'],\ graph_fn, request.session['graphInvariants'],\ lcc_fn, request.session['graphsize']) return HttpResponseRedirect(get_script_prefix() + 'confirmdownload')
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 = filesorter.checkFileExtGengraph(filesInUploadDir) # Check & sort files for fileName in [roi_xml_fn, fiber_fn, roi_raw_fn]: if fileName == "": # Means a file is missing from i/p return render_to_response('pipelineUpload.html', context_instance=RequestContext(request)) # Missing file for processing Gengraph baseName = fiber_fn[:-9] # MAY HAVE TO CHANGE ''' 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) request.session['smGrfn'], request.session['bgGrfn'], request.session['lccfn']\ ,request.session['SVDfn'] = processData(fiber_fn, roi_xml_fn, roi_raw_fn, \ request.session['graphs'], request.session['graphInvariants'],\ request.session['graphsize'], True) # Run ivariants here if len(request.session['invariants']) > 0: print "Computing invariants" if (request.session['graphsize'] == 'big'): graph_fn = request.session['bgGrfn'] lcc_fn = request.session['lccfn'] elif (request.session['graphsize'] == 'small'): graph_fn = request.session['smGrfn'] lcc_fn = None request.session['invariant_fns'] = runInvariants(request.session['invariants'],\ graph_fn, request.session['graphInvariants'],\ lcc_fn, request.session['graphsize']) return HttpResponseRedirect(get_script_prefix()+'confirmdownload')
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 """ # request.session.clear() 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('/') userDefProjectDir = adaptProjNameIfReq( os.path.join(settings.MEDIA_ROOT, 'public', userDefProjectName, site, subject, session, scanId)) ''' Define data directory paths ''' derivatives, rawdata, graphs, request.session[ 'graphInvariants'], images = defDataDirs(userDefProjectDir) ''' Make appropriate dirs if they dont already exist ''' createDirStruct.createDirStruct([ derivatives, rawdata, graphs, request.session['graphInvariants'], images ]) print 'Directory structure created...' uploadFiles = writeBodyToDisk(request.body, derivatives) # Check which file is which roi_xml_fn, fiber_fn, roi_raw_fn = filesorter.checkFileExtGengraph( uploadFiles) # Check & sort files ''' Data Processing ''' if (re.match(re.compile('(b|big)', re.IGNORECASE), graphsize)): request.session['graphsize'] = 'big' request.session['smGrfn'], request.session['bgGrfn'], lccfn, SVDfn \ = processData(fiber_fn, roi_xml_fn, roi_raw_fn,graphs,\ request.session['graphInvariants'],\ request.session['graphsize'],True) elif (re.match(re.compile('(s|small)', re.IGNORECASE), graphsize)): request.session['graphsize'] = 'small' request.session['smGrfn'], request.session['bgGrfn'], lccfn, SVDfn \ = processData(fiber_fn, roi_xml_fn, roi_raw_fn,graphs, request.session['graphInvariants'], request.session['graphsize'],True) else: return django.http.HttpResponseBadRequest( "Missing graph size. Specify big or small") # Run invariants if len(request.session['invariants']) > 0: print "Computing invariants" if (request.session['graphsize'] == 'big'): graph_fn = request.session['bgGrfn'] lcc_fn = request.session['lccfn'] elif (request.session['graphsize'] == 'small'): graph_fn = request.session['smGrfn'] lcc_fn = None invariant_fns = runInvariants(request.session['invariants'],\ graph_fn, request.session['graphInvariants'],\ lcc_fn, request.session['graphsize']) #ret = rzfile.printdir() #ret = rzfile.testzip() #ret = rzfile.namelist() # request.session.clear() dwnldLoc = "http://mrbrain.cs.jhu.edu" + 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): # request.session.clear() return django.http.HttpResponseBadRequest( "Expected web arguments to direct project correctly") else: # request.session.clear() return django.http.HttpResponseBadRequest( "Expected POST data, but none given")
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 """ # request.session.clear() 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('/') userDefProjectDir = adaptProjNameIfReq(os.path.join(settings.MEDIA_ROOT, 'public', userDefProjectName, site, subject, session, scanId)) ''' Define data directory paths ''' derivatives, rawdata, graphs, request.session['graphInvariants'], images = defDataDirs(userDefProjectDir) ''' Make appropriate dirs if they dont already exist ''' createDirStruct.createDirStruct([derivatives, rawdata, graphs, request.session['graphInvariants'], images]) print 'Directory structure created...' uploadFiles = writeBodyToDisk(request.body, derivatives) # Check which file is which roi_xml_fn, fiber_fn, roi_raw_fn = filesorter.checkFileExtGengraph(uploadFiles) # Check & sort files ''' Data Processing ''' if (re.match(re.compile('(b|big)', re.IGNORECASE), graphsize)): request.session['graphsize'] = 'big' request.session['smGrfn'], request.session['bgGrfn'], lccfn, SVDfn \ = processData(fiber_fn, roi_xml_fn, roi_raw_fn,graphs,\ request.session['graphInvariants'],\ request.session['graphsize'],True) elif(re.match(re.compile('(s|small)', re.IGNORECASE), graphsize)): request.session['graphsize'] = 'small' request.session['smGrfn'], request.session['bgGrfn'], lccfn, SVDfn \ = processData(fiber_fn, roi_xml_fn, roi_raw_fn,graphs, request.session['graphInvariants'], request.session['graphsize'],True) else: return django.http.HttpResponseBadRequest ("Missing graph size. Specify big or small") # Run invariants if len(request.session['invariants']) > 0: print "Computing invariants" if (request.session['graphsize'] == 'big'): graph_fn = request.session['bgGrfn'] lcc_fn = request.session['lccfn'] elif (request.session['graphsize'] == 'small'): graph_fn = request.session['smGrfn'] lcc_fn = None invariant_fns = runInvariants(request.session['invariants'],\ graph_fn, request.session['graphInvariants'],\ lcc_fn, request.session['graphsize']) #ret = rzfile.printdir() #ret = rzfile.testzip() #ret = rzfile.namelist() # request.session.clear() dwnldLoc = "http://mrbrain.cs.jhu.edu" + 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): # request.session.clear() return django.http.HttpResponseBadRequest ("Expected web arguments to direct project correctly") else: # request.session.clear() return django.http.HttpResponseBadRequest ("Expected POST data, but none given")