Example #1
0
    def __start_non_classic(self):
        # Autoconnect to a host
        if self.config["autoconnect"]:
            for host in self.connectionmanager.config["hosts"]:
                if host[0] == self.config["autoconnect_host_id"]:
                    try_connect = True
                    # Check to see if we need to start the localhost daemon
                    if self.config["autostart_localhost"] and host[1] in (
                            "localhost", "127.0.0.1"):
                        log.debug("Autostarting localhost:%s", host[2])
                        try_connect = client.start_daemon(
                            host[2], deluge.configmanager.get_config_dir())
                        log.debug("Localhost started: %s", try_connect)
                        if not try_connect:
                            dialogs.ErrorDialog(
                                _("Error Starting Daemon"),
                                _("There was an error starting the daemon process.  Try running it from a console to see if there is an error."
                                  )).run()

                    def on_connect(connector):
                        component.start()

                    def on_connect_fail(result, try_counter):
                        log.info("Connection to host failed..")
                        # We failed connecting to the daemon, but lets try again
                        if try_counter:
                            log.info("Retrying connection.. Retries left: %s",
                                     try_counter)
                            try_counter -= 1
                            import time
                            time.sleep(0.5)
                            do_connect(try_counter)
                        return

                    def do_connect(try_counter):
                        client.connect(
                            *host[1:]).addCallback(on_connect).addErrback(
                                on_connect_fail, try_counter)

                    if try_connect:
                        do_connect(6)
                    break

        if self.config["show_connection_manager_on_start"]:
            # XXX: We need to call a simulate() here, but this could be a bug in twisted
            try:
                reactor._simulate()
            except AttributeError:
                # twisted < 12
                reactor.simulate()
            self.connectionmanager.show()
Example #2
0
    def start_daemon(self, port, config):
        """
        Attempts to start a daemon process and will show an ErrorDialog if unable
        to.
        """
        try:
            return client.start_daemon(port, config)
        except OSError, e:
            from errno import ENOENT
            if e.errno == ENOENT:
                dialogs.ErrorDialog(
                    _("Unable to start daemon!"),
                    _("Deluge cannot find the 'deluged' executable, it is likely \
that you forgot to install the deluged package or it's not in your PATH.")).run()
            else:
                raise e
Example #3
0
    def __start_non_classic(self):
            # Autoconnect to a host
            if self.config["autoconnect"]:
                for host in self.connectionmanager.config["hosts"]:
                    if host[0] == self.config["autoconnect_host_id"]:
                        try_connect = True
                        # Check to see if we need to start the localhost daemon
                        if self.config["autostart_localhost"] and host[1] in ("localhost", "127.0.0.1"):
                            log.debug("Autostarting localhost:%s", host[2])
                            try_connect = client.start_daemon(host[2], deluge.configmanager.get_config_dir())
                            log.debug("Localhost started: %s", try_connect)
                            if not try_connect:
                                dialogs.ErrorDialog(
                                    _("Error Starting Daemon"),
                                    _("There was an error starting the daemon process.  Try running it from a console to see if there is an error.")).run()

                        def on_connect(connector):
                            component.start()
                        def on_connect_fail(result, try_counter):
                            log.info("Connection to host failed..")
                            # We failed connecting to the daemon, but lets try again
                            if try_counter:
                                log.info("Retrying connection.. Retries left: %s", try_counter)
                                try_counter -= 1
                                import time
                                time.sleep(0.5)
                                do_connect(try_counter)
                            return

                        def do_connect(try_counter):
                            client.connect(*host[1:]).addCallback(on_connect).addErrback(on_connect_fail, try_counter)

                        if try_connect:
                            do_connect(6)
                        break

            if self.config["show_connection_manager_on_start"]:
                # XXX: We need to call a simulate() here, but this could be a bug in twisted
                try:
                    reactor._simulate()
                except AttributeError:
                    # twisted < 12
                    reactor.simulate()
                self.connectionmanager.show()
    def start_daemon(self, port, config):
        """Attempts to start local daemon process and will show an ErrorDialog if not.

        Args:
            port (int): Port for the daemon to listen on.
            config (str): Config path to pass to daemon.

        Returns:
            bool: True is successfully started the daemon, False otherwise.

        """
        if client.start_daemon(port, config):
            log.debug('Localhost daemon started')
            reactor.callLater(1, self._update_host_status)
            return True
        else:
            ErrorDialog(
                _('Unable to start daemon!'),
                _('Check deluged package is installed and logs for further details')).run()
            return False
Example #5
0
    def start_daemon(self, port, config):
        """Attempts to start local daemon process and will show an ErrorDialog if not.

        Args:
            port (int): Port for the daemon to listen on.
            config (str): Config path to pass to daemon.

        Returns:
            bool: True is successfully started the daemon, False otherwise.

        """
        if client.start_daemon(port, config):
            log.debug('Localhost daemon started')
            reactor.callLater(1, self._update_host_status)
            return True
        else:
            ErrorDialog(
                _('Unable to start daemon!'),
                _('Check deluged package is installed and logs for further details'
                  )).run()
            return False
Example #6
0
 def start_daemon(self, host):
     try:
         if client.start_daemon(host[2], configmanager.get_config_dir()):
             return True
         else:
             QtGui.QMessageBox.critical(None,
                                        _("Error Starting Daemon"),
                                        _("There was an error starting the daemon process.  Try running it from a console to see if there is an error."))
     except Exception, e:
         if isinstance(e, OSError) and e.errno == 2:
             QtGui.QMessageBox.critical(None,
                                        _("Unable to start daemon!"),
                                        _("Deluge cannot find the 'deluged' executable, it is likely that you forgot to install the deluged package or it's not in your PATH."))
         else:
             import traceback
             QtGui.QMessageBox(QtGui.QMessageBox.Critical,
                               _("Unable to start daemon!"),
                               _("Please examine the details for more information."),
                               QtGui.QMessageBox.Ok,
                               None,
                               detailedText=traceback.format_exc()).exec_()
Example #7
0
 def start_daemon(self, port):
     """
     Starts a local daemon.
     """
     client.start_daemon(port, get_config_dir())
Example #8
0
    def __start_non_classic(self):
        # Autoconnect to a host
        if self.config["autoconnect"]:

            def update_connection_manager():
                if not self.connectionmanager.running:
                    return
                self.connectionmanager.glade.get_widget("button_refresh").emit(
                    "clicked")

            def close_connection_manager():
                if not self.connectionmanager.running:
                    return
                self.connectionmanager.glade.get_widget("button_close").emit(
                    "clicked")

            for host_config in self.connectionmanager.config["hosts"]:
                hostid, host, port, user, passwd = host_config
                if hostid == self.config["autoconnect_host_id"]:
                    try_connect = True
                    # Check to see if we need to start the localhost daemon
                    if self.config["autostart_localhost"] and host in (
                            "localhost", "127.0.0.1"):
                        log.debug("Autostarting localhost:%s", host)
                        try_connect = client.start_daemon(
                            port, deluge.configmanager.get_config_dir())
                        log.debug("Localhost started: %s", try_connect)
                        if not try_connect:
                            dialogs.ErrorDialog(
                                _("Error Starting Daemon"),
                                _("There was an error starting the daemon "
                                  "process.  Try running it from a console "
                                  "to see if there is an error.")).run()

                        # Daemon Started, let's update it's info
                        reactor.callLater(0.5, update_connection_manager)

                    def on_connect(connector):
                        component.start()
                        reactor.callLater(0.2, update_connection_manager)
                        reactor.callLater(0.5, close_connection_manager)

                    def on_connect_fail(reason, try_counter, host, port, user,
                                        passwd):
                        if not try_counter:
                            return

                        if reason.check(deluge.error.AuthenticationRequired,
                                        deluge.error.BadLoginError):
                            log.debug("PasswordRequired exception")
                            dialog = dialogs.AuthenticationDialog(
                                reason.value.message, reason.value.username)

                            def dialog_finished(response_id, host, port):
                                if response_id == gtk.RESPONSE_OK:
                                    reactor.callLater(0.5, do_connect,
                                                      try_counter - 1, host,
                                                      port,
                                                      dialog.get_username(),
                                                      dialog.get_password())

                            dialog.run().addCallback(dialog_finished, host,
                                                     port)
                            return

                        log.error("Connection to host failed..")
                        log.info("Retrying connection.. Retries left: "
                                 "%s", try_counter)
                        reactor.callLater(0.5, update_connection_manager)
                        reactor.callLater(0.5, do_connect, try_counter - 1,
                                          host, port, user, passwd)

                    def do_connect(try_counter, host, port, user, passwd):
                        log.debug("Trying to connect to %s@%s:%s", user, host,
                                  port)
                        d = client.connect(host, port, user, passwd)
                        d.addCallback(on_connect)
                        d.addErrback(on_connect_fail, try_counter, host, port,
                                     user, passwd)

                    if try_connect:
                        reactor.callLater(0.5, do_connect, 6, host, port, user,
                                          passwd)
                    break

        if self.config["show_connection_manager_on_start"]:
            # XXX: We need to call a simulate() here, but this could be a bug in twisted
            reactor.simulate()
            self.connectionmanager.show()
Example #9
0
    def __start_non_classic(self):
            # Autoconnect to a host
            if self.config["autoconnect"]:

                def update_connection_manager():
                    if not self.connectionmanager.running:
                        return
                    self.connectionmanager.builder.get_object("button_refresh").emit("clicked")

                def close_connection_manager():
                    if not self.connectionmanager.running:
                        return
                    self.connectionmanager.builder.get_object("button_close").emit("clicked")

                for host_config in self.connectionmanager.config["hosts"]:
                    hostid, host, port, user, passwd = host_config
                    if hostid == self.config["autoconnect_host_id"]:
                        try_connect = True
                        # Check to see if we need to start the localhost daemon
                        if self.config["autostart_localhost"] and host in ("localhost", "127.0.0.1"):
                            log.debug("Autostarting localhost:%s", host)
                            try_connect = client.start_daemon(
                                port, deluge.configmanager.get_config_dir()
                            )
                            log.debug("Localhost started: %s", try_connect)
                            if not try_connect:
                                dialogs.ErrorDialog(
                                    _("Error Starting Daemon"),
                                    _("There was an error starting the daemon "
                                      "process.  Try running it from a console "
                                      "to see if there is an error.")
                                ).run()

                            # Daemon Started, let's update it's info
                            reactor.callLater(0.5, update_connection_manager)

                        def on_connect(connector):
                            component.start()
                            reactor.callLater(0.2, update_connection_manager)
                            reactor.callLater(0.5, close_connection_manager)

                        def on_connect_fail(reason, try_counter,
                                            host, port, user, passwd):
                            if not try_counter:
                                return

                            if reason.check(deluge.error.AuthenticationRequired,
                                            deluge.error.BadLoginError):
                                log.debug("PasswordRequired exception")
                                dialog = dialogs.AuthenticationDialog(
                                    reason.value.message, reason.value.username
                                )
                                def dialog_finished(response_id, host, port):
                                    if response_id == gtk.RESPONSE_OK:
                                        reactor.callLater(
                                            0.5, do_connect, try_counter-1,
                                            host, port, dialog.get_username(),
                                            dialog.get_password())
                                dialog.run().addCallback(dialog_finished,
                                                         host, port)
                                return

                            log.info("Connection to host failed..")
                            log.info("Retrying connection.. Retries left: "
                                     "%s", try_counter)
                            reactor.callLater(0.5, update_connection_manager)
                            reactor.callLater(0.5, do_connect, try_counter-1,
                                              host, port, user, passwd)

                        def do_connect(try_counter, host, port, user, passwd):
                            log.debug("Trying to connect to %s@%s:%s",
                                      user, host, port)
                            d = client.connect(host, port, user, passwd)
                            d.addCallback(on_connect)
                            d.addErrback(on_connect_fail, try_counter,
                                         host, port, user, passwd)

                        if try_connect:
                            reactor.callLater(
                                0.5, do_connect, 6, host, port, user, passwd
                            )
                        break

            if self.config["show_connection_manager_on_start"]:
                # XXX: We need to call a simulate() here, but this could be a bug in twisted
                try:
                    reactor._simulate()
                except AttributeError:
                    # twisted < 12
                    reactor.simulate()
                self.connectionmanager.show()
Example #10
0
import tempfile
import os
import signal

import common

from twisted.trial import unittest

from deluge.ui.client import client

# Start a daemon to test with and wait a couple seconds to make sure it's started
config_directory = common.set_tmp_config_dir()
client.start_daemon(58847, config_directory)
import time
time.sleep(2)


class ClientTestCase(unittest.TestCase):
    def test_connect_no_credentials(self):
        d = client.connect("localhost", 58847)
        d.addCallback(self.assertEquals, 10)

        def on_connect(result):
            self.addCleanup(client.disconnect)
            return result
        d.addCallback(on_connect)
        return d
Example #11
0
 def start_daemon(self, port):
     """
     Starts a local daemon.
     """
     client.start_daemon(port, get_config_dir())