コード例 #1
0
ファイル: commander.py プロジェクト: cheuschober/deluge
    def exec_args(self,args,host,port,username,password):
        def on_connect(result):
            def on_started(result):
                def on_started(result):
                    deferreds = []
                    # If we have args, lets process them and quit
                    # allow multiple commands split by ";"
                    for arg in args.split(";"):
                        deferreds.append(defer.maybeDeferred(self.do_command, arg.strip()))

                    def on_complete(result):
                        self.do_command("quit")

                    dl = defer.DeferredList(deferreds).addCallback(on_complete)

                # We need to wait for the rpcs in start() to finish before processing
                # any of the commands.
                self.console.started_deferred.addCallback(on_started)
            component.start().addCallback(on_started)

        def on_connect_fail(reason):
            if reason.check(DelugeError):
                rm = reason.value.message
            else:
                rm = reason.getErrorMessage()
            print "Could not connect to: %s:%d\n %s"%(host,port,rm)
            self.do_command("quit")

        if host:
            d = client.connect(host,port,username,password)
        else:
            d = client.connect()
        d.addCallback(on_connect)
        d.addErrback(on_connect_fail)
コード例 #2
0
ファイル: test_client.py プロジェクト: deluge-torrent/deluge
 def test_connect_with_password(self):
     username, password = get_localhost_auth()
     yield client.connect('localhost', self.listen_port, username=username, password=password)
     yield client.core.create_account('testuser', 'testpw', 'DEFAULT')
     yield client.disconnect()
     ret = yield client.connect('localhost', self.listen_port, username='******', password='******')
     self.assertEqual(ret, AUTH_LEVEL_NORMAL)
     yield
コード例 #3
0
ファイル: dl_manager.py プロジェクト: TomT0m/SeriesPlay
	def connect(self):
		"""
		Connects with deluge server
		@returns a defered obj wich triggers when connected
		"""
		info("connect host={}, port={}".format(self.host, self.port))
		if self.host == None:
			self.defered_obj = client.connect()
		elif self.port != None:
			self.defered_obj = client.connect(port=self.port, host=self.host)
		else:
			self.defered_obj = client.connect(host=self.host)
		info("connecting request")	
		return self.defered_obj
コード例 #4
0
def filter_torrents(connection_data={},info_wanted=[],action=(lambda tid,tinfo: 'l'),interactive=True):
    """ Get all torrents and filter them
    Arguments:
    connection_data -- How to connect to the deluged daemon. Specify a dictionary of host, port(integer), username, password
    info_wanted -- A list of fields to be retrived for each torrent. You'll get it as a populated dictionary when action is called
    action -- function called for each torrent. Will get two variables - the torrent id and a populated dictionary of the torrent data. Should return a string indicating what to do with the torrent. Possible values:
        '':  Do nothing
        'd': Delete torrent (without deleting data)
        'D': Delete torrent WITH data
        'l': List torrent (display id and name)
        (Anything else): Causes an error.
        More things to come!
    interactive -- whether to write information / errors to output. Send False for cron jobs
    """
    # ensure 'name' is in torrent_info_wanted
    if 'name' not in info_wanted: info_wanted.append('name')
    # set parameters
    global cliconnect
    cliconnect = client.connect(**connection_data)
    global torrent_info_wanted
    torrent_info_wanted = info_wanted
    global torrentAction
    torrentAction = action
    if interactive:
        # create a handler equivalent to plain printing
        sh = logging.StreamHandler()
        sh.setFormatter(logging.Formatter("%(message)s"))
        log.addHandler(sh)
        log.setLevel(logging.INFO)
    else:
        # use parent loggers, or don't log at all
        log.addHandler(logging.NullHandler())
    # start the show
    cliconnect.addCallbacks(on_connect_success, endSession, errbackArgs=("Connection failed: check settings and try again."))
    reactor.run()
コード例 #5
0
    def register(self):
        c = client.connect()

        def on_connect_success(result):
            return "Heloooooooooooooo"

        c.addCallback(on_connect_success)
コード例 #6
0
ファイル: plugin_deluge.py プロジェクト: Anaerin/Flexget
        def connect(self, task, config):
            """Connects to the deluge daemon and runs on_connect_success """

            if config['host'] in ['localhost', '127.0.0.1'] and not config.get('user'):
                # If an user is not specified, we have to do a lookup for the localclient username/password
                auth = get_localhost_auth()
                if auth[0]:
                    config['user'], config['pass'] = auth
                else:
                    raise PluginError('Unable to get local authentication info for Deluge. '
                                      'You may need to specify an username and password from your Deluge auth file.')

            client.set_disconnect_callback(self.on_disconnect)

            d = client.connect(
                host=config['host'],
                port=config['port'],
                username=config['user'],
                password=config['pass'])

            d.addCallback(self.on_connect_success, task, config).addErrback(self.on_connect_fail)
            result = reactor.run()
            if isinstance(result, Exception):
                raise result
            return result
コード例 #7
0
    def connect_to_daemon(self):
        deferred = client.connect(**self.delugeConfig)

        deferred.addCallback(self.__on_connect_success)
        deferred.addErrback(self.__on_connect_fail)

        return deferred
コード例 #8
0
 def connect(self, host, autostart=False):
     if autostart and host[1] in ("127.0.0.1", "localhost"):
         if self.start_daemon(host):
             for try_counter in range(6, -1, -1):
                 try:
                     yield client.connect(*host[1:])
                     component.start()
                 except Exception:
                     log.exception("Connection to host failed.")
                     import time
                     time.sleep(0.5) # XXX: twisted timers anyone?
                     if try_counter:
                         log.info("Retrying connection.. Retries left: %s", try_counter)
     else:
         yield client.connect(*host[1:])
         component.start()
コード例 #9
0
ファイル: conkyDeluge.py プロジェクト: k2s/conkyDeluge
    def __init__(self, options):

        try:

            #disable all logging within Deluge functions, only output info from this script
            logging.disable(logging.FATAL)

            self.options = options
            self.torrents_status = []
            # sort out the server option
            self.options.server = self.options.server.replace(
                "localhost", "127.0.0.1")

            # create the rpc and client objects
            self.d = client.connect(self.options.server, self.options.port,
                                    self.options.username,
                                    self.options.password)

            # We add the callback to the Deferred object we got from connect()
            self.d.addCallback(self.on_connect_success)

            # We add the callback (in this case it's an errback, for error)
            self.d.addErrback(self.on_connect_fail)

            reactor.run()

        except Exception, e:
            self.logError("DelugeInfo Init:Unexpected error:" + e.__str__())
コード例 #10
0
ファイル: gtkui.py プロジェクト: pilluli/deluge
 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)
コード例 #11
0
    def connect_host(self, host_id):
        """Connect to host daemon"""
        for host_entry in self.config['hosts']:
            if host_entry[0] == host_id:
                __, host, port, username, password = host_entry
                return client.connect(host, port, username, password)

        return defer.fail(Exception('Bad host id'))
コード例 #12
0
ファイル: test_client.py プロジェクト: deluge-torrent/deluge
    def test_invalid_rpc_method_call(self):
        yield client.connect('localhost', self.listen_port, username='', password='')
        d = client.core.invalid_method()

        def on_failure(failure):
            self.assertEqual(failure.trap(error.WrappedException), error.WrappedException)
            self.addCleanup(client.disconnect)
        d.addCallbacks(self.fail, on_failure)
        yield d
コード例 #13
0
    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
コード例 #14
0
    def test_connect_no_credentials(self):
        d = client.connect('localhost', self.listen_port, username='', password='')

        def on_connect(result):
            self.assertEqual(client.get_auth_level(), AUTH_LEVEL_ADMIN)
            self.addCleanup(client.disconnect)
            return result

        d.addCallbacks(on_connect, self.fail)
        return d
コード例 #15
0
ファイル: test_client.py プロジェクト: deluge-torrent/deluge
    def test_connect_no_credentials(self):
        d = client.connect('localhost', self.listen_port, username='', password='')

        def on_connect(result):
            self.assertEqual(client.get_auth_level(), AUTH_LEVEL_ADMIN)
            self.addCleanup(client.disconnect)
            return result

        d.addCallbacks(on_connect, self.fail)
        return d
コード例 #16
0
def ConnectToDaemon():
	global delugeDaemon	
	host="localhost"
	port=58846
	user=""
	password=""
	client.set_disconnect_callback(daemon_disconnect_callback)
	if debugConnections:
		print "Connecting to deluge daemon..."
	delugeDaemon = client.connect(host, port, user, password)
コード例 #17
0
    def run(reactor, fn):
      global new_id

      log.info("should download " + str(fn))
      d = client.connect()
      reactor.resi = 5
      result = 5
      new_id = 5


      def on_set_1(new_id, result):
        c = client.core.set_torrent_move_completed(new_id, True)
        c.addCallback(lambda a:on_set_2(new_id, a))
        c.addErrback(on_add_fail)

      def on_set_2(new_id, result):
        client.disconnect()
        reactor.stop()
      

      def on_add_success(result):
        if not result:
          log.info("add torrent successful, was already enqueued")
          client.disconnect()
          reactor.stop()
        else:
          new_id = result
          c = client.core.set_torrent_move_completed_path(result, completed_dir)
          c.addCallback(lambda a: on_set_1(result, a))
          c.addErrback(on_add_fail)
          log.info("added new torrent: " + repr(result))
        new_id=None

      def on_add_fail(result):
        log.info("add torrent failed: " + repr(result) + str(result))
        client.disconnect()
        reactor.stop()

      def on_connect_success(result):
        log.info("connection successful: " + repr(result))
        c = client.core.add_torrent_magnet(fn, 
            {
              'download_location':download_dir,
              })

        c.addCallback(on_add_success)
        c.addErrback(on_add_fail)

      def on_connect_fail(result):
        log.info("connection fail: " + repr(result))
        reactor.stop()

      d.addCallback(on_connect_success)
      d.addErrback(on_connect_fail)
      return new_id
コード例 #18
0
    def test_connect_invalid_user(self):
        username, password = get_localhost_auth()
        d = client.connect('localhost', self.listen_port, username='******')

        def on_failure(failure):
            self.assertEqual(failure.trap(error.BadLoginError), error.BadLoginError)
            self.assertEqual(failure.value.message, 'Username does not exist')
            self.addCleanup(client.disconnect)

        d.addCallbacks(self.fail, on_failure)
        return d
コード例 #19
0
    def test_connect_no_credentials(self):

        d = client.connect("localhost", 58846)

        def on_failure(failure):
            self.assertEqual(failure.trap(error.AuthenticationRequired),
                             error.AuthenticationRequired)
            self.addCleanup(client.disconnect)

        d.addErrback(on_failure)
        return d
コード例 #20
0
        def run(reactor, fn):
            global new_id

            log.info("should download " + str(fn))
            d = client.connect()
            reactor.resi = 5
            result = 5
            new_id = 5

            def on_set_1(new_id, result):
                c = client.core.set_torrent_move_completed(new_id, True)
                c.addCallback(lambda a: on_set_2(new_id, a))
                c.addErrback(on_add_fail)

            def on_set_2(new_id, result):
                client.disconnect()
                reactor.stop()

            def on_add_success(result):
                if not result:
                    log.info("add torrent successful, was already enqueued")
                    client.disconnect()
                    reactor.stop()
                else:
                    new_id = result
                    c = client.core.set_torrent_move_completed_path(
                        result, completed_dir)
                    c.addCallback(lambda a: on_set_1(result, a))
                    c.addErrback(on_add_fail)
                    log.info("added new torrent: " + repr(result))
                new_id = None

            def on_add_fail(result):
                log.info("add torrent failed: " + repr(result) + str(result))
                client.disconnect()
                reactor.stop()

            def on_connect_success(result):
                log.info("connection successful: " + repr(result))
                c = client.core.add_torrent_magnet(
                    fn, {
                        'download_location': download_dir,
                    })

                c.addCallback(on_add_success)
                c.addErrback(on_add_fail)

            def on_connect_fail(result):
                log.info("connection fail: " + repr(result))
                reactor.stop()

            d.addCallback(on_connect_success)
            d.addErrback(on_connect_fail)
            return new_id
コード例 #21
0
    def exec_args(self, args, host, port, username, password):
        def on_connect(result):
            def on_started(result):
                def on_started(result):
                    deferreds = []
                    # If we have args, lets process them and quit
                    # allow multiple commands split by ";"
                    for arg in args.split(";"):
                        deferreds.append(
                            defer.maybeDeferred(self.do_command, arg.strip()))

                    def on_complete(result):
                        self.do_command("quit")

                    dl = defer.DeferredList(deferreds).addCallback(on_complete)

                # We need to wait for the rpcs in start() to finish before processing
                # any of the commands.
                self.console.started_deferred.addCallback(on_started)

            component.start().addCallback(on_started)

        def on_connect_fail(reason):
            if reason.check(DelugeError):
                rm = reason.value.message
            else:
                rm = reason.getErrorMessage()
            print "Could not connect to: %s:%d\n %s" % (host, port, rm)
            self.do_command("quit")

        if not username and host in ("127.0.0.1", "localhost"):
            # No username was provided and it's the localhost, so we can try
            # to grab the credentials from the auth file.
            from deluge.ui.common import get_localhost_auth
            username, password = get_localhost_auth()
        if host:
            d = client.connect(host, port, username, password)
        else:
            d = client.connect()
        d.addCallback(on_connect)
        d.addErrback(on_connect_fail)
コード例 #22
0
    def test_invalid_rpc_method_call(self):
        yield client.connect('localhost', self.listen_port, username='', password='')
        d = client.core.invalid_method()

        def on_failure(failure):
            self.assertEqual(
                failure.trap(error.WrappedException), error.WrappedException
            )
            self.addCleanup(client.disconnect)

        d.addCallbacks(self.fail, on_failure)
        yield d
コード例 #23
0
ファイル: test_client.py プロジェクト: zluca/deluge
    def test_connect_without_password(self):
        username, password = get_localhost_auth()
        d = client.connect('localhost', self.listen_port, username=username)

        def on_failure(failure):
            self.assertEqual(failure.trap(error.AuthenticationRequired),
                             error.AuthenticationRequired)
            self.assertEqual(failure.value.username, username)
            self.addCleanup(client.disconnect)

        d.addCallbacks(self.fail, on_failure)
        return d
コード例 #24
0
ファイル: connect.py プロジェクト: s0undt3ch/Deluge
        def do_connect():
            d = client.connect(host, port, username, password)
            def on_connect(result):
                self.console.write("{!success!}Connected to %s:%s!" % (host, port))
                component.start()

            def on_connect_fail(result):
                self.console.write("{!error!}Failed to connect to %s:%s with reason: %s" % (host, port, result.value.args[0]))

            d.addCallback(on_connect)
            d.addErrback(on_connect_fail)
            return d
コード例 #25
0
    def exec_args(self, options):
        """Execute console commands from command line."""
        from deluge.ui.console.cmdline.command import Commander
        commander = Commander(self._commands)

        def on_connect(result):
            def on_components_started(result):
                def on_started(result):
                    def do_command(result, cmd):
                        return commander.do_command(cmd)

                    def exec_command(result, cmd):
                        return commander.exec_command(cmd)

                    d = defer.succeed(None)
                    for command in options.parsed_cmds:
                        if command.command in ('quit', 'exit'):
                            break
                        d.addCallback(exec_command, command)
                    d.addCallback(do_command, 'quit')
                    return d

                # We need to wait for the rpcs in start() to finish before processing
                # any of the commands.
                self.started_deferred.addCallback(on_started)
                return self.started_deferred

            d = self.start_console()
            d.addCallback(on_components_started)
            return d

        def on_connect_fail(reason):
            if reason.check(DelugeError):
                rm = reason.getErrorMessage()
            else:
                rm = reason.value.message
            print('Could not connect to daemon: %s:%s\n %s' %
                  (options.daemon_addr, options.daemon_port, rm))
            commander.do_command('quit')

        d = None
        if not self.interactive and options.parsed_cmds[0].command == 'connect':
            d = commander.do_command(options.parsed_cmds.pop(0))
        else:
            log.info('connect: host=%s, port=%s, username=%s, password=%s',
                     options.daemon_addr, options.daemon_port,
                     options.daemon_user, options.daemon_pass)
            d = client.connect(options.daemon_addr, options.daemon_port,
                               options.daemon_user, options.daemon_pass)
        d.addCallback(on_connect)
        d.addErrback(on_connect_fail)
        return d
コード例 #26
0
    def test_connect_without_password(self):
        from deluge.ui import common
        username, password = common.get_localhost_auth()
        d = client.connect("localhost", 58846, username=username)

        def on_failure(failure):
            self.assertEqual(failure.trap(error.AuthenticationRequired),
                             error.AuthenticationRequired)
            self.assertEqual(failure.value.username, username)
            self.addCleanup(client.disconnect)

        d.addErrback(on_failure)
        return d
コード例 #27
0
ファイル: test_client.py プロジェクト: Ashod/Deluge
    def test_connect_no_credentials(self):

        d = client.connect("localhost", 58846)

        def on_failure(failure):
            self.assertEqual(
                failure.trap(error.AuthenticationRequired),
                error.AuthenticationRequired
            )
            self.addCleanup(client.disconnect)

        d.addErrback(on_failure)
        return d
コード例 #28
0
        def do_connect(result, username=None, password=None, *args):
            log.debug('Attempting to connect to daemon...')
            for host_entry in self.hostlist.config['hosts']:
                if host_entry[0] == host_id:
                    __, host, port, host_user, host_pass = host_entry

            username = username if username else host_user
            password = password if password else host_pass

            d = client.connect(host, port, username, password)
            d.addCallback(self._on_connect, host_id)
            d.addErrback(self._on_connect_fail, host_id, try_counter)
            return d
コード例 #29
0
    def test_connect_bad_password(self):
        username, password = get_localhost_auth()
        d = client.connect(
            'localhost', self.listen_port, username=username, password=password + '1'
        )

        def on_failure(failure):
            self.assertEqual(failure.trap(error.BadLoginError), error.BadLoginError)
            self.assertEqual(failure.value.message, 'Password does not match')
            self.addCleanup(client.disconnect)

        d.addCallbacks(self.fail, on_failure)
        return d
コード例 #30
0
        def do_connect(result, username=None, password=None, *args):
            log.debug('Attempting to connect to daemon...')
            for host_entry in self.hostlist.config['hosts']:
                if host_entry[0] == host_id:
                    __, host, port, host_user, host_pass = host_entry

            username = username if username else host_user
            password = password if password else host_pass

            d = client.connect(host, port, username, password)
            d.addCallback(self._on_connect, host_id)
            d.addErrback(self._on_connect_fail, host_id, try_counter)
            return d
コード例 #31
0
ファイル: test_client.py プロジェクト: Ashod/Deluge
    def test_connect_localclient(self):
        from deluge.ui import common
        username, password = common.get_localhost_auth()
        d = client.connect(
            "localhost", 58846, username=username, password=password
        )

        def on_connect(result):
            self.assertEqual(client.get_auth_level(), AUTH_LEVEL_ADMIN)
            self.addCleanup(client.disconnect)
            return result

        d.addCallback(on_connect)
        return d
コード例 #32
0
ファイル: test_client.py プロジェクト: deluge-torrent/deluge
    def test_connect_bad_password(self):
        username, password = get_localhost_auth()
        d = client.connect('localhost', self.listen_port, username=username, password=password + '1')

        def on_failure(failure):
            self.assertEqual(
                failure.trap(error.BadLoginError),
                error.BadLoginError
            )
            self.assertEqual(failure.value.message, 'Password does not match')
            self.addCleanup(client.disconnect)

        d.addCallbacks(self.fail, on_failure)
        return d
コード例 #33
0
ファイル: test_client.py プロジェクト: deluge-torrent/deluge
    def test_connect_invalid_user(self):
        username, password = get_localhost_auth()
        d = client.connect('localhost', self.listen_port, username='******')

        def on_failure(failure):
            self.assertEqual(
                failure.trap(error.BadLoginError),
                error.BadLoginError
            )
            self.assertEqual(failure.value.message, 'Username does not exist')
            self.addCleanup(client.disconnect)

        d.addCallbacks(self.fail, on_failure)
        return d
コード例 #34
0
ファイル: test_client.py プロジェクト: deluge-torrent/deluge
    def test_connect_without_password(self):
        username, password = get_localhost_auth()
        d = client.connect('localhost', self.listen_port, username=username)

        def on_failure(failure):
            self.assertEqual(
                failure.trap(error.AuthenticationRequired),
                error.AuthenticationRequired
            )
            self.assertEqual(failure.value.username, username)
            self.addCleanup(client.disconnect)

        d.addCallbacks(self.fail, on_failure)
        return d
コード例 #35
0
def tell_deluge_to(act):
    def on_connect_success(result):
        def disconnect(result):
            client.disconnect()
            reactor.crash()
        act().addCallback(disconnect)

    def on_connect_fail(result):
        print "Connection failed!"

    d = client.connect()
    d.addCallback(on_connect_success)
    d.addErrback(on_connect_fail)
    reactor.run()
コード例 #36
0
    def test_connect_bad_password(self):
        from deluge.ui import common
        username, password = common.get_localhost_auth()
        d = client.connect("localhost",
                           58846,
                           username=username,
                           password=password + '1')

        def on_failure(failure):
            self.assertEqual(failure.trap(error.BadLoginError),
                             error.BadLoginError)
            self.addCleanup(client.disconnect)

        d.addErrback(on_failure)
        return d
コード例 #37
0
    def test_connect_localclient(self):
        from deluge.ui import common
        username, password = common.get_localhost_auth()
        d = client.connect("localhost",
                           58846,
                           username=username,
                           password=password)

        def on_connect(result):
            self.assertEqual(client.get_auth_level(), AUTH_LEVEL_ADMIN)
            self.addCleanup(client.disconnect)
            return result

        d.addCallback(on_connect)
        return d
コード例 #38
0
ファイル: test_client.py プロジェクト: Ashod/Deluge
    def test_connect_bad_password(self):
        from deluge.ui import common
        username, password = common.get_localhost_auth()
        d = client.connect(
            "localhost", 58846, username=username, password=password+'1'
        )

        def on_failure(failure):
            self.assertEqual(
                failure.trap(error.BadLoginError),
                error.BadLoginError
            )
            self.addCleanup(client.disconnect)

        d.addErrback(on_failure)
        return d
コード例 #39
0
ファイル: connect.py プロジェクト: orther/Deluge
        def do_connect():
            d = client.connect(host, port, username, password)

            def on_connect(result):
                self.console.write("{!success!}Connected to %s:%s!" %
                                   (host, port))
                component.start()

            def on_connect_fail(result):
                self.console.write(
                    "{!error!}Failed to connect to %s:%s with reason: %s" %
                    (host, port, result.value.args[0]))

            d.addCallback(on_connect)
            d.addErrback(on_connect_fail)
            return d
コード例 #40
0
ファイル: main.py プロジェクト: deluge-torrent/deluge
    def exec_args(self, options):
        """Execute console commands from command line."""
        from deluge.ui.console.cmdline.command import Commander
        commander = Commander(self._commands)

        def on_connect(result):
            def on_components_started(result):
                def on_started(result):
                    def do_command(result, cmd):
                        return commander.do_command(cmd)

                    def exec_command(result, cmd):
                        return commander.exec_command(cmd)
                    d = defer.succeed(None)
                    for command in options.parsed_cmds:
                        if command.command in ('quit', 'exit'):
                            break
                        d.addCallback(exec_command, command)
                    d.addCallback(do_command, 'quit')
                    return d

                # We need to wait for the rpcs in start() to finish before processing
                # any of the commands.
                self.started_deferred.addCallback(on_started)
                return self.started_deferred
            d = self.start_console()
            d.addCallback(on_components_started)
            return d

        def on_connect_fail(reason):
            if reason.check(DelugeError):
                rm = reason.getErrorMessage()
            else:
                rm = reason.value.message
            print('Could not connect to daemon: %s:%s\n %s' % (options.daemon_addr, options.daemon_port, rm))
            commander.do_command('quit')

        d = None
        if not self.interactive and options.parsed_cmds[0].command == 'connect':
            d = commander.do_command(options.parsed_cmds.pop(0))
        else:
            log.info('connect: host=%s, port=%s, username=%s, password=%s',
                     options.daemon_addr, options.daemon_port, options.daemon_user, options.daemon_pass)
            d = client.connect(options.daemon_addr, options.daemon_port, options.daemon_user, options.daemon_pass)
        d.addCallback(on_connect)
        d.addErrback(on_connect_fail)
        return d
コード例 #41
0
ファイル: test_client.py プロジェクト: Ashod/Deluge
    def test_connect_without_password(self):
        from deluge.ui import common
        username, password = common.get_localhost_auth()
        d = client.connect(
            "localhost", 58846, username=username
        )

        def on_failure(failure):
            self.assertEqual(
                failure.trap(error.AuthenticationRequired),
                error.AuthenticationRequired
            )
            self.assertEqual(failure.value.username, username)
            self.addCleanup(client.disconnect)

        d.addErrback(on_failure)
        return d
コード例 #42
0
ファイル: connect.py プロジェクト: EiNSTeiN-/deluge-gtk3
        def do_connect():
            d = client.connect(host, port, username, password)
            def on_connect(result):
                if self.console.interactive:
                    self.console.write("{!success!}Connected to %s:%s" % (host, port))
                return component.start()

            def on_connect_fail(result):
                try:
                    msg = result.value.exception_msg
                except:
                    msg = result.value.args[0]
                self.console.write("{!error!}Failed to connect to %s:%s with reason: %s" % (host, port, msg))
                return result

            d.addCallback(on_connect)
            d.addErrback(on_connect_fail)
            return d
コード例 #43
0
ファイル: connect.py プロジェクト: deluge-torrent/deluge
        def do_connect():
            d = client.connect(host, port, options.username, options.password)

            def on_connect(result):
                if self.console.interactive:
                    self.console.write('{!success!}Connected to %s:%s!' % (host, port))
                return component.start()

            def on_connect_fail(result):
                try:
                    msg = result.value.exception_msg
                except AttributeError:
                    msg = result.value.message
                self.console.write('{!error!}Failed to connect to %s:%s with reason: %s' % (host, port, msg))
                return result

            d.addCallbacks(on_connect, on_connect_fail)
            return d
コード例 #44
0
def process_torrents():
 
    client_connected = False
 
    try:
        yield client.connect(host=deluge_host, username=deluge_username, password=deluge_password)
        client_connected = True
        log.info("Connected to deluge")
        torrents = yield client.core.get_torrents_status({}, ['name','label','progress','save_path','state','files'])
 
        downloads = [{
               'id' : id,
               'location' : torrent['save_path'] + '/' + torrent['name'],
               'label' : torrent['label']
            } for id, torrent in torrents.iteritems() if torrent['progress'] == 100 and torrent['label'].startswith('download')]
 
        log.info('List of torrents to download: %s', downloads)
 
        for torrent in downloads:
            log.info('Downloading torrent: %s', torrent)
 
            remote_location = torrent['location'].replace(' ', '\ ').replace('(', '\(').replace(')', '\)').replace('&', '\&').replace('[', '\[').replace(']', '\]').replace('\'', '\\\'')
            save_location = complete_dir + '/' + torrent['label']
 
            log.info('Remote location: %s', remote_location)
            log.info('Save location: %s', save_location)
 
            source = rsync_username + "@" + deluge_host + ":" + remote_location
            result = sshpass("-p", rsync_password, "rsync", "-hre", "ssh -o StrictHostKeyChecking=no", "-T", partial_dir, "--partial", "--progress", source, save_location)
            log.info('Got rsync result: %s', result)
            if (result.exit_code == 0):
                log.info('Remove label from torrent: %s', torrent)
                yield client.label.set_torrent(torrent['id'], 'No Label')
 
    except Exception as err:
        log.exception("Error downloading torrent")
 
    finally:
        if client_connected:
            log.info('Disconnecting deluge client')
            yield client.disconnect()
        log.info('Stopping reactor')
        reactor.stop()
コード例 #45
0
def filter_torrents(connection_data={},
                    info_wanted=[],
                    action=(lambda tid, tinfo: 'l'),
                    interactive=output):
    """ Get all torrents and filter them
    Arguments:
    connection_data -- How to connect to the deluged daemon. Specify a dictionary of host, port(integer), username, password
    info_wanted -- A list of fields to be retrived for each torrent. You'll get it as a populated dictionary when action is called
    action -- function called for each torrent. Will get two variables - the torrent id and a populated dictionary of the torrent data. Should return a string indicating what to do with the torrent. Possible values:
        '':  Do nothing
        'd': Delete torrent (without deleting data)
        'D': Delete torrent WITH data
        'l': List torrent (display id and name)
        (Anything else): Causes an error.
        More things to come!
    interactive -- whether to write information / errors to output. Send False for cron jobs
    """
    # ensure 'name' is in torrent_info_wanted
    if 'name' not in info_wanted: info_wanted.append('name')
    # set parameters
    global cliconnect
    cliconnect = client.connect(port=deluge_port)
    global torrent_info_wanted
    torrent_info_wanted = info_wanted
    global torrentAction
    torrentAction = action
    if interactive:
        # create a handler equivalent to plain printing
        sh = logging.StreamHandler()
        sh.setFormatter(logging.Formatter("%(message)s"))
        log.addHandler(sh)
        log.setLevel(logging.INFO)
    else:
        # use parent loggers, or don't log at all
        log.addHandler(logging.NullHandler())
    # start the show
    cliconnect.addCallbacks(
        on_connect_success,
        endSession,
        errbackArgs=("Connection failed: check settings and try again."))
    reactor.run()
コード例 #46
0
        def do_connect():
            d = client.connect(host, port, options.username, options.password)

            def on_connect(result):
                if self.console.interactive:
                    self.console.write('{!success!}Connected to %s:%s!' %
                                       (host, port))
                return component.start()

            def on_connect_fail(result):
                try:
                    msg = result.value.exception_msg
                except AttributeError:
                    msg = result.value.message
                self.console.write(
                    '{!error!}Failed to connect to %s:%s with reason: %s' %
                    (host, port, msg))
                return result

            d.addCallbacks(on_connect, on_connect_fail)
            return d
コード例 #47
0
ファイル: connect.py プロジェクト: Kash-Krishna/SharkByte
        def do_connect():
            d = client.connect(host, port, username, password)

            def on_connect(result):
                if self.console.interactive:
                    self.console.write("{!success!}Connected to %s:%s" %
                                       (host, port))
                return component.start()

            def on_connect_fail(result):
                try:
                    msg = result.value.exception_msg
                except:
                    msg = result.value.args[0]
                self.console.write(
                    "{!error!}Failed to connect to %s:%s with reason: %s" %
                    (host, port, msg))
                return result

            d.addCallback(on_connect)
            d.addErrback(on_connect_fail)
            return d
コード例 #48
0
ファイル: connectionmanager.py プロジェクト: malwinMP/deluge
 def do_retry_connect(try_counter):
     log.debug("user: %s pass: %s", user, password)
     d = client.connect(host, port, user, password)
     d.addCallback(self.__on_connected, host_id)
     d.addErrback(on_connect_fail, try_counter)
コード例 #49
0
ファイル: gtkui.py プロジェクト: EiNSTeiN-/deluge-gtk3
 def do_connect(try_counter):
     client.connect(
         *host[1:]).addCallback(on_connect).addErrback(
             on_connect_fail, try_counter)
コード例 #50
0
import sys
from deluge.ui.client import client
from twisted.internet import reactor

# Set up the logger to print out errors
from deluge.log import setupLogger
setupLogger()

# Deluge client
host=
port=
username=
password=

d = client.connect(host=host,port=port,username=username,password=password)

##################################################################
# FIND LABEL #####################################################
##################################################################

torrent_id = sys.argv[1]

def on_connect_success(result):
    def on_get_torrent_status(torrent):
        print torrent["label"]
        client.disconnect()
        reactor.stop()

    client.core.get_torrent_status(torrent_id, ["label"]).addCallback(on_get_torrent_status)
コード例 #51
0
 def do_connect(*args):
     d = client.connect(host, port, username, password, skip_authentication)
     d.addCallback(self.__on_connected, host_id)
     d.addErrback(self.__on_connected_failed, host_id, host, port,
                  username, password, try_counter)
     return d
コード例 #52
0
#!/usr/bin/python

from deluge.log import LOG as log
from deluge.ui.client import client
import deluge.component as component
from twisted.internet import reactor, defer
import time

cliconnect = client.connect()
is_interactive = True  # Set this to True to allow direct output or set to False for cron

status_keys = [
    "state", "save_path", "tracker", "tracker_status", "next_announce", "name",
    "total_size", "progress", "num_seeds", "total_seeds", "num_peers",
    "total_peers", "eta", "download_payload_rate", "upload_payload_rate",
    "ratio", "distributed_copies", "num_pieces", "piece_length", "total_done",
    "files", "file_priorities", "file_progress", "peers", "is_seed",
    "is_finished", "active_time", "seeding_time"
]

count = 0
torrent_ids = []


def printSuccess(dresult, is_success, smsg):
    global is_interactive
    if is_interactive:
        if is_success:
            print "[+]", smsg
        else:
            print "[i]", smsg
コード例 #53
0
ファイル: connectionmanager.py プロジェクト: malwinMP/deluge
 def do_connect(*args):
     client.connect(host, port, user, password).addCallback(self.__on_connected, host_id)
コード例 #54
0
minseedtime = 24  # Minimum seeding time (in hours)
src = home_dir + "/scripts/"  # Where is rtorrent_fast_resume.pl kept?
state_folder = home_dir + "/.config/deluge/state/"  # Link to deluge's state folder
watch_folder = home_dir + "/watch/"  # Link to rTorrent's watch folder
deluge_port = 12345  # Deluge Port. Found under "Remote client access" section in UCP
deluge_user = "******"  # Deluge Username. Found under "Remote client access" section in UCP
deluge_pass = "******"  # Deluge Password. Found under "Remote client access" section in UCP

#######################################################
# Execute
#######################################################
oldcount = 0
skipcount = 0
errorcount = 0
torrent_ids = []
cliconnect = client.connect(host_ip, deluge_port, deluge_user, deluge_pass)


def printSuccess(dresult, is_success, smsg):
    global is_interactive
    if is_interactive:
        if is_success:
            print "[+]", smsg
        else:
            print "[i]", smsg


def printError(emsg):
    global is_interactive
    if is_interactive:
        print "[e]", emsg
コード例 #55
0
 def connect_client(self, *args, **kwargs):
     return client.connect('localhost',
                           self.listen_port,
                           username=kwargs.get('user', ''),
                           password=kwargs.get('password', ''))
コード例 #56
0
 def tryConnect(self):
     self.dc = client.connect()
     self.dc.addCallback(self.onConnected)
     self.dc.addErrback(self.onConnectionFailure)
     reactor.run(installSignalHandlers=0)
コード例 #57
0
#!/usr/bin/python

import sys
from deluge.ui.client import client
from twisted.internet import reactor
from pprint import pprint

# Set up the logger to print out errors
from deluge.log import setupLogger
setupLogger()


d = client.connect()

torrent_id = sys.argv[1]

def on_connect_success(result):
    def on_get_torrent_status(torrent):
        try:
            print torrent['label']
        except KeyError:
            print ""
        client.disconnect()
        reactor.stop()

    client.core.get_torrent_status(torrent_id, ["label"]).addCallback(on_get_torrent_status)

d.addCallback(on_connect_success)

def on_connect_fail(result):
        print result