def add_one_user(self): self.deactivate_buttons() temp_id = int(self.id_entry.get()) e_mail = self.em_entry.get() first_name = self.fn_entry.get() last_name = self.ln_entry.get() # Checks that all the fields are filled in. if temp_id != "" and e_mail != "" and first_name != "" and last_name != "": # Checks that user has not been previously added if cT.user_by_id(temp_id) is None: curr_user = cT.create_single_user(temp_id, first_name, last_name, e_mail)[0] curr_vm = cT.get_vm_object(curr_user.assigned_VM) curr_vm.is_instance_ready() curr_vm.stop_instance() else: messagebox.showinfo("User Error", "This user already exist", parent=self) else: messagebox.showinfo( "Missing Requirements", "ID, eMail, First Name, and Last Name fields must be filled.", parent=self) self.clear_single_user_fields() self.activate_buttons()
def create_multi_user(self): cs_file = self.csv_entry.get() self.deactivate_buttons() if cs_file != "": user_csv_list = [] with open(cs_file, 'r', newline='') as CSV_FILE: reader = csv.reader(CSV_FILE) next(reader) for user_list in reader: user_csv_list.append(user_list) # Sets up the progress bar self.csv_progress['maximum'] = len(user_csv_list) * 2 bar = 0 # Creates user and assigns vm for new_user in user_csv_list: if new_user: if cT.user_by_id(int(new_user[0])) is None: success = cT.create_single_user( new_user[0].strip(), new_user[1].strip(), new_user[2].strip(), new_user[3].strip()) if not success[1]: messagebox.showinfo( "Warning", "Unable to notify user {0} of their account's password." .format(new_user[0]), parent=self) bar += 1 self.csv_progress["value"] = bar self.csv_progress.update() # waits for all machines to finish loading and shuts them down for curr_user in cT.get_list_users(): if curr_user.isTeacher is False: curr_vm = cT.get_vm_object(curr_user.assigned_VM) curr_vm.is_instance_ready() curr_vm.stop_instance() bar += 1 self.csv_progress["value"] = bar self.csv_progress.update() messagebox.showinfo("Done", "Process completed.", parent=self) self.csv_progress["value"] = 0 self.csv_progress.update() else: messagebox.showinfo( "Missing Info", "You need to first load a .csv file and provide a valid AMI.", parent=self) self.clear_multi_user_fields() self.activate_buttons()
def setUp(self) -> None: self.user = 5879456 self.name = "Test" self.last_name = "Subject" self.eMail = "*****@*****.**" cT.create_single_user(self.user, self.name, self.last_name, self.eMail)