def _loadFile(self): try: file = open(self._fileName, "rb") result = pickle.load(file) for student in result: DisciplineRepo.add(self, student) file.close() except Exception: raise ValueError("Cannot open file!")
def _loadFile(self): try: file = open(self._fileName, "r") entry = file.readline() while len(entry) > 2: entryList = entry.split(',') DisciplineRepo.add( self, Discipline(int(entryList[0]), entryList[1][:-1])) entry = file.readline() except FileNotFoundError as fnfe: raise ValueError("Cannot open file " + str(fnfe)) finally: file.close()
def readSettings(): settings = {} f = open("settings.properties", "r") s = f.read() lines = s.split("\n") for line in lines: tokens = line.split("=") settings[tokens[0].strip()] = tokens[1].strip() f.close() return settings settings = readSettings() if settings["repo_type"] == "memory": studentRepo = StudentRepo() disciplineRepo = DisciplineRepo() gradeRepo = GradeRepo() elif settings["repo_type"] == "text": studentRepo = StudentTextFileRepo(settings["student_repo_file"]) disciplineRepo = DisciplineTextFileRepo(settings["discipline_repo_file"]) gradeRepo = GradeTextFileRepo(settings["grade_repo_file"]) elif settings["repo_type"] == "binary": studentRepo = StudentBinaryFileRepo(settings["student_repo_file"]) disciplineRepo = DisciplineBinaryFileRepo(settings["discipline_repo_file"]) gradeRepo = GradeBinaryFileRepo(settings["grade_repo_file"]) studentValidator = StudentValidator(studentRepo) gradeValidator = GradeValidator(studentRepo, disciplineRepo) disciplineValidator = DisciplineValidator(disciplineRepo) undoController = UndoController() disciplineController = DisciplineController(disciplineRepo,
def __init__(self, fileName="disciplines.txt"): DisciplineRepo.__init__(self) self._fileName = fileName self._loadFile()
def clear(self): DisciplineRepo.clear(self) self._saveFile()
def update(self, oldDisciplineID, newDiscipline): DisciplineRepo.update(self, oldDisciplineID, newDiscipline) self._saveFile()
def remove(self, discipline): DisciplineRepo.remove(self, discipline) self._saveFile()
def add(self, discipline): DisciplineRepo.add(self, discipline) self._saveFile()
def add(self, student): DisciplineRepo.add(self, student) self._saveFile()
def _saveFile(self): file = open(self._fileName, "wb") pickle.dump(DisciplineRepo.getAll(self), file) file.close()