def edit_writer_information(writerFolderPath: str, writerName: str, writerEmail:str, writerLanguageList: list): """ Changes the details of the writer located in the provided folder to match the specified details. Overwrites all existing details. If a parameter is None, will not edit that writer detail. Arguments: writerFolderPath: str - The path to the writer whose details need to be changed. writerName: str - The new name of the writer writerEmail: str - The new email of the writer writerLanguageList: list - The new list of language names (str) that the writer knows. """ writerObject = Writer.load_from_folder(writerFolderPath) if writerObject is None: raise PyCException('Error: Writer {} does not exist'.format(writerFolderPath)) if not writerName is None: writerObject.name = writerName if not writerEmail is None: writerObject.email = writerEmail if not writerLanguageList is None: writerObject.clear_known_languages() writerObject.add_known_language_from_list(writerLanguageList) writerObject.save_changes()
def delete_users(writerNames: list): """ Deletes each user whose name is given in the provided list of writer names. If any of the users do not exist, a joint error message is provided. Arguments: writerNames: list - The list of writer names to delete """ invalidWriters = [] for writer in writerNames: writerToDelete = Writer.load_from_folder(writer) if writerToDelete is None: invalidWriters.append(writer) continue writerToDelete.delete() if len(invalidWriters) > 0: raise PyCException('Error: {} are invalid writers'.format(str(invalidWriters)))
def _get_loaded_writers(writerNames: list = None) -> list: """ Loads the writers with the provided names and returns them in a list. Arguments: writerNames: list - The list of names to load writers for. If None, all writers are loaded. """ if writerNames is None or len(writerNames) == 0: return Writers.get_all_writers() loadedWriters = [] for writerName in writerNames: loadedWriter = Writer.load_from_folder(writerName) if loadedWriter is None: raise PyCException('Error: {} is an invalid writer'.format(writerName)) else: loadedWriters.append(loadedWriter) return loadedWriters
def operate(args): """ Takes the passed in args and delegates to proper functionality. This is set as the executable function when the `writers assign` subparser is used. Arguments: args: Namespace - The arguments passed via CLI """ # If the user specified a problem list, use that as the list of problems. problemParser = NumberParse() if not args.problems is None: specifiedProblems = problemParser.str_list_to_uniq_range(args.problems) else: specifiedProblems = problemParser.str_list_to_uniq_range(['1+']) specifiedLanguages = [] if not args.language is None: for languageName in args.language: loadedLanguage = Languages.get_language_by_name(languageName) if loadedLanguage is None: raise PyCException('Error: {} is an invalid language'.format(languageName)) specifiedLanguages.append(loadedLanguage) else: specifiedLanguages = [Languages.get_language_by_name(name) for name in Languages.get_all_language_names()] specifiedWriters = [] if not args.full and not args.writer_names is None and len(args.writer_names) > 0: for writerName in args.writer_names: loadedWriter = Writer.load_from_folder(writerName) if loadedWriter is None: raise PyCException('Error: {} is an invalid writer'.format(writerName)) specifiedWriters.append(loadedWriter) else: specifiedWriters = Writers.get_all_writers() allocator = AssignmentAllocator(specifiedProblems, specifiedLanguages, specifiedWriters, fromScratch=args.full) allocator.do_assignment(Definitions.get_value('complete_threshold'), overflow=args.overallocate)