Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#382 closed feature-request (Invalid)

Scheduler (was: dBus Interface)

Reported by: garett@… Owned by: andar
Priority: trivial Milestone:
Component: GTK UI Version: 1.1.0_dev
Keywords: Cc:

Description

The loss of the scheduler plugin (albeit it temporarily) has embolden me to ask for some more functionality in the dBus interface. At the moment, it appears I can pass command arguments, which isn't quite powerful enough for me.

What I'd like to do is be able to stop/start downloading by modifying the max_active_limit configuration through dBus. Basically what scheduler was doing, but something I can call through a program launched by cron. Something like:

bus = dbus.SessionBus()
proxy = bus.get_object('org.deluge_torrent.Deluge', '/org/deluge_torrent/Deluge')
ui = dbus.Interface(proxy, 'org.deluge_torrent.Deluge')
ui.setConfig('max_active_limit', 0)

and

ui.setConfig('max_active_limit', 10)

I'm not quite sure the code above would be the right way to talk to deluge through the dbus ... python is not my language and dbus is something very new to me (about 15 minutes new). If I'm understanding dbus correctly, I might just be able to use dbus_send to pass this information as well.

In any case, the scheduler plugin is a real pain to configure and not quite as flexible as cron would allow me to be. What I'd really like to control is the max_active_limit, but I figure it shouldn't require any more effort to expose the entire configuration, allowing others to do other things ... like between these hours, don't seed, etc.

Also, I noticed IPC is in there too for windows, it might be nice to expose it there as well.

Thanks.

Attachments (1)

deluge_config.py (3.8 KB) - added by garett@… 13 years ago.
Script to alter configuration settings on the deluge backend

Download all attachments as: .zip

Change History (12)

comment:1 Changed 13 years ago by andar

Dbus is simply used to check whether the gtkui is running and send arguments to it for adding torrents to a running deluge.. What you really want is to speak to the daemon through XMLRPC. This is actually pretty easy.

This page should help you out: http://dev.deluge-torrent.org/wiki/Development/UiClient

Basically, all you need to do is set the config value to what you want in the core. You probably will only need to use client.set_config().

comment:2 Changed 13 years ago by anonymous

  • Resolution set to invalid
  • Status changed from new to closed

:) Yes, very easy that way. Thank you.

For anyone interested:

#!/usr/bin/python
from deluge.ui.client import aclient as client

client.set_core_uri()
client.set_config({'max_active_limit': 10})
client.force_call()

And, of course, the reverse of it to turn it off. Thank you andar ... I didn't even know that existed. You rock!

I'm not sure why, but without the force_call, it doesn't work ... *shrug*

comment:3 Changed 13 years ago by andar

If you use sclient instead of aclient you probably wouldn't need the force_call()

comment:4 Changed 13 years ago by garett@…

  • Summary changed from dBus Interface to Scheduler (was: dBus Interface)

Ah yes, you're right. I also made a few other changes and it's a little more versatile now.

#!/usr/bin/python
from sys import argv, exit
import logging

logging.disable(logging.ERROR)

if (len(argv) < 2):
    print "Need value for max_active_limit"
    exit(2)

if (argv[1].isdigit()):
    from deluge.ui.client import sclient as client

    client.set_core_uri()
    client.set_config({'max_active_limit': int(argv[1])})

else:
    print "Invalid max_active_limit value"
    exit(3)

Then I added a few lines in my user cron like so:

10 1 * * * /home/garett/cron/deluge_set_max_active_limit.py 10
10 8 * * * /home/garett/cron/deluge_set_max_active_limit.py 0

Voila, instant scheduler. Dankeschön.

That was a lot easier than I imagined it being. I'm assuming if one used pyinstaller, you could compile this for windows as well and use it with the built-in scheduler.

You guys have created a wonderful interface here. Thank you once again. My only worry is the damage my fledgling python and I can do with this API. :)

Changed 13 years ago by garett@…

Script to alter configuration settings on the deluge backend

comment:6 Changed 13 years ago by garett@…

I've kept going ... I think I have everything someone might need in scheduler now. A sample cron:

10 1 * * * /home/garett/cron/deluge_config.py --max_active_limit 15 --max_active_downloading 10 --max_active_seeding 5 --max_upload_speed=-1 --max_download_speed=-1
10 8 * * * /home/garett/cron/deluge_config.py --max_active_limit 2 --max_active_downloading 2 --max_active_seeding 0 --max_upload_speed=10 --max_download_speed=30
10 14 * * * /home/garett/cron/deluge_config.py --max_active_limit 0

One can also now specify the backend as well, which may be handy to some.

Usage: deluge_config.py [options]

Options:
  -h, --help            show this help message and exit
  --port=PORT           port for deluge backend host (default: 58846)
  --host=HOST           hostname of deluge backend to connect to (default:
                        localhost)
  --max_active_limit=MAX_ACTIVE_LIMIT
                        sets the absolute maximum number of active torrents on
                        the deluge backend
  --max_active_downloading=MAX_ACTIVE_DOWNLOADING
                        sets the maximum number of active downloading torrents
                        on the deluge backend
  --max_active_seeding=MAX_ACTIVE_SEEDING
                        sets the maximum number of active seeding torrents on
                        the deluge backend
  --max_download_speed=MAX_DOWNLOAD_SPEED
                        sets the maximum global download speed on the deluge
                        backend
  --max_upload_speed=MAX_UPLOAD_SPEED
                        sets the maximum global upload speed on the deluge
                        backend
  --debug               outputs debug information to the console

comment:7 Changed 13 years ago by mvoncken

Added to svn r3567, this shouldn't get lost in a forgotten bug-report, at leatst not intil we have our own scheduler.

comment:8 Changed 13 years ago by garett@…

You might find what you put into the repository less than useful. It's all HTML. You want this file: http://dev.deluge-torrent.org/attachment/ticket/382/deluge_config.py?format=raw

comment:9 Changed 13 years ago by mvoncken

was fixed in r3568

comment:10 Changed 12 years ago by anonymous

http://sdfgdfg.freehostingz.com/index1.html infotronics attendance enterprise

comment:11 Changed 12 years ago by sysadmn

Here's another example crontab using this wonderful utility. I've implemented the scheduler as a state machine. Define variables for each state, then you only need to notice the transitions.

# +---------------- minute (0 - 59)
# |  +------------- hour (0 - 23)
# |  |  +---------- day of month (1 - 31)
# |  |  |  +------- month (1 - 12)
# |  |  |  |  +---- day of week (0 - 6) (Sunday=0 or 7)
# |  |  |  |  |
# *  *  *  *  *  command to be executed
# Vixie cron allows variables to be defined in the crontab
D_CTRL = /usr/local/bin/deluge_config.py
D_FAST = "--max_upload_speed=-1 --max_download_speed=-1"
D_NORMAL = "--max_upload_speed=40 --max_download_speed=80"
D_OFF = "--max_active_limit 0"
D_DAEMON = /usr/bin/deluged

# Deluge Schedule:
# Weekdays: Normal from Noon to 10 PM
59 11 * * 1-5 ${D_CTRL} ${D_NORMAL}
# Weekdays: Fast from 10 PM to Noon
59 21 * * 1-5 ${D_CTRL} ${D_FAST}
# Sat, Sun: Normal from 8 AM to 10 PM
59 7 * * 0,6 ${D_CTRL} ${D_NORMAL}
# Sat, Sun: Fast from 10 PM to 8 AM
59 21 * * 0,6 ${D_CTRL} ${D_FAST}
# Uncomment the next lines to start deluged at reboot.
# You can add args to D_DAEMON definition or in config file.
@reboot ${D_DAEMON}
@reboot ${D_CTRL} ${D_NORMAL}
Note: See TracTickets for help on using tickets.