def runTest(self):
        dao = GecosAccessDataDAO()

        print "Try to load original data..."
        originalData = dao.load()

        print "Set test data..."
        newData = GecosAccessData()
        newData.set_url('test_url')
        newData.set_login('test_login')
        dao.save(newData)

        print "Load and check test data..."
        newData = dao.load()

        self.assertEqual(newData.get_url(), 'test_url')
        self.assertEqual(newData.get_login(), 'test_login')

        wddao = WorkstationDataDAO()
        wd = wddao.load()

        dao.delete(newData)
        self.assertFalse(os.path.isfile('/etc/gcc.control'))

        if originalData is not None:
            print "Restore original data..."
            dao.save(originalData)
            wddao.save(wd)
    def __init__(self, mainController):
        '''
        Constructor
        '''

        self.view = None  # TODO!
        self.controller = mainController
        self.gecosAccessDao = GecosAccessDataDAO()
        self.workstationDataDao = WorkstationDataDAO()
        self.localUserDao = LocalUserDAO()
        self.networkInterfaceDao = NetworkInterfaceDAO()
        self.ntpServerDao = NTPServerDAO()
        self.userAuthenticationMethodDao = UserAuthenticationMethodDAO()
        self.logger = logging.getLogger('SystemStatusController')
 def runTest(self):
     dao = WorkstationDataDAO()
     
     
     originalData = dao.load() 
     
     # Set a new name for this pc
     newData = WorkstationData()
     newData.set_name('test_name')
     newData.set_node_name('test_node_name')
     dao.save(newData)
     
     newData = dao.load()
     
     self.assertEqual(newData.get_name(), 'test_name')
     self.assertEqual(newData.get_node_name(), 'test_node_name')
     
     dao.delete(newData)
     self.assertFalse(os.path.isfile('/etc/pclabel'))
     
     if originalData is not None:
         dao.save(originalData)
class SystemStatusController(object):
    '''
    Controller class for the "show system status" functionality.
    '''
    def __init__(self, mainController):
        '''
        Constructor
        '''

        self.view = None  # TODO!
        self.controller = mainController
        self.gecosAccessDao = GecosAccessDataDAO()
        self.workstationDataDao = WorkstationDataDAO()
        self.localUserDao = LocalUserDAO()
        self.networkInterfaceDao = NetworkInterfaceDAO()
        self.ntpServerDao = NTPServerDAO()
        self.userAuthenticationMethodDao = UserAuthenticationMethodDAO()
        self.logger = logging.getLogger('SystemStatusController')

    def show(self):
        ''' Show system status window '''

        self.view = SystemStatusElemDialog(self, self.controller.window)
        pm = PackageManager()

        status = SystemStatus()
        status.set_cga_version(
            pm.get_package_version('gecosws-config-assistant'))
        status.set_network_interfaces(self.networkInterfaceDao.loadAll())
        status.set_time_server(self.ntpServerDao.load())
        status.set_workstation_data(self.workstationDataDao.load())
        status.set_gecos_access_data(self.gecosAccessDao.load())
        status.set_local_users(self.localUserDao.loadAll())
        status.set_user_authentication_method(
            self.userAuthenticationMethodDao.load())

        self.view.set_data(status)
        self.view.show()

    def hide(self):
        ''' Hide system status window '''

        # TODO implement this meth
        pass
    )

    from gecosws_config_assistant.dto.GecosAccessData import GecosAccessData
    from gecosws_config_assistant.dto.WorkstationData import WorkstationData
    from gecosws_config_assistant.dao.WorkstationDataDAO import WorkstationDataDAO
    from gecosws_config_assistant.dao.GecosAccessDataDAO import GecosAccessDataDAO

    accessDataDao = GecosAccessDataDAO()
    gecosAccessData = accessDataDao.load()
    if gecosAccessData is None:
        logging.error("Error reading c:\\etc\\gcc.control")
        nsis.setvar('4', "Error reading c:\\etc\\gcc.control")
        nsis.setvar('5', "")
        sys.exit()

    workstationDataDao = WorkstationDataDAO()
    workstationData = workstationDataDao.load()
    if workstationData is None:
        logging.error("Error reading c:\\etc\\gcc.control or C:\\etc\\pclabel")
        nsis.setvar('4',
                    "Error reading c:\\etc\\gcc.control or C:\\etc\\pclabel")
        nsis.setvar('5', "")
        sys.exit()

    nsis.setvar('0', gecosAccessData.get_url())
    nsis.setvar('1', gecosAccessData.get_login())
    nsis.setvar('2', workstationData.get_name())
    nsis.setvar('3', workstationData.get_node_name())

except SystemExit:
    nsis.setvar('6', "error")
    from gecosws_config_assistant.dao.WorkstationDataDAO import WorkstationDataDAO

    nsis.setvar('6', "false")
    gecosAccessData = GecosAccessData()
    gecosAccessData.set_url(nsis.getvar('$0'))
    gecosAccessData.set_login(nsis.getvar('$1'))
    gecosAccessData.set_password(nsis.getvar('$2'))
    
    if not os.path.isdir(os.path.join('C:\\', 'etc')):
        os.mkdir(os.path.join('C:\\', 'etc'))
    
    workstationData = WorkstationData()
    workstationData.set_ou(nsis.getvar('$3').decode('iso-8859-1').encode('utf-8'))
    workstationData.set_name(nsis.getvar('$4'))
    workstationData.set_node_name( binascii.hexlify(base64.b64decode(nsis.getvar('$5'))) )
    workstationDataDao = WorkstationDataDAO()

    # Check if exists "C:\chef\client.pem"
    if os.path.isfile(os.path.join('C:\\', 'chef', 'client.pem')):
        logging.error("Already exists a C:\\chef\\client.pem file")
        nsis.setvar('3', "error")
        nsis.setvar('4', "Already exists a C:\\chef\\client.pem file")
        nsis.setvar('5', "")
        sys.exit()    
    
    # Save workstation data
    workstationDataDao.save(workstationData)

    # Check c:\chef directory
    if not os.path.isdir(os.path.join('C:\\', 'chef')):
        os.mkdir(os.path.join('C:\\', 'chef'))