def __load_disciplines(self): try: with open(self.__file_name) as f: for line in f: try: arr = line.split(",") p = Discipline(int(arr[0]), arr[1], arr[2]) self.add_item(p) except Exception as ex: raise RepositoryError("Corrupted file", ex) except Exception as ex: raise RepositoryError("Error opening file " + self.__file_name, ex)
def __load_students_disciplines(self): try: with open(self.__file_name) as f: for line in f: try: arr = line.split(",") if len(arr) == 4: p = Student_Discipline(int(arr[0]), int(arr[1]), int(arr[2]), int(arr[3]) ) self.add_item(p) except Exception as ex: raise RepositoryError("Corrupted file", ex) except Exception as ex: raise RepositoryError("Error opening file " + self.__file_name, ex)
def __save_student(self, Student): #TODO: handle exceptions try: with open(self.__file_name, "a") as f: s = str(Student.Id) + "," + Student.name + "\n" f.write(s) except Exception as ex: raise RepositoryError(ex)
def __save_discipline (self, Discipline): #TODO: handle exceptions try: with open(self.__file_name, "a") as f: s = str(Discipline.Id) + "," + Discipline.Discipline_name + "," + Discipline.Discipline_prof + "\n" f.write(s) except Exception as ex: raise RepositoryError(ex)
def __save_student_discipline (self, Student_Discipline): #TODO: handle exceptions try: with open(self.__file_name, "a") as f: s = "\n" + str(Student_Discipline.Id) + "," + str(Student_Discipline.student_id) + "," + str(Student_Discipline.discipline_id) + "," + str(Student_Discipline.grade) f.write(s) except Exception as ex: raise RepositoryError(ex)