def updateABook(commandInPieces): # updates a book from the repository # input - details about the book that must be updated(id) and the values that must be edited repoCaller = Repo() listOfBooks = repoCaller.getListOfBooks() idToUpdate = commandInPieces[1] newBookId = commandInPieces[2] newTitle = commandInPieces[3] newAuthor = commandInPieces[4] updatedBook = Book(newBookId, newTitle, newAuthor) position = 0 try: validateABook(updatedBook) for iterator in listOfBooks: if Book.getBookId(iterator) == idToUpdate: if commandInPieces[0] != "undo": undoFunction = Undo("updateB", [ "undo", newBookId, Book.getBookId(iterator), Book.getBookName(iterator), Book.getBookAuthor(iterator), "undo", idToUpdate, newBookId, newTitle, newAuthor ]) repoCaller.addToListOfOperations(undoFunction) repoCaller.setRedoFalse() repoCaller.removeBookFromPosition(position) repoCaller.insertBookIntoPosition(position, updatedBook) repoCaller.loadIntoFiles() repoCaller.loadIntoPickle() break position += 1 except BookAlreadyExistsError: print(BookAlreadyExistsError()) return False