def _readFromLine(self):
     with open(self._fileName, "r") as f:
         lines = f.readlines()
         for line in lines:
             if line != '\n':
                 obj = self._objectType.readFromLine(line)
                 copyobj = deepcopy(obj)
                 copyobj.grade[0] = 0
                 GradeRepository.enroll(self, copyobj)
                 GradeRepository.store(self, obj)
示例#2
0
 def __init__(self, fileName, objectType):
     GradeRepository.__init__(
         self)  # initialising the repository with its list
     self._fileName = fileName  # the filename of the table that will be created
     self._objectType = objectType  # The object type e.g : Student, Discipline etc..
     self._conn = sqlite3.connect(
         "DATABASE.db")  # Creating the connection to the database
     self._c = self._conn.cursor(
     )  # Getting the cursor for the database ( like a real cursor )
     self._createTable()  # Creating the table if not created
     self._readFromDB(
     )  # Reading from the table ( if there's any input data to be read )
示例#3
0
 def _readFromDB(self):
     '''
     Reading from a database
     * - selects everything from the database, like a cursor selects something on the screen;
         to use the data we use fetchall, which returns a list of tuples;
         we use join to make every tuple from the list a string;
         the rest is the same as reading from file;
     '''
     self._c.execute('SELECT * FROM ' + self._fileName)
     lines = self._c.fetchall()
     for line in lines:
         if line != '\n':
             line = ','.join(line)
             obj = self._objectType.readFromLine(line)
             copyobj = deepcopy(obj)
             copyobj.grade[0] = 0
             GradeRepository.enroll(self, copyobj)
             GradeRepository.store(self, obj)
示例#4
0
 def obtainPersistencySource():
     with open("./local.settings", "r") as f:
         lines = f.readlines()
         repo_type = lines[0].strip().split('=')[1]
     if repo_type == "inmemory":
         return Repository(), Repository(), GradeRepository()
     if repo_type == "file":
         students_repo_file = lines[1].strip().split('=')[1]
         discipline_repo_file = lines[2].strip().split('=')[1]
         grade_repo_file = lines[3].strip().split('=')[1]
         return FileRepository(students_repo_file, Student), FileRepository(discipline_repo_file, Discipline), FileGradeRepository(grade_repo_file, Grade)
     if repo_type == "binary":
         students_repo_file = lines[1].strip().split('=')[1]
         discipline_repo_file = lines[2].strip().split('=')[1]
         grade_repo_file = lines[3].strip().split('=')[1]
         return PickleRepository(students_repo_file), PickleRepository(discipline_repo_file), PickleGradeRepository(grade_repo_file)
     if repo_type == "sql":
         students_repo_file = lines[1].strip().split('=')[1]
         discipline_repo_file = lines[2].strip().split('=')[1]
         grade_repo_file = lines[3].strip().split('=')[1]
         return SQL_Repo(students_repo_file, Student), SQL_Repo(discipline_repo_file, Discipline), SQL_GradeRepo(grade_repo_file, Grade)
示例#5
0
 def removeDiscipline(self, ident):
     GradeRepository.removeDiscipline(self, ident)
     self._writeToDB()
示例#6
0
 def removeStudent(self, ident):
     GradeRepository.removeStudent(self, ident)
     self._writeToDB()
示例#7
0
 def store(self, elem):
     GradeRepository.store(self, elem)
     self._writeToDB()
示例#8
0
 def store(self, elem):
     GradeRepository.store(self, elem)
     self.__writeToFile()
示例#9
0
 def __init__(self, filename):
     GradeRepository.__init__(self)
     self.__filename = filename
     self.__readFromFile()
示例#10
0
 def __init__(self, fileName="newFile.txt", objectType="None"):
     GradeRepository.__init__(self)
     self._fileName = fileName
     self._objectType = objectType
     self._readFromLine()
示例#11
0
def undoTest():
    '''
    '''
    undoController = UndoController()
    studentRepo = Repository()
    disciplineRepo = Repository()
    
    
    '''
    Start grade Controller
    '''
    gradeRepo = GradeRepository()
    gradeValidator = GradeValidator()
    gradeController = GradeControllerWithUndo(undoController, gradeRepo, gradeValidator, studentRepo, disciplineRepo)
    
    '''
    Start student Controller
    '''
    studentValidator = StudentValidator()
    studentController = StudentControllerWithUndo(undoController, studentRepo, studentValidator, gradeController)
    
    '''
    Start discipline Controller
    '''
    disciplineValidator = DisciplineValidator()
    disciplineController = DisciplineControllerWithUndo(undoController, disciplineRepo, disciplineValidator, gradeController)
    #######################################################
    
    
    undoController.newOperation()
    studentA = studentController.addStudent("cc11", "Ion")

    undoController.newOperation()
    studentB = studentController.addStudent("ab133", "Ana")
    
    undoController.newOperation()
    studentC = studentController.addStudent("1", "George")
    
    undoController.newOperation()
    studentD = studentController.addStudent("2", "Mihai")
    
    
    '''
    print("Len of Student Controller: ", len(studentController))
    print(msg)
    print(studentController)
    undoController.undo()
    undoController.undo()
    undoController.undo()
    undoController.undo()
    print(msg)
    
    print("Len of Student Controller: ", len(studentController))
    print(msg)   
    
    undoController.redo()
    undoController.redo()
    undoController.redo()
    undoController.redo()
     
    print("Len of Student Controller: ", len(studentController))
    print(msg)   
    print(studentController)
    '''
    
    undoController.newOperation()
    disciplineA = disciplineController.addDiscipline("1", "Math")
    
    undoController.newOperation()
    disciplineB = disciplineController.addDiscipline("2", "Physics")
    
    undoController.newOperation()
    disciplineC = disciplineController.addDiscipline("3", "Grammar")
    
    undoController.newOperation()
    disciplineD = disciplineController.addDiscipline("4", "C++")
    
    '''
    print("Len of DisciplineController Controller: ", len(disciplineController))
    print(msg)
    print(disciplineController)
    undoController.undo()
    undoController.undo()
    undoController.undo()
    undoController.undo()
    print(msg)
    
    print("Len of DisciplineController Controller: ", len(disciplineController))
    print(msg)
    print(disciplineController)
    
    undoController.redo()
    undoController.redo()
    undoController.redo()
    undoController.redo()
    print(msg)
    print("Len of DisciplineController Controller: ", len(disciplineController))
    print(disciplineController)
    '''
    
    gradeController.enrollStudent("1", "cc11", [0])
    gradeController.addGrade("1", "cc11", [7])
    gradeController.addGrade("1", "cc11", [10])
    
    gradeController.enrollStudent("2", "cc11", [0])
    gradeController.addGrade("2", "cc11", [9])
    gradeController.addGrade("2", "cc11", [2])
    
    gradeController.enrollStudent("1", "ab133", [0])
    gradeController.addGrade("1", "ab133", [10])
    gradeController.addGrade("1", "ab133", [3])
    
    gradeController.enrollStudent("1", "1", [0])
    gradeController.addGrade("1", "1", [10])
    gradeController.addGrade("1", "1", [3])
    
    print(msg)
    print("Len of GradeController: ", len(gradeController))
    print(gradeController)
    print(msg)
    
    undoController.newOperation()
    studentController.removeStudent("1")
    
    undoController.newOperation()
    studentController.removeStudent("ab133")
    
    print(msg)
    print(studentController)
    print(msg)
    print(msg)
    
    print("Len of GradeController: ", len(gradeController))
    print(gradeController)
    
    undoController.undo()
    print(gradeController)
    
    
    undoController.undo()
    print(gradeController)