#718: Mejorar la comprobación de salida de la sesión de usuario.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@4971 a21b9725-9963-47de-94b9-378ad31fedc9
remotes/github/oglive
ramon 2016-07-01 09:01:54 +00:00
parent 11f7a07988
commit 98fc98d803
1 changed files with 38 additions and 23 deletions

View File

@ -39,6 +39,7 @@ import time
import signal import signal
import json import json
import six import six
import atexit
from opengnsys import ipc from opengnsys import ipc
from opengnsys import utils from opengnsys import utils
@ -54,11 +55,15 @@ from opengnsys.loader import loadModules
trayIcon = None trayIcon = None
def sigAtExit():
def sigTerm(sigNo, stackFrame): #logger.debug("Exec sigAtExit")
if trayIcon: if trayIcon:
trayIcon.quit() trayIcon.quit()
#def sigTerm(sigNo, stackFrame):
# logger.debug("Exec sigTerm")
# if trayIcon:
# trayIcon.quit()
# About dialog # About dialog
class OGAAboutDialog(QtGui.QDialog): class OGAAboutDialog(QtGui.QDialog):
@ -161,17 +166,16 @@ class MessagesProcessor(QtCore.QThread):
class OGASystemTray(QtGui.QSystemTrayIcon): class OGASystemTray(QtGui.QSystemTrayIcon):
def __init__(self, app_, parent=None): def __init__(self, app_, parent=None):
self.app = app_ self.app = app_
self.config = readConfig(client=True) self.config = readConfig(client=True)
# Get opengnsys section as dict # Get opengnsys section as dict
cfg = dict(self.config.items('opengnsys')) cfg = dict(self.config.items('opengnsys'))
# Set up log level # Set up log level
logger.setLevel(cfg.get('log', 'INFO')) logger.setLevel(cfg.get('log', 'INFO'))
self.ipcport = int(cfg.get('ipc_port', IPC_PORT)) self.ipcport = int(cfg.get('ipc_port', IPC_PORT))
# style = app.style() # style = app.style()
# icon = QtGui.QIcon(style.standardPixmap(QtGui.QStyle.SP_ComputerIcon)) # icon = QtGui.QIcon(style.standardPixmap(QtGui.QStyle.SP_ComputerIcon))
icon = QtGui.QIcon(':/images/img/oga.png') icon = QtGui.QIcon(':/images/img/oga.png')
@ -182,10 +186,10 @@ class OGASystemTray(QtGui.QSystemTrayIcon):
exitAction.triggered.connect(self.about) exitAction.triggered.connect(self.about)
self.setContextMenu(self.menu) self.setContextMenu(self.menu)
self.ipc = MessagesProcessor(self.ipcport) self.ipc = MessagesProcessor(self.ipcport)
if self.ipc.isAlive() is False: if self.ipc.isAlive() is False:
raise Exception('No connection to service, exiting.') raise Exception('No connection to service, exiting.')
self.timer = QtCore.QTimer() self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.timerFnc) self.timer.timeout.connect(self.timerFnc)
@ -203,13 +207,13 @@ class OGASystemTray(QtGui.QSystemTrayIcon):
self.timer.start(1000) # Launch idle checking every 1 seconds self.timer.start(1000) # Launch idle checking every 1 seconds
self.ipc.start() self.ipc.start()
def initialize(self): def initialize(self):
# Load modules and activate them # Load modules and activate them
# Also, sends "login" event to service # Also, sends "login" event to service
self.modules = loadModules(self, client=True) self.modules = loadModules(self, client=True)
logger.debug('Modules: {}'.format(list(v.name for v in self.modules))) logger.debug('Modules: {}'.format(list(v.name for v in self.modules)))
# Send init to all modules # Send init to all modules
validMods = [] validMods = []
for mod in self.modules: for mod in self.modules:
@ -220,7 +224,7 @@ class OGASystemTray(QtGui.QSystemTrayIcon):
except Exception as e: except Exception as e:
logger.exception() logger.exception()
logger.error("Activation of {} failed: {}".format(mod.name, utils.exceptionToMessage(e))) logger.error("Activation of {} failed: {}".format(mod.name, utils.exceptionToMessage(e)))
self.modules[:] = validMods # copy instead of assignment self.modules[:] = validMods # copy instead of assignment
# If this is running, it's because he have logged in, inform service of this fact # If this is running, it's because he have logged in, inform service of this fact
@ -257,12 +261,12 @@ class OGASystemTray(QtGui.QSystemTrayIcon):
return return
except Exception as e: except Exception as e:
logger.error('Got exception {} processing generic message on {}'.format(e, v.name)) logger.error('Got exception {} processing generic message on {}'.format(e, v.name))
logger.error('Module {} not found, messsage {} not sent'.format(module, message)) logger.error('Module {} not found, messsage {} not sent'.format(module, message))
def executeScript(self, script): def executeScript(self, script):
logger.debug('Executing script') logger.debug('Executing script')
script = six.text_type(script.toUtf8()).decode('base64') script = six.text_type(script.toUtf8()).decode('base64')
th = ScriptExecutorThread(script) th = ScriptExecutorThread(script)
th.start() th.start()
@ -273,7 +277,7 @@ class OGASystemTray(QtGui.QSystemTrayIcon):
def about(self): def about(self):
self.aboutDlg.exec_() self.aboutDlg.exec_()
def quit(self): def cleanup(self):
logger.debug('Quit invoked') logger.debug('Quit invoked')
if self.stopped is False: if self.stopped is False:
self.stopped = True self.stopped = True
@ -282,7 +286,7 @@ class OGASystemTray(QtGui.QSystemTrayIcon):
except Exception: except Exception:
logger.exception() logger.exception()
logger.error('Got exception deinitializing modules') logger.error('Got exception deinitializing modules')
try: try:
# If we close Client, send Logoff to Broker # If we close Client, send Logoff to Broker
self.ipc.sendLogout(operations.getCurrentUser()) self.ipc.sendLogout(operations.getCurrentUser())
@ -292,13 +296,22 @@ class OGASystemTray(QtGui.QSystemTrayIcon):
# May we have lost connection with server, simply exit in that case # May we have lost connection with server, simply exit in that case
pass pass
try: try:
# operations.logoff() # Uncomment this after testing to logoff user # operations.logoff() # Uncomment this after testing to logoff user
pass pass
except Exception: except Exception:
pass pass
self.app.quit() def quit(self):
#logger.debug("Exec quit {}".format(self.stopped))
if self.stopped is False:
self.cleanup()
self.app.quit()
def closeEvent(self,event):
logger.debug("Exec closeEvent")
event.accept()
self.quit()
if __name__ == '__main__': if __name__ == '__main__':
app = QtGui.QApplication(sys.argv) app = QtGui.QApplication(sys.argv)
@ -325,10 +338,12 @@ if __name__ == '__main__':
trayIcon.quit() trayIcon.quit()
sys.exit(1) sys.exit(1)
app.aboutToQuit.connect(trayIcon.cleanup)
trayIcon.show() trayIcon.show()
# Catch kill and logout user :) # Catch kill and logout user :)
signal.signal(signal.SIGTERM, sigTerm) #signal.signal(signal.SIGTERM, sigTerm)
atexit.register(sigAtExit)
res = app.exec_() res = app.exec_()