Exemplo n.º 1
0
def getActivationFile(prop, PATH):
    nemesys.info('getActivationFile function')
    try:
        #activation code
        ac = str(prop['code'])
        nemesys.info('Activation Code found: %s' % ac)
    except Exception as e:
        nemesys.error(
            'Exception in reading activation code from cfg.properties: ' +
            str(e))
        et = ErrorThread('ace')
        et.start()
        sys.exit(1)
    try:
        path = PATH + os.sep + '..' + os.sep + 'config'
        download = getconf(ac, path, _clientConfigurationFile,
                           _configurationServer)
        nemesys.info('download = %s' % str(download))
        if download != True:
            raise Exception('Download failed')
        else:
            nemesys.info('Configuration file successfully downloaded')
            myProp.writeProps(_PATH + "cfg" + os.sep + "cfg.properties",
                              '\nregistered', 'ok')
            _prop = myProp.readProps(_PATH + "cfg" + os.sep + "cfg.properties")
    except Exception as e:
        nemesys.error('Cannot download the configuration file: ' + str(e))
        nemesys.error('Exit from Ne.Me.Sys.')
        myProp.writeProps(_PATH + "cfg" + os.sep + "cfg.properties",
                          '\nregistered', 'nok')
        _prop = myProp.readProps(_PATH + "cfg" + os.sep + "cfg.properties")
        et = ErrorThread('download')
        et.start()
        sys.exit(1)
Exemplo n.º 2
0
def getActivationFile(prop,PATH):
    nemesys.info('getActivationFile function')
    try:
        #activation code
        ac = str(prop['code'])
        nemesys.info('Activation Code found: %s' % ac)
    except Exception as e:
        nemesys.error('Exception in reading activation code from cfg.properties: '+str(e))
        et = ErrorThread('ace')
        et.start()
        sys.exit(1)
    try:
        path=PATH+os.sep+'..'+os.sep+'config'
        download= getconf(ac, path, _clientConfigurationFile, _configurationServer)
        nemesys.info('download = %s' % str(download))
        if download != True:
            raise Exception('Download failed') 
        else:
            nemesys.info('Configuration file successfully downloaded')
            myProp.writeProps(_PATH+"cfg"+os.sep+"cfg.properties",'\nregistered','ok')
            _prop=myProp.readProps(_PATH+"cfg"+os.sep+"cfg.properties")
    except Exception as e:
        nemesys.error('Cannot download the configuration file: '+str(e))
        nemesys.error('Exit from Ne.Me.Sys.')
        myProp.writeProps(_PATH+"cfg"+os.sep+"cfg.properties",'\nregistered','nok')
        _prop=myProp.readProps(_PATH+"cfg"+os.sep+"cfg.properties")
        et=ErrorThread('download')
        et.start()
        sys.exit(1)
Exemplo n.º 3
0
def getActivationFile(appresult, path, config_path):
    '''
      Scarica il file di configurazione. Ritorna True se tutto è andato bene
    '''
    logger.info('getActivationFile function')

    ac = appresult 
    logger.info('Codici ricevuti: %s' % ac)
    
    download = False
    try:
        download = getconf(ac, path, _clientConfigurationFile, _configurationServer)
        logger.info('download = %s' % str(download))
    except Exception as e:
        logger.error('Cannot download the configuration file: %s' % str(e))
        raise LoginConnectionException(str(e))
    if download != True:
        logger.info('Received error from server, wrong credentials or license not active')
        raise LoginAuthenticationException("")
    else:
        logger.info('Configuration file successfully downloaded')
        myProp.writeProps(config_path,'\nregistered','ok')
        _prop=myProp.readProps(config_path)
        OkDialog()
        return True
Exemplo n.º 4
0
def getActivationFile(appresult, path, config_path):
    '''
      Scarica il file di configurazione. Ritorna True se tutto è andato bene
    '''
    logger.info('getActivationFile function')

    ac = appresult
    logger.info('Codici ricevuti: %s' % ac)

    download = False
    try:
        download = getconf(ac, path, _clientConfigurationFile,
                           _configurationServer)
        logger.info('download = %s' % str(download))
    except Exception as e:
        logger.error('Cannot download the configuration file: %s' % str(e))
        raise LoginConnectionException(str(e))
    if download != True:
        logger.info(
            'Received error from server, wrong credentials or license not active'
        )
        raise LoginAuthenticationException("")
    else:
        logger.info('Configuration file successfully downloaded')
        myProp.writeProps(config_path, '\nregistered', 'ok')
        _prop = myProp.readProps(config_path)
        OkDialog()
        return True
Exemplo n.º 5
0
        myProp.writeProps(_PATH + "cfg" + os.sep + "cfg.properties",
                          '\nregistered', 'nok')
        _prop = myProp.readProps(_PATH + "cfg" + os.sep + "cfg.properties")
        et = ErrorThread('download')
        et.start()
        sys.exit(1)


### Activation code ###
try:
    if 'code' not in _prop:
        appresult = GCGmain()
        nemesys.info('appresult')
        if appresult != '':
            nemesys.info('appresult != ""')
            myProp.writeProps(_PATH + "cfg" + os.sep + "cfg.properties",
                              '\ncode', app.result)
            _prop = myProp.readProps(_PATH + "cfg" + os.sep + "cfg.properties")
            root.destroy()
        else:
            nemesys.info('appresult = ""')
            #root.destroy()
            nemesys.error('Exit: activation code not provided')
            myProp.writeProps(_PATH + "cfg" + os.sep + "cfg.properties",
                              '\nregistered', 'nok')
            _prop = myProp.readProps(_PATH + "cfg" + os.sep + "cfg.properties")
            et = ErrorThread('code')
            et.start()
            raise Exception('Activation Code not provided')
except Exception as e:
    servicemanager.LogWarningMsg('Exception at activation code: ' + str(e))
    sys.exit(1)
Exemplo n.º 6
0
        nemesys.error('Exit from Ne.Me.Sys.')
        myProp.writeProps(_PATH+"cfg"+os.sep+"cfg.properties",'\nregistered','nok')
        _prop=myProp.readProps(_PATH+"cfg"+os.sep+"cfg.properties")
        et=ErrorThread('download')
        et.start()
        sys.exit(1)
        

### Activation code ###
try:
    if 'code' not in _prop:
            appresult = GCGmain()
            nemesys.info('appresult')
            if appresult != '':
                    nemesys.info('appresult != ""')
                    myProp.writeProps(_PATH+"cfg"+os.sep+"cfg.properties",'\ncode',app.result)
                    _prop=myProp.readProps(_PATH+"cfg"+os.sep+"cfg.properties")
                    root.destroy()            
            else:
                    nemesys.info('appresult = ""')
                    #root.destroy()
                    nemesys.error('Exit: activation code not provided')
                    myProp.writeProps(_PATH+"cfg"+os.sep+"cfg.properties",'\nregistered','nok')
                    _prop=myProp.readProps(_PATH+"cfg"+os.sep+"cfg.properties")
                    et=ErrorThread('code')
                    et.start()
                    raise Exception('Activation Code not provided')
except Exception as e:
    servicemanager.LogWarningMsg('Exception at activation code: '+str(e))
    sys.exit(1)
Exemplo n.º 7
0
def main():
    ###  DISCOVERING PATH  ###
    try:
        _PATH = os.path.dirname(sys.argv[0])
        if _PATH == '':
                _PATH="."+os.sep
        if _PATH[len(_PATH)-1] != os.sep: _PATH=_PATH+os.sep
    except Exception as e:
        pass
    
    config_path = _PATH+"cfg"+os.sep+"cfg.properties" 

    ###  READING PROPERTIES  ###
    _prop = None
    try:
        _prop= myProp.readProps(config_path)
    except Exception as e:
        logger.error("Could not read configuration file from %s" % config_path)
        ErrorDialog("File di configurazione non trovata in %s, impossibile procedere con l'installazione" % config_path)
        sys.exit(1)

    if not 'code' in _prop:
        result = False
        j=0
        has_canceled = False
        # Al massimo faccio fare 5 tentativi di inserimento codice di licenza
        while not result and j<5 and not has_canceled:    
                # Prendo un codice licenza valido sintatticamente
            appresult = None
            errorfunc = None
            try:
                appresult = getCode()
                result = getActivationFile(appresult, paths._CONF_DIR, config_path)
            except LoginAuthenticationException as e:
                logger.warning("Authentication failure n. %d" % j)
                errorfunc = CodeError
            except LoginConnectionException as e:
                logger.warning("Authentication connection problem: %s" % str(e))
                errorfunc = ConnectionError
            except LoginCancelledException:
                has_canceled = True
            except LoginOtherException as e:
                logger.warning("Other login problem: %s" % str(e))
                errorfunc = OtherError
            except Exception as e:
                logger.error("Caught exception while downloading configuration file: %s" % str(e) )

            if result == False and not has_canceled and j<4:
                if errorfunc:
                    errorfunc()
                else:
                    logger.warning('Final Error occurred at attempt number %d' %j)
                    FinalError()
            j+=1
    
        if has_canceled:
            CancelError()
            sys.exit(0)
        elif result == False:
            MaxError()
            logger.warning('MaxError occurred at attempt number 5')
            myProp.writeProps(config_path,'\ncode',appresult)
            _prop=myProp.readProps(config_path)
            myProp.writeProps(config_path,'\nregistered','nok')
            _prop=myProp.readProps(config_path)
            sys.exit(1)
        elif result == True:
            logger.info('License file successfully downloaded')
            myProp.writeProps(config_path,'\ncode',appresult)
            _prop=myProp.readProps(config_path)    
    else:
        logger.debug('Activation Code found')
        if 'registered' in _prop:
            #Ho tentato almeno una volta il download
            logger.debug('Registered in _prop')
            status = str(_prop['registered'])
            if status == 'ok':
                # Allora posso continuare lo start del servizio
                logger.debug('Status of registered is Ok')
                logger.info('Configuration file already downloaded')
            else:
                # Il servizio non può partire
                logger.error('Login previously failed. ')
                # Dialog to unistall and retry
                MaxError()
Exemplo n.º 8
0
def main():
    ###  DISCOVERING PATH  ###
    try:
        _PATH = os.path.dirname(sys.argv[0])
        if _PATH == '':
            _PATH = "." + os.sep
        if _PATH[len(_PATH) - 1] != os.sep: _PATH = _PATH + os.sep
    except Exception as e:
        pass

    config_path = _PATH + "cfg" + os.sep + "cfg.properties"

    ###  READING PROPERTIES  ###
    _prop = None
    try:
        _prop = myProp.readProps(config_path)
    except Exception as e:
        logger.error("Could not read configuration file from %s" % config_path)
        ErrorDialog(
            "File di configurazione non trovata in %s, impossibile procedere con l'installazione"
            % config_path)
        sys.exit(1)

    if not 'code' in _prop:
        result = False
        j = 0
        has_canceled = False
        # Al massimo faccio fare 5 tentativi di inserimento codice di licenza
        while not result and j < 5 and not has_canceled:
            # Prendo un codice licenza valido sintatticamente
            appresult = None
            errorfunc = None
            try:
                appresult = getCode()
                result = getActivationFile(appresult, paths._CONF_DIR,
                                           config_path)
            except LoginAuthenticationException as e:
                logger.warning("Authentication failure n. %d" % j)
                errorfunc = CodeError
            except LoginConnectionException as e:
                logger.warning("Authentication connection problem: %s" %
                               str(e))
                errorfunc = ConnectionError
            except LoginCancelledException:
                has_canceled = True
            except LoginOtherException as e:
                logger.warning("Other login problem: %s" % str(e))
                errorfunc = OtherError
            except Exception as e:
                logger.error(
                    "Caught exception while downloading configuration file: %s"
                    % str(e))

            if result == False and not has_canceled and j < 4:
                if errorfunc:
                    errorfunc()
                else:
                    logger.warning(
                        'Final Error occurred at attempt number %d' % j)
                    FinalError()
            j += 1

        if has_canceled:
            CancelError()
            sys.exit(0)
        elif result == False:
            MaxError()
            logger.warning('MaxError occurred at attempt number 5')
            myProp.writeProps(config_path, '\ncode', appresult)
            _prop = myProp.readProps(config_path)
            myProp.writeProps(config_path, '\nregistered', 'nok')
            _prop = myProp.readProps(config_path)
            sys.exit(1)
        elif result == True:
            logger.info('License file successfully downloaded')
            myProp.writeProps(config_path, '\ncode', appresult)
            _prop = myProp.readProps(config_path)
    else:
        logger.debug('Activation Code found')
        if 'registered' in _prop:
            #Ho tentato almeno una volta il download
            logger.debug('Registered in _prop')
            status = str(_prop['registered'])
            if status == 'ok':
                # Allora posso continuare lo start del servizio
                logger.debug('Status of registered is Ok')
                logger.info('Configuration file already downloaded')
            else:
                # Il servizio non può partire
                logger.error('Login previously failed. ')
                # Dialog to unistall and retry
                MaxError()