def __loadFromFile(self): try: f = open(self.__fName, "r") line = f.readline().strip() while line != "": attributes = line.split(";") book = Rental(attributes[0], attributes[1], attributes[2], attributes[3], attributes[4], attributes[5]) RepoRental.addElement(self, book, 0) line = f.readline().strip() except IOError: raise RepoFileError() finally: f.close()
def __addElementToFile(self): f = open(self.__fName, "w") elems = RepoRental.getAll(self) for elem in elems: book = str(elem.get_rental_id()) + ";" + elem.get_book_id( ) + ";" + elem.get_client_id() + ";" + elem.get_rented_date() + ";" book = book + str(elem.get_due_date()) + ";" + str( elem.get_returned_date()) + "\n" f.write(book) f.close()
def setUp(self): self.__bookId = 5 self.__title = "Fratii Karamazov" self.__author = "Dostoievski" self.__description = "pam pam" self.__clientId = 7 self.__name = "Ion Iliescu" self.__rentalId = 16 self.__rentedDate = 20 self.__dueDate = 13 self.__returnedDate = 30 self.__book = Book(self.__bookId, self.__title, self.__description, self.__author) self.__client = Client(self.__clientId, self.__name) self.__rental = Rental(self.__rentalId, self.__bookId, self.__clientId, self.__rentedDate, self.__dueDate, self.__returnedDate) self.__repoBook = RepoBook() self.__repoClient = RepoClient() self.__undoList = UndoRedo() self.__repoRental = RepoRental(self.__repoBook, self.__repoClient) self.__validBook = BookValidator() self.__validClient = ClientValidator() self.__validRental = RepoValidator(self.__repoBook, self.__repoClient) self.__bookService = ServiceBook(self.__repoBook, self.__validBook, self.__undoList) self.__clientService = ServiceClient(self.__repoClient, self.__validClient, self.__undoList) self.__rentalService = ServiceRental(self.__repoBook, self.__repoClient, self.__validRental, self.__repoRental, self.__undoList)
def __init__(self, booksRepo, clientsRepo, fileName): RepoRental.__init__(self, booksRepo, clientsRepo) self.__fName = fileName self.__loadFromFile()
def getRentals(self, index): return RepoRental.getRentals(self, index) self.__addElementToFile()
def mostRented(self, command1, command2): RepoRental.mostRented(self, command1, command2) self.__addElementToFile()
def addRental(self, element, param): RepoRental.addRental(self, element, param) self.__addElementToFile()
def giveElementId(self, index): return RepoRental.giveElementId(self, index) self.__addElementToFile()
def updateElement(self, element): RepoRental.updateElement(self, element) self.__addElementToFile()
def findRentalId(self, bookId, command): return RepoRental.findRentalId(self, bookId, command) self.__addElementToFile()
def removeElementInCascade(self, index): RepoRental.removeElementInCascade(self, index) self.__addElementToFile()
def removeElement(self, element, command): RepoRental.removeElement(self, element, command) self.__addElementToFile()
def removeElementUndo(self, element, param): RepoRental.removeElementUndo(self, element, param) self.__addElementToFile()
def searchElement1(self, element): return RepoRental.searchElement1(self, element) self.__addElementToFile()
def rentedAuthors(self): RepoRental.rentedAuthors(self) self.__addElementToFile()
def findElement(self, element): return RepoRental.findElement(self, element) self.__addElementToFile()
def getAll(self): return RepoRental.getAll(self) self.__addElementToFile()
def searchId(self, id): return RepoRental.searchId(self, id) self.__addElementToFile()
def printElement(self): RepoRental.printElement(self) self.__addElementToFile()
from repo.RepositoryPickleFiles import RepoBookBinaryFiles from repo.RepositoryClientsFiles import RepoClientTextFiles from repo.RepositoryClientsPickleFiles import RepoClientBinaryFiles from repo.RepositoryChooser import ChooseRepo from valid.Validation import BookValidator, ClientValidator, RepoValidator from business.Service import ServiceBook, ServiceClient, ServiceRental from tests.Tests import Tests from undo.UndoRedo import UndoOperation, UndoRedo repo = ChooseRepo("settings.properties") repoChoose = repo.ChooseRepoType() repoFiles = repo.fileNames() if repoChoose == "memory": bookRepo = RepoBook() clientRepo = RepoClient() rentalRepo = RepoRental(bookRepo, clientRepo) elif repoChoose == "textfiles": bookRepo = RepoBookTextFiles(repoFiles[0]) clientRepo = RepoClientTextFiles(repoFiles[1]) rentalRepo = RepoRentalTextFiles(bookRepo, clientRepo, repoFiles[2]) else: bookRepo = RepoBookBinaryFiles(repoFiles[0]) clientRepo = RepoClientBinaryFiles(repoFiles[1]) rentalRepo = RepoRentalPickleFiles(bookRepo, clientRepo, repoFiles[2]) #bookRepo = RepoBookBinaryFiles() #clientRepo = RepoClientBinaryFiles() #bookRepo = RepoBookTextFiles() #bookRepo = RepoBook() #clientRepo = RepoClient() #clientRepo = RepoClientTextFiles() #rentalRepo = RepoRental(bookRepo, clientRepo)
def returnElement(self, i): return RepoRental.returnElement(self, i) self.__addElementToFile()