Ejemplo n.º 1
0
    def set_up(self):
        self.set_unittest_maxdiff(None)
        self.rpcserver = RPCServer(listen=False)
        self.rpcserver.factory.protocol = DelugeRPCProtocolTester

        self.factory = self.rpcserver.factory
        self.session_id = '0'
        self.request_id = 11
        self.protocol = self.rpcserver.factory.protocol(self.session_id)
        self.protocol.factory = self.factory
        self.factory.session_protocols[self.session_id] = self.protocol
        self.factory.interested_events[self.session_id] = [
            'TorrentFolderRenamedEvent'
        ]
        self.protocol.sessionno = self.session_id
        self.factory.authorized_sessions[
            self.session_id] = self.protocol.AuthLevel(
                rpcserver.AUTH_LEVEL_DEFAULT, '')

        self.config = test_common.get_test_config()
        self.core = Core("test")
        # Must call enable to create the RSSFeedScheduler in core
        self.core.enable(config=self.config)
        self.rpcserver.register_object(self.core)
        return component.start()
Ejemplo n.º 2
0
 def set_up(self):
     self.setup_config()
     RPCServer(listen=False)
     self.core = Core()
     self.session = lt.session()
     self.torrent = None
     return component.start()
Ejemplo n.º 3
0
    def __init__(self,
                 listen_interface=None,
                 interface=None,
                 port=None,
                 standalone=False,
                 read_only_config_keys=None):
        """
        Args:
            listen_interface (str, optional): The IP address to listen to bittorrent connections on.
            interface (str, optional): The IP address the daemon will listen for UI connections on.
            port (int, optional): The port the daemon will listen for UI connections on.
            standalone (bool, optional): If True the client is in Standalone mode otherwise, if
                False, start the daemon as separate process.
            read_only_config_keys (list of str, optional): A list of config keys that will not be
                altered by core.set_config() RPC method.
        """
        self.standalone = standalone
        self.pid_file = get_config_dir('deluged.pid')
        log.info('Deluge daemon %s', get_version())
        if is_daemon_running(self.pid_file):
            raise DaemonRunningError(
                'Deluge daemon already running with this config directory!')

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

        # Catch some Windows specific signals
        if windows_check():

            def win_handler(ctrl_type):
                """Handle the Windows shutdown or close events."""
                log.debug('windows handler ctrl_type: %s', ctrl_type)
                if ctrl_type == CTRL_CLOSE_EVENT or ctrl_type == CTRL_SHUTDOWN_EVENT:
                    self._shutdown()
                    return 1

            SetConsoleCtrlHandler(win_handler)

        # Start the core as a thread and join it until it's done
        self.core = Core(listen_interface=listen_interface,
                         read_only_config_keys=read_only_config_keys)

        if port is None:
            port = self.core.config['daemon_port']
        self.port = port

        if interface and not is_ip(interface):
            log.error('Invalid UI interface (must be IP Address): %s',
                      interface)
            interface = None

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

        log.debug('Listening to UI on: %s:%s and bittorrent on: %s', interface,
                  port, listen_interface)
Ejemplo n.º 4
0
 def set_up(self):
     common.set_tmp_config_dir()
     self.rpcserver = RPCServer(listen=False)
     self.core = Core()
     self.core.config.config['lsd'] = False
     self.clock = task.Clock()
     self.tm = self.core.torrentmanager
     self.tm.callLater = self.clock.callLater
     return component.start()
Ejemplo n.º 5
0
 def set_up(self):
     common.set_tmp_config_dir()
     self.rpcserver = RPCServer(listen=False)
     self.core = Core()
     self.core.config.config['lsd'] = False
     self.clock = task.Clock()
     self.core.torrentmanager.callLater = self.clock.callLater
     self.listen_port = 51242
     return component.start().addCallback(self.start_web_server)
Ejemplo n.º 6
0
 def set_up(self):
     self.setup_config()
     self.rpcserver = RPCServer(listen=False)
     self.core = Core()
     self.core.config.config['lsd'] = False
     self.core.config.config['new_release_check'] = False
     self.session = self.core.session
     self.torrent = None
     return component.start()
Ejemplo n.º 7
0
 def setUp(self):
     self.setup_config()
     global rpcserver
     global core
     rpcserver = RPCServer(listen=False)
     core = Core()
     self.session = lt.session()
     self.torrent = None
     return component.start()
Ejemplo n.º 8
0
 def set_up(self):
     self.rpcserver = RPCServer(listen=False)
     self.rpcserver.factory.protocol = DelugeRPCProtocolTester
     self.factory = self.rpcserver.factory
     self.session_id = '0'
     self.request_id = 11
     self.protocol = self.rpcserver.factory.protocol()
     self.protocol.factory = self.factory
     self.protocol.transport = self.protocol
     self.factory.session_protocols[self.session_id] = self.protocol
     self.factory.authorized_sessions[self.session_id] = None
     self.factory.interested_events[self.session_id] = ['TorrentFolderRenamedEvent']
     self.protocol.sessionno = self.session_id
     return component.start()
Ejemplo n.º 9
0
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():
                    import win32process
                    return pid in win32process.EnumProcesses()
                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
        try:
            locale.setlocale(locale.LC_ALL, '')
            if hasattr(locale, "bindtextdomain"):
                locale.bindtextdomain(
                    "deluge",
                    pkg_resources.resource_filename("deluge", "i18n"))
            if hasattr(locale, "textdomain"):
                locale.textdomain("deluge")
            gettext.bindtextdomain(
                "deluge", pkg_resources.resource_filename("deluge", "i18n"))
            gettext.textdomain("deluge")
            gettext.install("deluge",
                            pkg_resources.resource_filename("deluge", "i18n"))
        except Exception, e:
            log.error("Unable to initialize gettext/locale: %s", e)
            import __builtin__
            __builtin__.__dict__["_"] = lambda x: x

        # Twisted catches signals to terminate, so just have it call the shutdown
        # method.
        reactor.addSystemEventTrigger("before", "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)

        if options and options.listen_interface:
            listen_interface = options.listen_interface
        else:
            listen_interface = ""

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

        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()
Ejemplo n.º 10
0
    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()
Ejemplo n.º 11
0
 def setUp(self):
     common.set_tmp_config_dir()
     self.rpcserver = RPCServer(listen=False)
     self.core = Core()
     d = component.start()
     return d
Ejemplo n.º 12
0
 def setUp(self):
     common.set_tmp_config_dir()
     self.rpcserver = RPCServer(listen=False)
     self.core = Core()
     return component.start().addCallback(self.startWebserver)
Ejemplo n.º 13
0
 def set_up(self):
     common.set_tmp_config_dir()
     self.rpcserver = RPCServer(listen=False)
     self.core = Core()
     self.listen_port = 51242
     return component.start().addCallback(self.start_web_server)
Ejemplo n.º 14
0
 def set_up(self):
     common.set_tmp_config_dir()
     RPCServer(listen=False)
     self.core = Core()
     return component.start()