示例#1
0
    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()
示例#2
0
    def storeToFile(self):
        try:
            file = open(self.__fileName, 'w')
            rentalList = RentalRepository.getAllRentals(self)
            for rental in rentalList:
                stringToStore = str(rental.getRentalId()) + ";" + str(rental.getMovieId()) + ";" + \
                                str(rental.getClientId()) + ";"

                rentedDateString = str(rental.getRentedDate().year) + "/" + \
                                   str(rental.getRentedDate().month) + "/" + \
                                   str(rental.getRentedDate().day)

                dueDateString = str(rental.getDueDate().year) + "/" + \
                                   str(rental.getDueDate().month) + "/" + \
                                   str(rental.getDueDate().day) + ""

                if rental.isReturned():
                    returnedDateString = str(rental.getReturnDate().year) + "/" + \
                                       str(rental.getReturnDate().month) + "/" + \
                                       str(rental.getReturnDate().day)
                else:
                    returnedDateString = "None"

                stringToStore = stringToStore + rentedDateString + ";" + dueDateString + ";" +\
                                returnedDateString + "\n"

                file.write(stringToStore)
        except IOError:
            raise FileRepositoryException("Rental File Error")
        finally:
            file.close()
示例#3
0
 def __init__(self, fileName="rentals.txt"):
     RentalRepository.__init__(self)
     self.__fileName = fileName
     self.__loadFromFile()
示例#4
0
 def addStartingRentals(self, clientList):
     RentalRepository.addStartingRentals(self, clientList)
     self.storeToFile()
示例#5
0
 def getAllRentals(self):
     return RentalRepository.getAllRentals(self)
示例#6
0
    def lateRentals(self):

        return RentalRepository.lateRentals(self)
示例#7
0
 def uncomplete(self, rentalId):
     RentalRepository.uncomplete(self, rentalId)
     self.storeToFile()
示例#8
0
 def getBiggestRentalId(self):
     return RentalRepository.getBiggestRentalId(self)
示例#9
0
 def remove(self, rentalId):
     return RentalRepository.remove(self, rentalId)
     self.storeToFile()
示例#10
0
 def complete(self, rentalId, date):
     RentalRepository.complete(self, rentalId, date)
     self.storeToFile()
示例#11
0
 def size(self):
     return RentalRepository.size(self)
示例#12
0
 def findRentalById(self, rentalId):
     return RentalRepository.findRentalById(self, rentalId)
示例#13
0
 def exists(self, rentalId):
     return RentalRepository.exists(self, rentalId)
示例#14
0
 def addRentalAtIndex(self, rental, index):
     RentalRepository.addRentalAtIndex(self, rental, index)
     self.storeToFile()
示例#15
0
 def add(self, rental):
     RentalRepository.add(self, rental)
     self.storeToFile()