def start(): while True: ui.print_menu(options, 'Back to Main Menu') user_input=ui.user_inputs(['number']) if user_input=='1': show_all(table) elif user_input=='2': data_manager.write_to_table('students_tester.csv',create_student(table,students_fields)) elif user_input=='3': ui.print_result(read_student(table)) elif user_input=='4': read_students(table) elif user_input=='5': update_student(table) elif user_input=='6': data_manager.write_to_table("students_tester.csv",activate_deactivate(table)) elif user_input=='7': data_manager.write_to_table("students_tester.csv",delete_student(table)) elif user_input=='0': break else: ui.print_error('Wrong Number')
def validate_string_input(string, condition=""): """ Validate if string from input is not empty and is in given condition. Condition must be in format: ["a", "b", "c".....] >>> validate_string_input("", ["s"]) ERROR: Input can't be empty False >>> validate_string_input("s", ["c"]) ERROR: Input must be in ['c'] False >>> validate_string_input("Not_empty", "") True >>> validate_string_input("content", ["content"]) True """ is_string_correct = True if not string: ui.print_error("Input can't be empty") is_string_correct = False if condition: if string: if string not in condition: ui.print_error("Input must be in {}".format(condition)) is_string_correct = False os.system('clear') return is_string_correct
def delete_student(tablet): ''' Users can delete existing students by entering their ID. Students cannot be deleted if they have an existing Application ''' searched_id=ui.user_inputs(["ID"]) application_table=data_manager.read_data("application.csv") student_index=2 can_be_deleted=True for row in application_table: if row[student_index]==searched_id: can_be_deleted=False break if can_be_deleted==True: student_id=0 to_delete_index=None for row in range(len(table)): if table[row][student_id]==searched_id: to_delete_index=row table.pop(to_delete_index) else: ui.print_error("Can't delete that person!") return table
def update_student(table): ''' Users can update the details of existing students by first entering their ID and then the information (name, age) to be updated. IDs cannot be updated. ''' student_id=0 searched_id=ui.user_inputs(["ID"]) to_update_index=None for row in range(len(table)): if table[row][student_id]==searched_id: to_update_index=row break if to_update_index!=None: to_update_data_list=ui.user_inputs(students_fields) to_update_data_list.insert(0,table[to_update_index][student_id]) table.pop(to_update_index) table.insert(to_update_index,to_update_data_list) data_manager.write_to_table("students_tester.csv",table) else: ui.print_error("Not found that ID!")
def ask_pm( self, usable_pms: dict[str, PackageManager]) -> Optional[PackageManager]: """ Ask to the user witch PM use for the installation :return: the PM to use, or None if cancel """ possibles_pm = list(set(self.pms.keys()) & set(usable_pms.values())) choice = 0 while not 1 <= choice <= len(possibles_pm): ui.print_information("Possible package managers:") for index in range(len(possibles_pm)): ui.print_description( str(index + 1) + ": " + possibles_pm[index].system_name) choice = ui.ask( "Enter the number of the package manager you want to use (-1 to cancel the installation): " ) if choice == "-1": ui.print_error("Installation canceled") return None elif not (choice.isnumeric() and 1 <= int(choice) <= len(possibles_pm)): ui.print_error( "Error: please enter a number between %d and %d" % (1, len(possibles_pm))) choice = 0 else: choice = int(choice) return possibles_pm[choice - 1]
def choose(): myfile = "position/positions.txt" option = ui.get_inputs("\nPlease enter a number: ") table = data_manager.imports_from_file(myfile) if option == "1": ui.clear() data_manager.export_to_file(myfile, create_position(table)) elif option == "2": ui.clear() idx = ui.get_inputs("Enter the position ID: ") if common.check_valid_id(table, idx) == False: ui.clear() ui.print_error(f"Invalid position ID! ('{idx}')") else: ui.print_result( get_applied_students(read_position(table, idx), idx), "Position details") elif option == "3": ui.clear() result = common.read_elements(table) if len(result) == 0: ui.clear() ui.print_error("There are no positions in this list!") else: show_table(format_seats(result)) elif option == "4": ui.clear() idx = ui.get_inputs("Enter position ID: ") if common.check_valid_id(table, idx) == False: ui.clear() ui.print_error(f"Invalid position ID! ('{idx}')") else: data_manager.export_to_file( myfile, update_position( table, idx, "description", ui.get_inputs( "Enter the new value of the description.\n"))) elif option == "5": ui.clear() idx = ui.get_inputs("Enter position ID: ") if common.check_valid_id(table, idx) == False: ui.clear() ui.print_error(f"Invalid position ID! ('{idx}')") return True if common.check_data_in_app(idx, "position") == True: ui.clear() ui.print_error("You cannot delete this position!") else: data_manager.export_to_file(myfile, common.delete_element(table, idx)) elif option == "0": ui.clear() return False else: raise KeyError(f"There is no such option. ({option})") return True
def install_kde_theme(theme_name: str, theme_folder_path: str) -> None: """ Check that every needed software is here, then start to install the KDE theme """ # Checking that every command is available commands_to_check = ["kpackagetool5", "lookandfeeltool", "wget", "tar"] for command in commands_to_check: check_command = "type " + command + " > /dev/null 2>&1" # The execution will return 0 if present, else an other number. So it's not bool(command) command_available = not bool(ui.exec_system(check_command)) if not command_available: ui.print_error("Error: " + command + " is needed but not find. Theme install canceled.") return # looking if the theme is already installed, and deleting it if yes check_install_result = subprocess.run(['lookandfeeltool', '-l'], stdout=subprocess.PIPE) already_installed = theme_name in check_install_result.stdout.decode("utf-8") if already_installed: ui.print_information(theme_name + " already installed. Deleting...") delete_command = "kpackagetool5 -r " + theme_folder_path delete_failed = bool(ui.exec_system(delete_command)) if delete_failed: ui.print_error("Error: impossible to delete the theme.") return # INSTALLATION OF THE DEPENDENCIES ui.print_information("Installation of the dependencies...") dependencies_installation_failed = bool(ui.exec_system("sh %s/install_theme_components.sh" % CURRENT_DIR_PATH)) if dependencies_installation_failed: ui.print_error("Error: impossible to install all the needed dependencies.") return print() ui.print_information("Installation of %s (the global theme)..." % theme_name) installation_command = "kpackagetool5 -i " + theme_folder_path installation_failed = bool(ui.exec_system(installation_command)) if installation_failed: ui.print_error("Error: impossible to install the global theme.") return ui.print_information("Global theme successfully installed.") ui.print_information("Setting the theme... (some QDBusConnection errors can span but they aren't serious)") setting_the_theme_command = "lookandfeeltool --apply " + theme_name setting_failed = bool(ui.exec_system(setting_the_theme_command)) if setting_failed: ui.print_error("Error: impossible to set the global theme.") else: ui.print_information("Global theme successfully set.") ui.print_information( "Note that with KDE a bug can occur when changing window style:" + "if you have a white strip on some window (like the setting app)," + "change the color decoration to a light-one that then re-change it to Sweet-Dark." )
def main(): ui.clear() while True: handle_menu() try: choose() except KeyError as err: ui.clear() ui.print_error(str(err))
def start_module(): ui.clear() while True: Show_menu() try: if not choose(): break else: ui.get_inputs('\nPress ENTER to continue') ui.clear() except KeyError as err: ui.clear() ui.print_error(str(err))
def choose(): user_input = ui.user_inputs(['number']) if user_input == '1': student.start() elif user_input == '2': company.start() elif user_input == '3': position.start() elif user_input == '4': application.start() elif user_input == '0': sys.exit(0) else: ui.print_error('Wrong Number')
def start(): while True: ui.print_menu(options, 'Back to Main Menu') user_input = ui.user_inputs(['number']) if user_input == '1': create_application(application_fields, table) elif user_input == '2': data_manager.write_to_table("application.csv", update_application(table)) elif user_input == '3': data_manager.write_to_table("application.csv", delete_application(table)) elif user_input == '0': break else: ui.print_error('Wrong Number')
def read_student(table): ''' Users can show the details of existing students by entering their ID. All “Application” of student shows up here. ''' user_id=0 user_name=1 result="" searched_id=ui.user_inputs(["ID"]) valid_id=False for row in table: if row[user_id]==searched_id: valid_id=True result+=row[user_name]+": " if valid_id==True: searching_table=data_manager.read_data("application.csv") position_list=[] student_id=2 position_id=3 for row in searching_table: if row[student_id]==searched_id: position_list.append(row[position_id]) position_id=0 position_name=1 searching_table=data_manager.read_data("position.csv") position_name_list=[] for element in position_list: for row in searching_table: if row[position_id]==element: position_name_list.append(row[position_name]) for element in range(len(position_name_list)): if element!=len(position_name_list)-1: result+=position_name_list[element]+", " else: result+=position_name_list[element] else: ui.print_error("Not found that ID!") return result
def delete_application(table): ''' Users can delete existing applications by entering their IDs. ''' id_index = 0 searched_id = ui.user_inputs(["ID"]) to_delete_row_index = None for row in range(len(table)): if table[row][id_index] == searched_id: to_delete_row_index = row break if to_delete_row_index != None: table.pop(to_delete_row_index) else: ui.print_error("Not found thath ID!") return table
def start(): while True: ui.print_menu(options, 'Back to Main Menu') user_input = ui.user_inputs(['number']) if user_input == '1': result_table = create_company(table, company_fields) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('New record saved') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '2': result = read_company(table) if result: ui.print_dictionary(result) else: ui.print_error("There's no company with that ID") elif user_input == '3': ui.print_table(table, company_fields) elif user_input == '4': result_table = update_company(table, company_fields) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('Record update') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '5': result_table = delete_company(table) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('Record deleted') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '0': break else: ui.print_error('Wrong Number')
def update_application(table): ''' Users can update existing applications by entering their ID. Only the “accepted” status can be changed. ''' found_it = False id_index = 0 accepted_index = 1 searched_id = ui.user_inputs(["ID"]) for row in range(len(table)): if table[row][id_index] == searched_id: found_it = True if table[row][accepted_index] == "yes": table[row][accepted_index] = "no" else: table[row][accepted_index] = "yes" if not found_it: ui.print_error("Not found that ID!") return table
def activate_deactivate(table): ''' Users can activate/deactivate students by entering their ID ''' searched_id=ui.user_inputs(["ID"]) valid_id=False student_id=0 student_activity=3 for row in table: if row[student_id]==searched_id: valid_id=True if row[student_activity]=="yes": row[student_activity]="no" else: row[student_activity]="yes" if not valid_id: ui.print_error("Not found that ID!") return table
def start(): while True: ui.print_menu(options, 'Back to Main Menu') user_input = ui.user_inputs(['number']) if user_input == '1': result_table = create_position( data_manager.read_data('position.csv'), position_fields) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('New record saved') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '2': ui.print_dictionary(read_position(table, position_fields)) elif user_input == '3': table_and_fields = read_positions(table, position_fields) ui.print_table(table_and_fields[0], table_and_fields[1]) elif user_input == '4': result_table = update_position(table) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('Record updated') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '5': result_table = delete_position(table) if result_table: data_manager.write_to_table(file_name, result_table) ui.print_progress('Record deleted') else: ui.print_error('Invalid data \n Record not saved.') elif user_input == '0': break else: ui.print_error('Wrong Number')
def create_application(fields, table): ''' Users can create new applications. An application has an ID, an “accepted” field, a “Student ID” and a “Position ID”. IDs are unique amongst other applications. Student and Position IDs must exist. The “accepted” field stores whether the application was accepted by a company or not. ''' to_add = ui.user_inputs(fields) accepted_index = 0 if to_add[accepted_index] == "yes" or to_add[accepted_index] == "no": student_id_index = 1 position_id_index = 2 student_is_ok = False position_is_ok = False compare_table = data_manager.read_data("students.csv") student_id_index_from_student_table = 0 for row in range(len(compare_table)): if compare_table[row][ student_id_index_from_student_table] == to_add[ student_id_index]: student_is_ok = True compare_table = data_manager.read_data("position.csv") position_id_index_in_position_table = 0 position_places_index = 2 max_places = None for row in range(len(compare_table)): if compare_table[row][ position_id_index_in_position_table] == to_add[ position_id_index]: max_places = int(compare_table[row][position_places_index]) position_is_ok = True break count = 0 if position_is_ok == True: application_table_position_id = 3 application_acceptance = 1 for row in table: if row[application_table_position_id]==to_add[position_id_index] \ and row[application_acceptance]=="yes": count += 1 if count >= max_places: position_is_ok = False table_student_id_index = 2 table_position_id = 3 for row in table: if row[table_student_id_index]==to_add[table_student_id_index-1] \ and row[table_position_id]==to_add[table_position_id-1]: position_is_ok = False if position_is_ok == True and student_is_ok == True: to_add.insert(0, common.create_id(table)) table.append(to_add) data_manager.write_to_table("application.csv", table) else: ui.print_error("Can't add that row.") else: ui.print_error("Wrong input(yes or no)")
def choose(): myfile = "application/applications.txt" option = ui.get_inputs("\nPlease enter a number: ") table = data_manager.imports_from_file(myfile) if option == "1": ui.clear() pos_name = ui.get_inputs("Enter a position name to apply: ") positions = data_manager.imports_from_file("position/positions.txt") student_id = ui.get_inputs("Enter a student id to apply: ") students = data_manager.imports_from_file("student/students.txt") opt = ui.get_inputs("Enter the status(applied/not applied): ") if common.check_valid_id(positions, pos_name) == False or common.check_valid_id( students, student_id) == False: ui.clear() ui.print_error("Non existing position or student!") else: if opt != "applied" and opt != "not applied": ui.clear() ui.print_error("Thats not an option") else: data_manager.export_to_file( myfile, create_applicaion(table, opt, pos_name, student_id, positions)) elif option == "2": ##Update Applications ui.clear() idx = ui.get_inputs("Enter application ID: ") if common.check_valid_id(table, idx) == False: ui.clear() ui.print_error(f"Invalid application ID! ('{idx}')") return True else: if common.check_if_applied(table, idx) == True: ui.clear() ui.print_error("You cant modify not applied status") else: for row in table: if row[0] == idx: row[1] = "not applied" data_manager.export_to_file(myfile, table) elif option == "3": ui.clear() idx = ui.get_inputs("Enter application ID: ") if common.check_valid_id(table, idx) == False: ui.clear() ui.print_error(f"Invalid application ID! ('{idx}')") else: data_manager.export_to_file(myfile, common.delete_element(table, idx)) elif option == "4": ui.clear() result = common.read_elements(table) if len(result) == 0: ui.clear() ui.print_error("There are no application in this list!") else: show_table(result) elif option == "0": ui.clear() return False else: raise KeyError(f"There is no such option. ({option})") return True
def choose(): myfile = "student/students.txt" option = ui.get_inputs("\nPlease enter a number: ") table = data_manager.imports_from_file(myfile) if option == "1": ui.clear() data_manager.export_to_file(myfile, create_student(table)) elif option == "2": ui.clear() idx = ui.get_inputs("Enter the student ID: ") if common.check_valid_id(table, idx) == False: ui.clear() ui.print_error(f"Invalid student ID! ('{idx}')") else: result = get_student_applications(idx, read_student(table, idx)) ui.print_result(result, "Student details") elif option == "3": ui.clear() result = read_students(table) if len(result) == 0: ui.clear() ui.print_error("There are no students in this list!") else: show_table(result) elif option == "4": ui.clear() attributes = ["name", "age", "status"] idx = ui.get_inputs("Enter student ID: ") if common.check_valid_id(table, idx) == False: ui.clear() ui.print_error(f"Invalid student ID! ('{idx}')") return True update = ui.get_inputs("Which attribute do you want to change?\n") update = update.lower() if update not in attributes: ui.clear() ui.print_error(f"You cannot change this attribute! ('{update}')") else: data_manager.export_to_file( myfile, update_student( table, idx, update, ui.get_inputs(f"Enter the new value of the {update}.\n"))) elif option == "5": ui.clear() idx = ui.get_inputs("Enter student ID: ") if common.check_valid_id(table, idx) == False: ui.clear() ui.print_error(f"Invalid student ID! ('{idx}')") else: data_manager.export_to_file( myfile, update_student(table, idx, "status", get_new_status(table, idx))) elif option == "6": ui.clear() idx = ui.get_inputs("Enter student ID: ") if common.check_valid_id(table, idx) == False: ui.clear() ui.print_error(f"Invalid student ID! ('{idx}')") return True if common.check_data_in_app(idx, "student") == True: ui.clear() ui.print_error("You cannot delete this student!") else: data_manager.export_to_file(myfile, common.delete_element(table, idx)) elif option == "0": ui.clear() return False else: raise KeyError(f"There is no such option. ({option})") return True