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() contract_id = self.get_current_contract_id()
if contract_id is None: if contract_id is None:
self.logger.debug('[Agreement] There is no any contract in database.') 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: 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 return False
else: else:
return True return None
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
def get_current_contract_id(self): def get_current_contract_id(self):
return self.db_service.select_one_result('contract', 'id', 'id =(select MAX(id) from contract)') return self.db_service.select_one_result('contract', 'id', 'id =(select MAX(id) from contract)')
@ -53,6 +52,7 @@ class Agreement:
title = result[1] title = result[1]
contract_id = result[2] contract_id = result[2]
try:
command = 'export DISPLAY={0};python3 {1} \'{2}\' \'{3}\' '.format(display, self.ask_path, content, title) 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) result_code, p_out, p_err = Util.execute(command, as_user=username)
pout = str(p_out).replace('\n', '') pout = str(p_out).replace('\n', '')
@ -63,8 +63,10 @@ class Agreement:
elif pout == 'N': elif pout == 'N':
self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), '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)) self.logger.debug('[Agreement] Agreement was ignored by {}. Session will be closed'.format(username))
Util.execute('pkill -9 -u {}'.format(username))
else: else:
self.logger.error('[Agreement] A problem occurred while executing ask.py. Error Message: {}'.format(str(pout))) self.logger.error('[Agreement] A problem occurred while executing ask.py. Error Message: {}'.format(str(pout)))
else: 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): def agreement_update(self, arg):
plugin = json.loads(arg) plugin = json.loads(arg)
if plugin['content'] != 'null' and plugin['content']!='': if plugin['content'] != 'null' and plugin['content'] != '':
self.db_service.update('contract',self.db_service.get_cols('contract'),[plugin['content'],plugin['title'],plugin['timestamp']]) self.db_service.update('contract', self.db_service.get_cols('contract'), [plugin['content'], plugin['title'], plugin['timestamp']])
def install_plugin(self, arg): def install_plugin(self, arg):
plugin = json.loads(arg) plugin = json.loads(arg)