Ejemplo n.º 1
0
def on_tray_icon_command(cmd):
    from main import shutdowner
    from services import driver
    from p2p import network_connector
    lg.out(2, 'on_tray_icon_command %s' % cmd)
    if cmd == 'exit':
        # SendCommandToGUI('exit')
        shutdowner.A('stop', 'exit')

    elif cmd == 'restart':
        # SendCommandToGUI('exit')
        appList = bpio.find_process(['bpgui.', ])
        if len(appList) > 0:
            shutdowner.A('stop', 'restartnshow')  # ('restart', 'show'))
        else:
            shutdowner.A('stop', 'restart')  # ('restart', ''))

    elif cmd == 'reconnect':
        if driver.is_on('service_network'):
            network_connector.A('reconnect')

    elif cmd == 'show':
        show()

    elif cmd == 'hide':
        pass
        # SendCommandToGUI('exit')

    elif cmd == 'toolbar':
        pass
        # SendCommandToGUI('toolbar')

    else:
        lg.warn('wrong command: ' + str(cmd))
Ejemplo n.º 2
0
 def _call_upnp(port):
     # start messing with upnp settings
     # success can be false if you're behind a router that doesn't support upnp
     # or if you are not behind a router at all and have an external ip address
     from system import run_upnpc
     shutdowner.A('block')
     success, port = run_upnpc.update(port)
     shutdowner.A('unblock')
     return (success, port)
Ejemplo n.º 3
0
    def _on_tray_icon_command(self, cmd):
        if _Debug:
            lg.out(_DebugLevel,
                   "initializer._on_tray_icon_command : [%s]" % cmd)
        try:
            from main import shutdowner
            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':
                # TODO: raise up electron window ?
                pass

            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)  # @UndefinedVariable
                            return
                        elif result == 'source-code-fetched':
                            tray_icon.draw_icon('updated')
                            reactor.callLater(
                                5,
                                tray_icon.restore_icon)  # @UndefinedVariable
                            return
                        tray_icon.restore_icon()

                    tray_icon.draw_icon('sync')
                    git_proc.sync(_sync_callback, update_method='reset')
                except:
                    lg.exc()

            elif cmd == 'hide':
                pass

            elif cmd == 'toolbar':
                pass

            else:
                lg.warn('wrong command: ' + str(cmd))
        except:
            lg.exc()
Ejemplo n.º 4
0
def step4(version_digest):
    lg.out(4, 'os_windows_update.step4')
    global _UpdatingInProgress
    global _CurrentVersionDigest
    global _NewVersionNotifyFunc
    global _UpdatingByUser

    _CurrentVersionDigest = str(version_digest)
    local_version = bpio.ReadBinaryFile(settings.CheckSumFile())
    if local_version == _CurrentVersionDigest:
        lg.out(6, 'os_windows_update.step4 no need to update')
        _UpdatingInProgress = False
        return

    lg.out(
        6, 'os_windows_update.step4 local=%s current=%s ' %
        (local_version, _CurrentVersionDigest))

    if settings.getUpdatesMode() == settings.getUpdatesModeValues(
    )[2] and not _UpdatingByUser:
        lg.out(
            6,
            'os_windows_update.step4 run scheduled, but mode is %s, skip now' %
            settings.getUpdatesMode())
        return

    if _UpdatingByUser or settings.getUpdatesMode(
    ) == settings.getUpdatesModeValues()[0]:
        #        info_file_path = os.path.join(bpio.getExecutableDir(), settings.FilesDigestsFilename())
        info_file_path = settings.InfoFile()
        if os.path.isfile(info_file_path):
            try:
                os.remove(info_file_path)
            except:
                lg.out(
                    1, 'os_windows_update.step4 ERROR can no remove ' +
                    info_file_path)
                lg.exc()

        param = ''
        if _UpdatingByUser:
            param = 'show'
        from main import shutdowner
        if param == 'show':
            shutdowner.A('stop', 'restartnshow')
        else:
            shutdowner.A('stop', 'restart')

    else:
        if _NewVersionNotifyFunc is not None:
            _NewVersionNotifyFunc(_CurrentVersionDigest)
Ejemplo n.º 5
0
def shutdown():
    from logs import lg
    from main import config
    from system import bpio
    if _Debug:
        lg.out(_DebugLevel, 'bpmain.shutdown')

    if config.conf():
        config.conf().removeConfigNotifier('logs/debug-level')

    from main import shutdowner
    shutdowner.A('reactor-stopped')

    from main import listeners
    listeners.shutdown()

    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():
            if _Debug:
                lg.out(_DebugLevel, '    %r' % a)
    else:
        if _Debug:
            lg.out(
                _DebugLevel,
                'bpmain.shutdown automat.objects().clear() SUCCESS, no state machines left in memory'
            )

    if _Debug:
        lg.out(
            _DebugLevel, 'bpmain.shutdown currently %d threads running:' %
            len(threading.enumerate()))
    for t in threading.enumerate():
        if _Debug:
            lg.out(_DebugLevel, '    ' + str(t))

    if _Debug:
        lg.out(_DebugLevel,
               'bpmain.shutdown finishing and closing log file, EXIT')

    # automat.CloseLogFile()
    automat.SetExceptionsHandler(None)
    automat.SetLogOutputHandler(None)

    lg.close_log_file()

    lg.close_intercepted_log_file()

    lg.stdout_stop_redirecting()
    lg.stderr_stop_redirecting()

    from main import settings
    settings.shutdown()

    return 0
Ejemplo n.º 6
0
 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
     from main import shutdowner
     shutdowner.A('stop', 'restart')
Ejemplo n.º 7
0
def stop_bitdust():
    executable_path = os.getcwd()
    print('stop_bitdust executable_path=%r' % executable_path)
    try:
        os.chdir('bitdust')
    except:
        pass
    print('executable_path after : %r' % os.getcwd())
    from main import shutdowner
    # reactor.callLater(0, shutdowner.A, 'stop', 'exit')  # @UndefinedVariable
    shutdowner.A('stop', 'exit')
    return True
Ejemplo n.º 8
0
 def A(self, event, *args, **kwargs):
     from main import installer
     from main import shutdowner
     #---AT_STARTUP---
     if self.state == 'AT_STARTUP':
         if event == 'run':
             self.state = 'LOCAL'
             shutdowner.A('init')
             self.doInitLocal(*args, **kwargs)
             self.flagCmdLine = False
         elif event == 'run-cmd-line-register':
             self.state = 'INSTALL'
             shutdowner.A('init')
             self.flagCmdLine = True
             installer.A('register-cmd-line', *args, **kwargs)
             shutdowner.A('ready')
         elif event == 'run-cmd-line-recover':
             self.state = 'INSTALL'
             shutdowner.A('init')
             self.flagCmdLine = True
             installer.A('recover-cmd-line', *args, **kwargs)
             shutdowner.A('ready')
     #---LOCAL---
     elif self.state == 'LOCAL':
         if event == 'init-local-done' and not self.isInstalled(
                 *args, **kwargs) and self.isGUIPossible(*args, **kwargs):
             self.state = 'INSTALL'
             installer.A('init')
             shutdowner.A('ready')
             self.doInitInterfaces(*args, **kwargs)
             self.doShowGUI(*args, **kwargs)
             self.doUpdate(*args, **kwargs)
         elif (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'STOPPING'
             self.doDestroyMe(*args, **kwargs)
         elif event == 'init-local-done' and (
             (not self.isInstalled(*args, **kwargs)
              and not self.isGUIPossible(*args, **kwargs))
                 or self.isInstalled(*args, **kwargs)):
             self.state = 'INTERFACES'
             shutdowner.A('ready')
             self.doInitInterfaces(*args, **kwargs)
     #---MODULES---
     elif self.state == 'MODULES':
         if event == 'init-modules-done':
             self.state = 'READY'
             self.doUpdate(*args, **kwargs)
             self.doShowGUI(*args, **kwargs)
         elif (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doDestroyMe(*args, **kwargs)
     #---INSTALL---
     elif self.state == 'INSTALL':
         if not self.flagCmdLine and (event == 'installer.state'
                                      and args[0] == 'DONE'):
             self.state = 'STOPPING'
             shutdowner.A('stop', "restartnshow")
         elif self.flagCmdLine and (event == 'installer.state'
                                    and args[0] == 'DONE'):
             self.state = 'STOPPING'
             shutdowner.A('stop', "exit")
         elif (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doDestroyMe(*args, **kwargs)
     #---READY---
     elif self.state == 'READY':
         if (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doDestroyMe(*args, **kwargs)
     #---STOPPING---
     elif self.state == 'STOPPING':
         if (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doUpdate(*args, **kwargs)
             self.doDestroyMe(*args, **kwargs)
     #---EXIT---
     elif self.state == 'EXIT':
         pass
     #---SERVICES---
     elif self.state == 'SERVICES':
         if event == 'init-services-done':
             self.state = 'MODULES'
             self.doInitModules(*args, **kwargs)
             shutdowner.A('ready')
         elif (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doDestroyMe(*args, **kwargs)
     #---INTERFACES---
     elif self.state == 'INTERFACES':
         if event == 'init-interfaces-done':
             self.state = 'SERVICES'
             self.doInitServices(*args, **kwargs)
         elif (event == 'shutdowner.state' and args[0] == 'FINISHED'):
             self.state = 'EXIT'
             self.doDestroyMe(*args, **kwargs)
     return None
Ejemplo n.º 9
0
 def _tray_control_func(cmd):
     if cmd == 'exit':
         from main import shutdowner
         shutdowner.A('stop', 'exit')