Esempio n. 1
0
    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!")
Esempio n. 2
0
 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()
Esempio n. 3
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()
disciplineController = DisciplineController(disciplineRepo,
Esempio n. 4
0
 def __init__(self, fileName="disciplines.txt"):
     DisciplineRepo.__init__(self)
     self._fileName = fileName
     self._loadFile()
Esempio n. 5
0
 def clear(self):
     DisciplineRepo.clear(self)
     self._saveFile()
Esempio n. 6
0
 def update(self, oldDisciplineID, newDiscipline):
     DisciplineRepo.update(self, oldDisciplineID, newDiscipline)
     self._saveFile()
Esempio n. 7
0
 def remove(self, discipline):
     DisciplineRepo.remove(self, discipline)
     self._saveFile()
Esempio n. 8
0
 def add(self, discipline):
     DisciplineRepo.add(self, discipline)
     self._saveFile()
Esempio n. 9
0
 def add(self, student):
     DisciplineRepo.add(self, student)
     self._saveFile()
Esempio n. 10
0
 def _saveFile(self):
     file = open(self._fileName, "wb")
     pickle.dump(DisciplineRepo.getAll(self), file)
     file.close()