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))
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))
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))
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))
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))