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 convert_graph(request): if (request.method == 'POST'): form = ConvertForm(request.POST, request.FILES) # instantiating form if form.is_valid(): upload_fn = form.files['fileObj'].name save_dir, convert_file_save_loc = getworkdirs() saved_file = os.path.join(save_dir, upload_fn) saveFileToDisk(form.files['fileObj'], saved_file) # If zip is uploaded if os.path.splitext(upload_fn)[1].strip() == '.zip': unzip(saved_file, save_dir) # Delete zip so its not included in the graphs we uploaded os.remove(saved_file) uploaded_files = glob(os.path.join( save_dir, "*")) # get the uploaded file names else: uploaded_files = [saved_file] #Browser """ task_convert.delay(settings.MEDIA_ROOT, uploaded_files, convert_file_save_loc, form.cleaned_data['input_format'], form.cleaned_data['output_format'], form.cleaned_data["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 your job fails you will receive an email notification as well.<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 = ConvertForm() # An empty, unbound form # Render the form return render_to_response('convertupload.html', {'convertForm': form}, context_instance=RequestContext(request))
def convert_graph(request): if (request.method == 'POST'): form = ConvertForm(request.POST, request.FILES) # instantiating form if form.is_valid(): upload_fn = form.files['fileObj'].name save_dir, convert_file_save_loc = getworkdirs() saved_file = os.path.join(save_dir, upload_fn) saveFileToDisk(form.files['fileObj'], saved_file) # If zip is uploaded if os.path.splitext(upload_fn)[1].strip() == '.zip': unzip(saved_file, save_dir) # Delete zip so its not included in the graphs we uploaded os.remove(saved_file) uploaded_files = glob(os.path.join(save_dir, "*")) # get the uploaded file names else: uploaded_files = [saved_file] #Browser """ task_convert.delay(settings.MEDIA_ROOT, uploaded_files, convert_file_save_loc, form.cleaned_data['input_format'], form.cleaned_data['output_format'], form.cleaned_data["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 your job fails you will receive an email notification as well.<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 = ConvertForm() # An empty, unbound form # Render the form return render_to_response( 'convertupload.html', {'convertForm': form}, context_instance=RequestContext(request))