예제 #1
0
파일: qtui.py 프로젝트: marscher/deluge_qt
    def on_quit(self):
        # Note: Qt docs advise to do cleanup in aboutToQuit(),
        # because is some cases exec_ is not guaranteed to return.
        from deluge import component

        component.stop()
        component.shutdown()

        self.ui_config.save()
예제 #2
0
파일: qtui.py 프로젝트: s0undt3ch/deluge_qt
    def on_quit(self):
        # Note: Qt docs advise to do cleanup in aboutToQuit(),
        # because is some cases exec_ is not guaranteed to return.
        from deluge import component

        component.stop()
        component.shutdown()

        self.ui_config.save()
예제 #3
0
파일: gtkui.py 프로젝트: Aniverse/deluge-1
    def shutdown(self, *args, **kwargs):
        log.debug("gtkui shutting down..")

        component.stop()

        # Process any pending gtk events since the mainloop has been quit
        while gtk.events_pending():
            gtk.main_iteration(0)

        # Shutdown all components
        component.shutdown()

        # Make sure the config is saved.
        self.config.save()
예제 #4
0
파일: gtkui.py 프로젝트: Ashod/Deluge
    def shutdown(self, *args, **kwargs):
        log.debug("gtkui shutting down..")

        component.stop()

        # Process any pending gtk events since the mainloop has been quit
        while gtk.events_pending():
            gtk.main_iteration(0)

        # Shutdown all components
        component.shutdown()

        # Make sure the config is saved.
        self.config.save()
예제 #5
0
    def shutdown(self, *args, **kwargs):
        log.debug("gtkui shutting down..")

        component.stop()

        # Process any pending gtk events since the mainloop has been quit
        if not deluge.common.windows_check() and not deluge.common.osx_check():
            while events_pending() and reactor.running:
                reactor.doIteration(0)

        # Shutdown all components
        component.shutdown()

        # Make sure the config is saved.
        self.config.save()
예제 #6
0
파일: gtkui.py 프로젝트: laanwj/deluge
    def shutdown(self, *args, **kwargs):
        log.debug("gtkui shutting down..")

        component.stop()

        # Process any pending gtk events since the mainloop has been quit
        if not deluge.common.windows_check() and not deluge.common.osx_check():
            while gtk.events_pending() and reactor.running:
                reactor.doIteration(0)

        # Shutdown all components
        component.shutdown()

        # Make sure the config is saved.
        self.config.save()
예제 #7
0
    def tearDown(self):  # NOQA
        client._daemon_proxy = None
        client.__started_standalone = False

        def on_shutdown(result):
            component._ComponentRegistry.components = {}
        return component.shutdown().addCallback(on_shutdown)
예제 #8
0
    def tearDown(self):  # NOQA
        def on_shutdown(result):
            # Components aren't removed from registry in component.shutdown...
            # so must do that manually
            component._ComponentRegistry.components = {}

        return component.shutdown().addCallback(on_shutdown)
예제 #9
0
    def tearDown(self):
        def on_shutdown(result):
            component._ComponentRegistry.components = {}
            del self.am
            del self.core

        return component.shutdown().addCallback(on_shutdown)
예제 #10
0
    def tearDown(self):
        def on_shutdown(result):
            component._ComponentRegistry.components = {}
            del self.am
            del self.core

        return component.shutdown().addCallback(on_shutdown)
예제 #11
0
    def tear_down(self):
        def on_shutdown(result):
            del self.rpcserver
            del self.core
            return self.webserver.stopListening()

        return component.shutdown().addCallback(on_shutdown)
 def tearDown(self):
     d = component.shutdown()
     # Components aren't removed from registry in component.shutdown...
     # so must do that manually
     for c_name in component._ComponentRegistry.components.keys():
         del component._ComponentRegistry.components[c_name]
     return d
예제 #13
0
    def tearDown(self):
        if self.torrent:
            self.torrent.prev_status_cleanup_loop.stop()

        def on_shutdown(result):
            component._ComponentRegistry.components = {}
        return component.shutdown().addCallback(on_shutdown)
예제 #14
0
    def tear_down(self):

        def on_shutdown(result):
            del self.rpcserver
            del self.core
            return self.webserver.stopListening()

        return component.shutdown().addCallback(on_shutdown)
예제 #15
0
    def tearDown(self):
        if self.torrent:
            self.torrent.prev_status_cleanup_loop.stop()

        def on_shutdown(result):
            component._ComponentRegistry.components = {}

        return component.shutdown().addCallback(on_shutdown)
    def tearDown(self):  # NOQA
        def on_shutdown(result):
            # Components aren't removed from registry in component.shutdown
            # so must do that manually
            component._ComponentRegistry.components = {}
            if getattr(self, 'patch_component_start', False) is True:
                self.component_start_patcher.stop()

        return component.shutdown().addCallback(on_shutdown)
예제 #17
0
def started_deluge_client(tmpdir):
    # Set Up
    standalone_client = Client()

    if len(component._ComponentRegistry.components) != 0:
        warnings.warn("The component._ComponentRegistry.components"
                      " is not empty on test setup.\n"
                      "This is probably caused by another test"
                      " that did not clean up after finishing!:"
                      f" {component._ComponentRegistry.components}")

    configmanager.set_config_dir(tmpdir)
    standalone_client.start_standalone()

    pytest_twisted.blockon(component.start())
    yield standalone_client

    # Tear Down
    pytest_twisted.blockon(standalone_client.disconnect())
    pytest_twisted.blockon(component.shutdown())

    # There can be KeyErrors after pytest run about RPCServer
    # This errors are happening because of the next clear()
    #
    # It is so because plugins objects (that are based on CorePluginBase)
    # are still stored inside RPCServer's factory.methods
    # When RPCServer object is destroyed, it's dicts are cleared as well
    # That's when CorePluginBase.__del__ is called
    # And it tries to obtain RPCServer object from a list of components,
    # but this object already excluded from the list, so it fails to
    # deregister itself from RPCServer's dicts.
    #
    # Moreover, calling RPCServer's deregister_object is of no use, because:
    # def deregister_object(self, obj):
    #     """
    #     Deregisters an objects exported rpc methods.
    #
    #     :param obj: the object that was previously registered
    #
    #     """
    # >       for key, value in self.factory.methods.items():
    #             if value.__self__ == obj:
    #                 del self.factory.methods[key]
    # E       RuntimeError: dictionary changed size during iteration

    component._ComponentRegistry.components.clear()
    component._ComponentRegistry.dependents.clear()
예제 #18
0
파일: daemon.py 프로젝트: Aniverse/deluge-2
 def _shutdown(self, *args, **kwargs):
     log.info(
         'Deluge daemon shutting down, waiting for components to shutdown...'
     )
     if not self.standalone:
         return component.shutdown()
예제 #19
0
    def tear_down(self):
        def on_shutdown(result):
            del self.rpcserver
            del self.core

        return component.shutdown().addCallback(on_shutdown)
예제 #20
0
파일: daemon.py 프로젝트: laanwj/deluge
                    self._shutdown()

    @export()
    def shutdown(self, *args, **kwargs):
        reactor.callLater(0, reactor.stop)

    def _shutdown(self, *args, **kwargs):
        if os.path.exists(deluge.configmanager.get_config_dir("deluged.pid")):
            try:
                os.remove(deluge.configmanager.get_config_dir("deluged.pid"))
            except Exception, e:
                log.exception(e)
                log.error("Error removing deluged.pid!")

        log.info("Waiting for components to shutdown..")
        d = component.shutdown()
        return d

    @export()
    def info(self):
        """
        Returns some info from the daemon.

        :returns: str, the version number
        """
        return deluge.common.get_version()

    @export()
    def get_method_list(self):
        """
        Returns a list of the exported methods.
예제 #21
0
파일: daemon.py 프로젝트: malwinMP/deluge
                self._shutdown()

    @export()
    def shutdown(self, *args, **kwargs):
        reactor.callLater(0, reactor.stop)

    def _shutdown(self, *args, **kwargs):
        if os.path.exists(deluge.configmanager.get_config_dir("deluged.pid")):
            try:
                os.remove(deluge.configmanager.get_config_dir("deluged.pid"))
            except Exception, e:
                log.exception(e)
                log.error("Error removing deluged.pid!")

        log.info("Waiting for components to shutdown..")
        d = component.shutdown()
        return d

    @export()
    def info(self):
        """
        Returns some info from the daemon.

        :returns: str, the version number
        """
        return deluge.common.get_version()

    @export()
    def get_method_list(self):
        """
        Returns a list of the exported methods.
예제 #22
0
 def tear_down(self):
     def on_shutdown(result):
         del self.rpcserver
     return component.shutdown().addCallback(on_shutdown)
예제 #23
0
 def on_start(result, c1):
     d = component.shutdown()
     d.addCallback(on_shutdown, c1)
     return d
예제 #24
0
 def shutdown(self, *args, **kwargs):
     log.debug('GTKUI shutting down...')
     # Shutdown all components
     if client.is_standalone:
         return component.shutdown()
예제 #25
0
파일: gtkui.py 프로젝트: newfyle/deluge
 def shutdown(self, *args, **kwargs):
     log.debug('GTKUI shutting down...')
     # Shutdown all components
     if client.is_standalone:
         return component.shutdown()
예제 #26
0
 def tearDown(self):  # NOQA
     client._daemon_proxy = None
     client.__started_standalone = False
     return component.shutdown()
예제 #27
0
 def tear_down(self):
     # We must ensure that the components in component registry are removed
     return component.shutdown()
예제 #28
0
파일: daemon.py 프로젝트: orther/Deluge
class Daemon(object):
    def __init__(self, options=None, args=None, classic=False):
        # Check for another running instance of the daemon
        if os.path.isfile(deluge.configmanager.get_config_dir("deluged.pid")):
            # Get the PID and the port of the supposedly running daemon
            try:
                (pid, port) = open(
                    deluge.configmanager.get_config_dir(
                        "deluged.pid")).read().strip().split(";")
                pid = int(pid)
                port = int(port)
            except ValueError:
                pid = None
                port = None

            def process_running(pid):
                if deluge.common.windows_check():
                    # Do some fancy WMI junk to see if the PID exists in Windows
                    from win32com.client import GetObject

                    def get_proclist():
                        WMI = GetObject('winmgmts:')
                        processes = WMI.InstancesOf('Win32_Process')
                        return [
                            process.Properties_('ProcessID').Value
                            for process in processes
                        ]

                    return pid in get_proclist()
                else:
                    # We can just use os.kill on UNIX to test if the process is running
                    try:
                        os.kill(pid, 0)
                    except OSError:
                        return False
                    else:
                        return True

            if pid is not None and process_running(pid):
                # Ok, so a process is running with this PID, let's make doubly-sure
                # it's a deluged process by trying to open a socket to it's port.
                import socket
                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                try:
                    s.connect(("127.0.0.1", port))
                except socket.error:
                    # Can't connect, so it must not be a deluged process..
                    pass
                else:
                    # This is a deluged!
                    s.close()
                    raise deluge.error.DaemonRunningError(
                        "There is a deluge daemon running with this config "
                        "directory!")

        # Initialize gettext
        deluge.common.setup_translations()

        # Twisted catches signals to terminate, so just have it call the shutdown
        # method.
        reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)

        # Catch some Windows specific signals
        if deluge.common.windows_check():
            from win32api import SetConsoleCtrlHandler
            from win32con import CTRL_CLOSE_EVENT
            from win32con import CTRL_SHUTDOWN_EVENT

            def win_handler(ctrl_type):
                log.debug("ctrl_type: %s", ctrl_type)
                if ctrl_type == CTRL_CLOSE_EVENT or ctrl_type == CTRL_SHUTDOWN_EVENT:
                    self.__shutdown()
                    return 1

            SetConsoleCtrlHandler(win_handler)

        version = deluge.common.get_version()

        log.info("Deluge daemon %s", version)
        log.debug("options: %s", options)
        log.debug("args: %s", args)
        # Set the config directory
        if options and options.config:
            deluge.configmanager.set_config_dir(options.config)

        from deluge.core.core import Core
        # Start the core as a thread and join it until it's done
        self.core = Core()

        port = self.core.config["daemon_port"]
        if options and options.port:
            port = options.port
        if options and options.ui_interface:
            interface = options.ui_interface
        else:
            interface = ""

        self.rpcserver = RPCServer(
            port=port,
            allow_remote=self.core.config["allow_remote"],
            listen=not classic,
            interface=interface)

        # Register the daemon and the core RPCs
        self.rpcserver.register_object(self.core)
        self.rpcserver.register_object(self)

        # Make sure we start the PreferencesManager first
        component.start("PreferencesManager")

        if not classic:
            # Write out a pid file all the time, we use this to see if a deluged is running
            # We also include the running port number to do an additional test
            open(deluge.configmanager.get_config_dir("deluged.pid"),
                 "wb").write("%s;%s\n" % (os.getpid(), port))

            component.start()
            try:
                reactor.run()
            finally:
                self._shutdown()

    @export()
    def shutdown(self, *args, **kwargs):
        reactor.callLater(0, reactor.stop)

    def _shutdown(self, *args, **kwargs):
        try:
            os.remove(deluge.configmanager.get_config_dir("deluged.pid"))
        except Exception, e:
            log.exception(e)
            log.error("Error removing deluged.pid!")

        component.shutdown()
        try:
            reactor.stop()
        except twisted.internet.error.ReactorNotRunning:
            log.debug("Tried to stop the reactor but it is not running..")
예제 #29
0
 def tear_down(self):
     d = component.shutdown()
     d.addCallback(self.disconnect_client)
     d.addCallback(self.terminate_core)
     return d
예제 #30
0
 def tear_down(self):
     return component.shutdown()
예제 #31
0
 def tear_down(self):
     d = component.shutdown()
     d.addCallback(self.disconnect_client)
     d.addCallback(self.terminate_core)
     return d
예제 #32
0
 def tear_down(self):
     # We must ensure that the components in component registry are removed
     return component.shutdown()
예제 #33
0
파일: test_stats.py 프로젝트: th841/deluge
 def tear_down(self):
     client.stop_standalone()
     return component.shutdown()
예제 #34
0
 def on_start(result, c1):
     d = component.shutdown()
     d.addCallback(on_shutdown, c1)
     return d
예제 #35
0
 def _shutdown(self, *args, **kwargs):
     log.info('Deluge daemon shutting down, waiting for components to shutdown...')
     if not self.standalone:
         return component.shutdown()