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'
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 not None:
return True 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: 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 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,18 +52,21 @@ class Agreement:
title = result[1] title = result[1]
contract_id = result[2] contract_id = result[2]
command = 'export DISPLAY={0};python3 {1} \'{2}\' \'{3}\' '.format(display, self.ask_path, content, title) try:
result_code, p_out, p_err = Util.execute(command, as_user=username) command = 'export DISPLAY={0};python3 {1} \'{2}\' \'{3}\' '.format(display, self.ask_path, content, title)
pout = str(p_out).replace('\n', '') result_code, p_out, p_err = Util.execute(command, as_user=username)
if pout != 'Error': pout = str(p_out).replace('\n', '')
if pout == 'Y': if pout != 'Error':
self.logger.debug('[Agreement] Agreement was accepted by {}.'.format(username)) if pout == 'Y':
self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'Y']) self.logger.debug('[Agreement] Agreement was accepted by {}.'.format(username))
elif pout == 'N': self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'Y'])
self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'N']) elif pout == 'N':
self.logger.debug('[Agreement] Agreement was ignored by {}. Session will be closed'.format(username)) self.db_service.update('agreement', self.db_service.get_cols('agreement'), [contract_id, username, Util.timestamp(), 'N'])
Util.execute('pkill -9 -u {}'.format(username)) 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: 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 (Probably argument fault). 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))) 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)