Exemplo n.º 1
0
    def _loadFile(self):

        try:
            file = open(self._fileName, "rb")
            result = pickle.load(file)
            for student in result:
                StudentRepo.add(self, student)
            file.close()
        except Exception:
            raise ValueError("Cannot open file!")
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
 def __init__(self, fileName="students.pickle"):
     StudentRepo.__init__(self)
     self._fileName = fileName
     self._loadFile()
Exemplo n.º 4
0
 def clear(self):
     StudentRepo.clear(self)
     self._saveFile()
Exemplo n.º 5
0
 def update(self, oldStudent, newStudent):
     StudentRepo.update(self, oldStudent, newStudent)
     self._saveFile()
Exemplo n.º 6
0
 def add(self, student):
     StudentRepo.add(self, student)
     self._saveFile()
Exemplo n.º 7
0
 def remove(self, studentID):
     StudentRepo.remove(self, studentID)
     self._saveFile()
Exemplo n.º 8
0
 def _saveFile(self):
     file = open(self._fileName, "wb")
     pickle.dump(StudentRepo.getAll(self), file)
     file.close()