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)
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)
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
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
### 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 #print _PATH #servicemanager.LogInfoMsg('Executable path: '+str(_PATH)) except Exception as e: #servicemanager.LogErrorMsg('Exception at executable path: '+str(e)) pass ### READING PROPERTIES ### try: _prop = myProp.readProps(_PATH + "cfg" + os.sep + "cfg.properties") #servicemanager.LogInfoMsg('properties path: '+str(_PATH)+'cfg\cfg.properties') except Exception as e: #servicemanager.LogErrorMsg('Exception properties path: '+str(e)) pass ### Logging Functionality ### #quando esegui da linea di comando il file di prop e' in C:\Python26\Lib\site-packages\win32\cfg !! nemesys = logging.getLogger("nemesys") nemesys.setLevel(logging.DEBUG) fh1 = logging.FileHandler(_PATH + 'errorGui.log') fh1.setLevel(logging.DEBUG) formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") fh1.setFormatter(formatter) nemesys.addHandler(fh1)
### 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 #print _PATH #servicemanager.LogInfoMsg('Executable path: '+str(_PATH)) except Exception as e: #servicemanager.LogErrorMsg('Exception at executable path: '+str(e)) pass ### READING PROPERTIES ### try: _prop= myProp.readProps(_PATH+"cfg"+os.sep+"cfg.properties") #servicemanager.LogInfoMsg('properties path: '+str(_PATH)+'cfg\cfg.properties') except Exception as e: #servicemanager.LogErrorMsg('Exception properties path: '+str(e)) pass ### Logging Functionality ### #quando esegui da linea di comando il file di prop e' in C:\Python26\Lib\site-packages\win32\cfg !! nemesys = logging.getLogger("nemesys") nemesys.setLevel(logging.DEBUG) fh1 = logging.FileHandler(_PATH+'errorGui.log') fh1.setLevel(logging.DEBUG) formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") fh1.setFormatter(formatter) nemesys.addHandler(fh1)
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()
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()