waiting time out in case agreement display error

This commit is contained in:
Volkan Şahin 2016-06-28 12:23:01 +03:00
parent c33e4bdb4d
commit 42e23f082e
2 changed files with 26 additions and 24 deletions

View file

@ -21,15 +21,14 @@ class Agreement:
contract_id = self.get_current_contract_id()
if contract_id is None:
self.logger.debug('[Agreement] There is no any contract in database.')
if self.db_service.select_one_result('agreement', 'id', " contract_id='{0}' and username='{1}' and choice='Y' ".format('-1', username)) is None:
return False
else:
return True
contract_id = '-1'
if self.db_service.select_one_result('agreement', 'id', " contract_id='{0}' and username='{1}' and choice='Y' ".format(contract_id, username)) is not None:
return True
elif self.db_service.select_one_result('agreement', 'id', " contract_id='{0}' and username='{1}' and choice='N' ".format(contract_id, username)) is not None:
return False
else:
if self.db_service.select_one_result('agreement', 'id', " contract_id='{0}' and username='{1}' and choice='Y' ".format(contract_id, username)) is None:
return False
else:
return True
return None
def get_current_contract_id(self):
return self.db_service.select_one_result('contract', 'id', 'id =(select MAX(id) from contract)')
@ -53,18 +52,21 @@ class Agreement:
title = result[1]
contract_id = result[2]
command = 'export DISPLAY={0};python3 {1} \'{2}\' \'{3}\' '.format(display, self.ask_path, content, title)
result_code, p_out, p_err = Util.execute(command, as_user=username)
pout = str(p_out).replace('\n', '')
if pout != 'Error':
if pout == 'Y':
self.logger.debug('[Agreement] Agreement was accepted by {}.'.format(username))
self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'Y'])
elif pout == 'N':
self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'N'])
self.logger.debug('[Agreement] Agreement was ignored by {}. Session will be closed'.format(username))
Util.execute('pkill -9 -u {}'.format(username))
try:
command = 'export DISPLAY={0};python3 {1} \'{2}\' \'{3}\' '.format(display, self.ask_path, content, title)
result_code, p_out, p_err = Util.execute(command, as_user=username)
pout = str(p_out).replace('\n', '')
if pout != 'Error':
if pout == 'Y':
self.logger.debug('[Agreement] Agreement was accepted by {}.'.format(username))
self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'Y'])
elif pout == 'N':
self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'N'])
self.logger.debug('[Agreement] Agreement was ignored by {}. Session will be closed'.format(username))
else:
self.logger.error('[Agreement] A problem occurred while executing ask.py. Error Message: {}'.format(str(pout)))
else:
self.logger.error('[Agreement] A problem occurred while executing ask.py. Error Message: {}'.format(str(pout)))
else:
self.logger.error('[Agreement] A problem occurred while executing ask.py (Probably argument fault). Error Message: {}'.format(str(pout)))
self.logger.error('[Agreement] A problem occurred while executing ask.py (Probably argument fault). Error Message: {}'.format(str(pout)))
except Exception as e:
self.logger.error('[Agreement] A Problem occurred while displaying agreement. Error Message: {}'.format(str(e)))

View file

@ -49,8 +49,8 @@ class ExecutionManager(object):
def agreement_update(self, arg):
plugin = json.loads(arg)
if plugin['content'] != 'null' and plugin['content']!='':
self.db_service.update('contract',self.db_service.get_cols('contract'),[plugin['content'],plugin['title'],plugin['timestamp']])
if plugin['content'] != 'null' and plugin['content'] != '':
self.db_service.update('contract', self.db_service.get_cols('contract'), [plugin['content'], plugin['title'], plugin['timestamp']])
def install_plugin(self, arg):
plugin = json.loads(arg)