def _on_tray_icon_command(self, cmd): lg.out(2, "initializer._on_tray_icon_command : [%s]" % cmd) try: if cmd == 'exit': shutdowner.A('stop', 'exit') elif cmd == 'restart': shutdowner.A('stop', 'restart') elif cmd == 'reconnect': from p2p import network_connector if driver.is_on('service_network'): network_connector.A('reconnect') elif cmd == 'show': from web import control control.show() elif cmd == 'sync': try: from updates import git_proc from system import tray_icon def _sync_callback(result): if result == 'error': tray_icon.draw_icon('error') reactor.callLater(5, tray_icon.restore_icon) return elif result == 'source-code-fetched': tray_icon.draw_icon('updated') reactor.callLater(5, tray_icon.restore_icon) return tray_icon.restore_icon() tray_icon.draw_icon('sync') git_proc.sync(_sync_callback) except: lg.exc() elif cmd == 'hide': pass elif cmd == 'toolbar': pass else: lg.warn('wrong command: ' + str(cmd)) except: lg.exc()
def _on_software_code_updated(self, evt): lg.out(2, 'initializer._on_software_code_updated will RESTART BitDust now! "source-code-fetched" event received') if False: # TODO: add checks to prevent restart if any important jobs running at the moment return if False: # TODO: add an option to the settings return shutdowner.A('stop', 'restart')
def shutdown(): from logs import lg from main import config from system import bpio lg.out(2, 'bpmain.shutdown') import shutdowner shutdowner.A('reactor-stopped') from main import events events.shutdown() from automats import automat automat.objects().clear() if len(automat.index()) > 0: lg.warn('%d automats was not cleaned' % len(automat.index())) for a in automat.index().keys(): lg.out(2, ' %r' % a) else: lg.out( 2, 'bpmain.shutdown automat.objects().clear() SUCCESS, no state machines left in memory' ) config.conf().removeCallback('logs/debug-level') lg.out( 2, 'bpmain.shutdown currently %d threads running:' % len(threading.enumerate())) for t in threading.enumerate(): lg.out(2, ' ' + str(t)) lg.out(2, 'bpmain.shutdown finishing and closing log file, EXIT') automat.CloseLogFile() lg.close_log_file() if bpio.Windows() and bpio.isFrozen(): lg.stdout_stop_redirecting() return 0
def A(self, event, arg): #---AT_STARTUP--- if self.state == 'AT_STARTUP': if event == 'run': self.state = 'LOCAL' shutdowner.A('init') self.doInitLocal(arg) self.flagCmdLine = False elif event == 'run-cmd-line-register': self.state = 'INSTALL' shutdowner.A('init') self.flagCmdLine = True installer.A('register-cmd-line', arg) shutdowner.A('ready') elif event == 'run-cmd-line-recover': self.state = 'INSTALL' shutdowner.A('init') self.flagCmdLine = True installer.A('recover-cmd-line', arg) shutdowner.A('ready') #---LOCAL--- elif self.state == 'LOCAL': if event == 'init-local-done' and not self.isInstalled( arg) and self.isGUIPossible(arg): self.state = 'INSTALL' installer.A('init') shutdowner.A('ready') self.doInitInterfaces(arg) self.doShowGUI(arg) self.doUpdate(arg) elif (event == 'shutdowner.state' and arg == 'FINISHED'): self.state = 'STOPPING' self.doDestroyMe(arg) elif event == 'init-local-done' and ( (not self.isInstalled(arg) and not self.isGUIPossible(arg)) or self.isInstalled(arg)): self.state = 'INTERFACES' shutdowner.A('ready') self.doInitInterfaces(arg) #---MODULES--- elif self.state == 'MODULES': if event == 'init-modules-done': self.state = 'READY' self.doUpdate(arg) self.doShowGUI(arg) elif (event == 'shutdowner.state' and arg == 'FINISHED'): self.state = 'EXIT' self.doDestroyMe(arg) #---INSTALL--- elif self.state == 'INSTALL': if not self.flagCmdLine and (event == 'installer.state' and arg == 'DONE'): self.state = 'STOPPING' shutdowner.A('stop', "restartnshow") elif self.flagCmdLine and (event == 'installer.state' and arg == 'DONE'): self.state = 'STOPPING' shutdowner.A('stop', "exit") elif (event == 'shutdowner.state' and arg == 'FINISHED'): self.state = 'EXIT' self.doDestroyMe(arg) #---READY--- elif self.state == 'READY': if (event == 'shutdowner.state' and arg == 'FINISHED'): self.state = 'EXIT' self.doDestroyMe(arg) #---STOPPING--- elif self.state == 'STOPPING': if (event == 'shutdowner.state' and arg == 'FINISHED'): self.state = 'EXIT' self.doUpdate(arg) self.doDestroyMe(arg) #---EXIT--- elif self.state == 'EXIT': pass #---SERVICES--- elif self.state == 'SERVICES': if event == 'init-services-done': self.state = 'MODULES' self.doInitModules(arg) shutdowner.A('ready') elif (event == 'shutdowner.state' and arg == 'FINISHED'): self.state = 'EXIT' self.doDestroyMe(arg) #---INTERFACES--- elif self.state == 'INTERFACES': if event == 'init-interfaces-done': self.state = 'SERVICES' self.doInitServices(arg) elif (event == 'shutdowner.state' and arg == 'FINISHED'): self.state = 'EXIT' self.doDestroyMe(arg) return None
def _tray_control_func(cmd): if cmd == 'exit': import shutdowner shutdowner.A('stop', 'exit')