def __loadFromFile(self): try: file = open(self.__fileName, 'r') line = file.readline().strip() while line != "": attributes = line.split(";") rentedDateString = attributes[3].split("/") rentedDate = date(int(rentedDateString[0]), int(rentedDateString[1]), int(rentedDateString[2])) dueDateString = attributes[4].split("/") dueDate = date(int(dueDateString[0]), int(dueDateString[1]), int(dueDateString[2])) returnedDateString = attributes[5].split("/") if returnedDateString[0] != "None": returnedDate = date(int(returnedDateString[0]), int(returnedDateString[1]), int(returnedDateString[2])) else: returnedDate = None rental = Rental(int(attributes[0]), int(attributes[1]), int(attributes[2]), rentedDate, dueDate, returnedDate) RentalRepository.add(self, rental) line = file.readline().strip() except IOError: raise FileRepositoryException("Rental File Error") finally: file.close()
def add(self, rental): RentalRepository.add(self, rental) self.storeToFile()