diff --git a/deluge/scripts/deluge_remote.py b/deluge/scripts/deluge_remote.py index b631dd4e0..cc6f864d5 100644 --- a/deluge/scripts/deluge_remote.py +++ b/deluge/scripts/deluge_remote.py @@ -1,288 +1,90 @@ - - - - #382: deluge_config.py - Deluge - Trac - - - +#!/usr/bin/python +# +# This software is in the public domain, furnished "as is", without technical +# support, and with no warranty, express or implied, as to its usefulness for +# any purpose. +# +# deluge_config.py +# This code (at least in theory) allows one to alter configuration settings +# on a deluge backend. At the moment, though, it only alters the parameters +# that I've found useful to change. +# +# Authour: Garett Harnish - - - - -
-
- - -
-
+from sys import argv, exit, stderr +from optparse import OptionParser - +settings = {} - -
+# set values if set and valid +if options.max_active_limit: + if options.max_active_limit.isdigit() and int(options.max_active_limit) >= 0: + settings['max_active_limit'] = int(options.max_active_limit) + else: + stderr.write ("ERROR: Invalid max_active_limit parameter!\n") + exit (-1) +if options.max_active_downloading: + if options.max_active_downloading.isdigit() and int(options.max_active_downloading) >= 0: + settings['max_active_downloading'] = int(options.max_active_downloading) + else: + stderr.write ("ERROR: Invalid max_active_downloading parameter!\n") + exit (-1) +if options.max_active_seeding: + if options.max_active_seeding.isdigit() and int(options.max_active_seeding) >= 0: + settings['max_active_seeding'] = int(options.max_active_seeding) + else: + stderr.write ("ERROR: Invalid max_active_seeding parameter!\n") + exit (-1) +if options.max_download_speed: + if isFloatDigit(options.max_download_speed) and (float(options.max_download_speed) >= 0.0 or float(options.max_download_speed) == -1.0): + settings['max_download_speed'] = float(options.max_download_speed) + else: + stderr.write ("ERROR: Invalid max_download_speed parameter!\n") + exit (-1) - +if options.max_upload_speed: + if isFloatDigit(options.max_upload_speed) and (float(options.max_upload_speed) >= 0.0 or float(options.max_upload_speed) == -1.0): + settings['max_upload_speed'] = float(options.max_upload_speed) + else: + stderr.write ("ERROR: Invalid max_upload_speed parameter!\n") + exit (-1) -
- - -

Ticket #382: deluge_config.py

- - - - -
- File deluge_config.py, 3.8 kB - (added by garett@zy.ca, 2 days ago) -

-Script to alter configuration settings on the deluge backend -

-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Line 
1#!/usr/bin/python
2#
3# This software is in the public domain, furnished "as is", without technical
4# support, and with no warranty, express or implied, as to its usefulness for
5# any purpose.
6#
7# deluge_config.py
8# This code (at least in theory) allows one to alter configuration settings
9# on a deluge backend.   At the moment, though, it only alters the parameters
10# that I've found useful to change.
11#
12# Authour: Garett Harnish
13
14from sys import argv, exit, stderr
15from optparse import OptionParser
16
17import logging
18
19def isFloatDigit (string):
20    if string.isdigit():
21        return True
22    else:
23        try:
24            tmp = float(string)
25            return True
26        except: return False;
27
28# set up command-line options
29parser = OptionParser()
30parser.add_option("--port", help="port for deluge backend host (default: 58846)", default="58846", dest="port")
31parser.add_option("--host", help="hostname of deluge backend to connect to (default: localhost)", default="localhost", dest="host")
32parser.add_option("--max_active_limit", help="sets the absolute maximum number of active torrents on the deluge backend", dest="max_active_limit")
33parser.add_option("--max_active_downloading", help="sets the maximum number of active downloading torrents on the deluge backend", dest="max_active_downloading")
34parser.add_option("--max_active_seeding", help="sets the maximum number of active seeding torrents on the deluge backend", dest="max_active_seeding")
35parser.add_option("--max_download_speed", help="sets the maximum global download speed on the deluge backend", dest="max_download_speed")
36parser.add_option("--max_upload_speed", help="sets the maximum global upload speed on the deluge backend", dest="max_upload_speed")
37parser.add_option("--debug", help="outputs debug information to the console", default=False, action="store_true", dest="debug")
38
39# grab command-line options
40(options, args) = parser.parse_args()
41
42if not options.debug:
43    logging.disable(logging.ERROR)
44
45settings = {}
46
47# set values if set and valid
48if options.max_active_limit:
49    if options.max_active_limit.isdigit() and int(options.max_active_limit) >= 0:
50        settings['max_active_limit'] = int(options.max_active_limit)
51    else:
52        stderr.write ("ERROR: Invalid max_active_limit parameter!\n")
53        exit (-1)
54
55if options.max_active_downloading:
56    if options.max_active_downloading.isdigit() and int(options.max_active_downloading) >= 0:
57        settings['max_active_downloading'] = int(options.max_active_downloading)
58    else:
59        stderr.write ("ERROR: Invalid max_active_downloading parameter!\n")
60        exit (-1)
61
62if options.max_active_seeding:
63    if options.max_active_seeding.isdigit() and int(options.max_active_seeding) >= 0:
64        settings['max_active_seeding'] = int(options.max_active_seeding)
65    else:
66        stderr.write ("ERROR: Invalid max_active_seeding parameter!\n")
67        exit (-1)
68
69if options.max_download_speed:
70    if isFloatDigit(options.max_download_speed) and (float(options.max_download_speed) >= 0.0 or float(options.max_download_speed) == -1.0):
71        settings['max_download_speed'] = float(options.max_download_speed)
72    else:
73        stderr.write ("ERROR: Invalid max_download_speed parameter!\n")
74        exit (-1)
75
76if options.max_upload_speed:
77    if isFloatDigit(options.max_upload_speed) and (float(options.max_upload_speed) >= 0.0 or float(options.max_upload_speed) == -1.0):
78        settings['max_upload_speed'] = float(options.max_upload_speed)
79    else:
80        stderr.write ("ERROR: Invalid max_upload_speed parameter!\n")
81        exit (-1)
82
83# If there is something to do ...
84if settings:
85    # create connection to daemon
86    from deluge.ui.client import sclient as client
87    client.set_core_uri("http://" + options.host + ":" + options.port)
88
89    # commit configurations changes
90    client.set_config(settings)
-
- - - -
- - - -
- - - - - - - +# If there is something to do ... +if settings: + # create connection to daemon + from deluge.ui.client import sclient as client + client.set_core_uri("http://" + options.host + ":" + options.port) + # commit configurations changes + client.set_config(settings)