Exemple #1
0
 def __init__(self, fName):
     self.__fileName = fName
     self.contactList = list()
     self.validator = Validator()
     try:
         self.__contactsFile = open(self.__fileName, "r")
     except IOError:
         self.__contactsFile = open(self.__fileName, "w")
         self.__contactsFile.close()
         self.__contactsFile = open(self.__fileName, "r")
     self.readFile()
Exemple #2
0
class Repository:
    
    def __init__(self,fName):
        self.__fileName = fName
        self.contactList = list()
        self.validator = Validator()
        try:       
            self.__contactsFile = open (self.__fileName,"r")
        except IOError:
            self.__contactsFile = open (self.__fileName,"w")
            self.__contactsFile.close()
            self.__contactsFile = open (self.__fileName,"r")
        self.readFile()
        
    def readFile(self):
        line = "nonempty"
        while line != "":
            line = self.__contactsFile.readline()
            if line != "":
                elements = line.split(",")
                contact = Contact (elements[0].strip(), elements[1].strip(), elements[2].strip(), elements[3].strip())
                self.contactList.append(contact)              
        self.__contactsFile.close()
        
    def storeContact(self,id,name,phoneNr,group):
        contact = Contact (id,name,phoneNr,group)
        errorList = self.validator.validateContact(contact)
        if len(errorList) != 0:
            return errorList
        self.contactList.append(contact)
        self.__contactsFile = open (self.__fileName,"w")
        for contact in self.contactList:
            self.__contactsFile.write(str(contact.getId()) + "," + contact.getName() + "," + contact.getPhoneNr() + "," + contact.getGroup() + "\n")
        self.__contactsFile.close()
        return "Contact added successfully!"
Exemple #3
0
 def __init__(self, fName):
     self.__fName = fName
     self.validator = Validator()
     self.labList = list()
     try:
         self.__labFile = open(self.__fName, "r")
     except IOError:
         self.__labFile = open(self.__fName, "w")
         self.__labFile.close()
         self.__labFile = open(self.__fName, "r")
     self.readFile()
Exemple #4
0
 def __init__(self,fName):
     self.__fileName = fName
     self.contactList = list()
     self.validator = Validator()
     try:       
         self.__contactsFile = open (self.__fileName,"r")
     except IOError:
         self.__contactsFile = open (self.__fileName,"w")
         self.__contactsFile.close()
         self.__contactsFile = open (self.__fileName,"r")
     self.readFile()
Exemple #5
0
class Repository:
    def __init__(self, fName):
        self.__fileName = fName
        self.contactList = list()
        self.validator = Validator()
        try:
            self.__contactsFile = open(self.__fileName, "r")
        except IOError:
            self.__contactsFile = open(self.__fileName, "w")
            self.__contactsFile.close()
            self.__contactsFile = open(self.__fileName, "r")
        self.readFile()

    def readFile(self):
        line = "nonempty"
        while line != "":
            line = self.__contactsFile.readline()
            if line != "":
                elements = line.split(",")
                contact = Contact(elements[0].strip(), elements[1].strip(),
                                  elements[2].strip(), elements[3].strip())
                self.contactList.append(contact)
        self.__contactsFile.close()

    def storeContact(self, id, name, phoneNr, group):
        contact = Contact(id, name, phoneNr, group)
        errorList = self.validator.validateContact(contact)
        if len(errorList) != 0:
            return errorList
        self.contactList.append(contact)
        self.__contactsFile = open(self.__fileName, "w")
        for contact in self.contactList:
            self.__contactsFile.write(
                str(contact.getId()) + "," + contact.getName() + "," +
                contact.getPhoneNr() + "," + contact.getGroup() + "\n")
        self.__contactsFile.close()
        return "Contact added successfully!"
Exemple #6
0
'''
Created on 22.02.2013

@author: mihai_000
'''
from Domain.Validator import Validator
from Repository.Repository import Repository
from UI.Console import Console
from UI.Controller import Controller

if __name__ == '__main__':
    bookRepository = Repository("books.txt")
    bookValidator = Validator()
    bookController = Controller(bookRepository, bookValidator)
    bookConsole = Console(bookController)
    bookConsole.run()
Exemple #7
0
'''
Created on 23.02.2013

@author: mihai_000
'''
from Domain.Validator import Validator
from Repository.Repository import Repository
from UI.Console import Console
from UI.Controller import Controller, test_Controller

if __name__ == '__main__':
    transRepository = Repository("dictionary.txt")
    testRepository = Repository("test.txt")
    transValidator = Validator()
    transController = Controller(transRepository, transValidator)
    testController = test_Controller(testRepository, transValidator)
    transConsole = Console(transController)
    transConsole.run()