def user_requestSimResults(self, ARG=False): """ Checks if the specified simulation is done running and if its results file has been uploaded to the client's storage container. If the simulation has finished, the results are downloaded to the clients computer. :param ARG: :return: """ if ARG: print "Checking for " + self.curr_sim.name + " results..." # Check if project is listed in client's simulation file not_listed = self.check_sim(self.curr_sim.name) ######## Get Results if Ready ######## if not_listed: stderr.write("\nProject does not exist.") exit(1) else: # Retrieve names of all user's files in their container try: blobs = blob_service.list_blobs(container_name=self.username.lower()) except: stderr.write('An error occurred while accessing your storage.') exit(1) sim_results = 'r-' + self.curr_sim.vm_id results_in = False # Check if results are in for uploaded_file in blobs: if uploaded_file.name == sim_results: # Download results file file_path = 'c:/Users/' + comp_user + '/Simulations/' + self.username + '/' + self.curr_sim.name + \ '_results.zip' try: blob_service.get_blob_to_path(self.username.lower(), sim_results, file_path) except: stderr.write('An error occurred while downloading your results.') exit(1) AzureSimulation.extract_files(self.curr_sim.name + '_results') results_in = True break if results_in: print "\nYour results are in! Check C:/Users/" + comp_user + "/Simulations/" + self.username + " for " \ "the " + self.curr_sim.name + "_results folder." else: # If the results are not in and the VM is still running... try: sms.get_role(self.username, self.username, self.curr_sim.vm_id) # The simulation is still running print "\nThe simulation is still running. Check back later to retrieve results." # If the results are not in but the VM is already deleted... except: # The results did not upload print "Your results were unable to be uploaded. Try running the simulation again." elif not ARG: ######## Get Simulation Name ######### requested_sim = "1" while requested_sim == '1': requested_sim = raw_input("\nSelect a project to check for results.\n" "Press '1' to list projects or enter project name: ") if requested_sim == '1': self.list_projects() ######## Get Results if Ready ######## while self.check_sim(requested_sim) == True: print "\nProject does not exist." option = None while option not in ['1', '2', '3']: option = raw_input("(1) Check another project\n" "(2) Back to menu\n" "(3) Quit\n" ">> ") if option not in ['1', '2', '3']: stderr.write("\nInput not recognized.\n") sleep(0.5) if option == 1: requested_sim = "1" while requested_sim == '1': requested_sim = raw_input("\nSelect a project to check for results.\n" "Press '1' to list projects or enter project name: ") if requested_sim == '1': self.list_projects() elif option == '2': return elif option == '3': quit(0) # Retrieve all user's files from their container try: blobs = blob_service.list_blobs(container_name=self.username.lower()) except: stderr.write('An error occurred while trying to access your storage.') exit(1) sim_results = 'r-' + self.curr_sim.vm_id results_in = False # Check if results are in for uploaded_file in blobs: if uploaded_file.name == sim_results: # Download results file file_path = 'c:/Users/' + comp_user + '/Simulations/' + self.username + '/' + requested_sim + \ '_results.zip' try: blob_service.get_blob_to_path(self.username.lower(), sim_results, file_path) except: stderr.write('An error occurred when trying to download your results.') exit(1) # Extract results AzureTools.extract_files(requested_sim + '_results', self.username) results_in = True break if results_in: print "\nYour results are in! Check C:/Users/" + comp_user + "/Simulations/" + self.username + " for " \ "the " + requested_sim + "_results folder." return else: # If the results are not in and the VM is still running... try: sms.get_role(self.username, self.username, self.curr_sim.vm_id) # The simulation is still running print "\nThe simulation is still running. Check back later to retrieve results." # If the results are not in but the VM is already deleted... except: # The results did not upload print "Your results were unable to be uploaded. Try running the simulation again." return
def user_requestSimResults(self, ARG=False): """ Checks if the specified simulation is done running and if its results file has been uploaded to the client's storage container. If the simulation has finished, the results are downloaded to the clients computer. :param ARG: :return: """ if ARG: print "Checking for " + self.curr_sim.name + " results..." # Check if project is listed in client's simulation file not_listed = self.check_sim(self.curr_sim.name) ######## Get Results if Ready ######## if not_listed: stderr.write("\nProject does not exist.") exit(1) else: # Retrieve names of all user's files in their container try: blobs = blob_service.list_blobs( container_name=self.username.lower()) except: stderr.write( 'An error occurred while accessing your storage.') exit(1) sim_results = 'r-' + self.curr_sim.vm_id results_in = False # Check if results are in for uploaded_file in blobs: if uploaded_file.name == sim_results: # Download results file file_path = 'c:/Users/' + comp_user + '/Simulations/' + self.username + '/' + self.curr_sim.name + \ '_results.zip' try: blob_service.get_blob_to_path( self.username.lower(), sim_results, file_path) except: stderr.write( 'An error occurred while downloading your results.' ) exit(1) AzureSimulation.extract_files(self.curr_sim.name + '_results') results_in = True break if results_in: print "\nYour results are in! Check C:/Users/" + comp_user + "/Simulations/" + self.username + " for " \ "the " + self.curr_sim.name + "_results folder." else: # If the results are not in and the VM is still running... try: sms.get_role(self.username, self.username, self.curr_sim.vm_id) # The simulation is still running print "\nThe simulation is still running. Check back later to retrieve results." # If the results are not in but the VM is already deleted... except: # The results did not upload print "Your results were unable to be uploaded. Try running the simulation again." elif not ARG: ######## Get Simulation Name ######### requested_sim = "1" while requested_sim == '1': requested_sim = raw_input( "\nSelect a project to check for results.\n" "Press '1' to list projects or enter project name: ") if requested_sim == '1': self.list_projects() ######## Get Results if Ready ######## while self.check_sim(requested_sim) == True: print "\nProject does not exist." option = None while option not in ['1', '2', '3']: option = raw_input("(1) Check another project\n" "(2) Back to menu\n" "(3) Quit\n" ">> ") if option not in ['1', '2', '3']: stderr.write("\nInput not recognized.\n") sleep(0.5) if option == 1: requested_sim = "1" while requested_sim == '1': requested_sim = raw_input( "\nSelect a project to check for results.\n" "Press '1' to list projects or enter project name: " ) if requested_sim == '1': self.list_projects() elif option == '2': return elif option == '3': quit(0) # Retrieve all user's files from their container try: blobs = blob_service.list_blobs( container_name=self.username.lower()) except: stderr.write( 'An error occurred while trying to access your storage.') exit(1) sim_results = 'r-' + self.curr_sim.vm_id results_in = False # Check if results are in for uploaded_file in blobs: if uploaded_file.name == sim_results: # Download results file file_path = 'c:/Users/' + comp_user + '/Simulations/' + self.username + '/' + requested_sim + \ '_results.zip' try: blob_service.get_blob_to_path(self.username.lower(), sim_results, file_path) except: stderr.write( 'An error occurred when trying to download your results.' ) exit(1) # Extract results AzureTools.extract_files(requested_sim + '_results', self.username) results_in = True break if results_in: print "\nYour results are in! Check C:/Users/" + comp_user + "/Simulations/" + self.username + " for " \ "the " + requested_sim + "_results folder." return else: # If the results are not in and the VM is still running... try: sms.get_role(self.username, self.username, self.curr_sim.vm_id) # The simulation is still running print "\nThe simulation is still running. Check back later to retrieve results." # If the results are not in but the VM is already deleted... except: # The results did not upload print "Your results were unable to be uploaded. Try running the simulation again." return