Changeset a684994


Ignore:
Timestamp:
07/25/2008 06:42:58 PM (16 years ago)
Author:
Martijn Voncken <mvoncken@gmail.com>
Branches:
2.0.x, develop, extjs4-port, master
Children:
93c3d4
Parents:
5013ea
Message:

fix previous commit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • deluge/scripts/deluge_remote.py

    r5013ea ra684994  
    1 <!DOCTYPE html
    2     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    3     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    4 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    5 <head>
    6  <title>#382: deluge_config.py - Deluge - Trac</title><link rel="start" href="/wiki" /><link rel="search" href="/search" /><link rel="help" href="/wiki/TracGuide" /><link rel="stylesheet" href="/trac/css/trac.css" type="text/css" /><link rel="stylesheet" href="/trac/css/code.css" type="text/css" /><link rel="icon" href="/chrome/common/trac.ico" type="image/x-icon" /><link rel="shortcut icon" href="/chrome/common/trac.ico" type="image/x-icon" /><link rel="up" href="/ticket/382" title="Ticket #382" /><link rel="alternate" href="/attachment/ticket/382/deluge_config.py?format=raw" title="Original Format" type="text/x-python; charset=iso-8859-15" /><style type="text/css">
    7 </style>
    8  <script type="text/javascript" src="/trac/js/trac.js"></script>
    9 </head>
    10 <body>
     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
    1113
    12 <head>
    13 <link href="http://dev.deluge-torrent.org/chrome/common/deluge-specific.css" rel="stylesheet" type="text/css" />
    14 </head>
    15 <body>
    16 <div id="headerd">
    17   <div id="headerd-inner">
    18     <div id="delugelogo">
    19       <h1 id="delugetext"><a href="http://deluge-torrent.org/">Deluge <span id="msg_to_news">(return to news &amp; home)</span></a></h1>
    20     </div>
    21     <ul id="navbar">
    22         <!--[if gte IE 6]>
    23         <li><img src="chrome/common/spacer.gif" width="20"></li>
    24         <![endif]-->
    25       <li><a href="http://deluge-torrent.org/about.php">About</a></li>
    26       <li><a href="http://deluge-torrent.org/downloads.php">Download</a></li>
    27       <li><a href="http://forum.deluge-torrent.org/">Community</a></li>
    28       <li><a href="http://dev.deluge-torrent.org/" class="currenttab">Development</a></li>
    29       <li><a href="http://deluge-torrent.org/faq.php">FAQ</a></li>
    30       <li><a href="http://deluge-torrent.org/screenshots.php">Screenshots</a></li>
    31       <li><a href="http://deluge-torrent.org/plugin-list.php">Plugins</a></li>
    32     </ul>
    33   </div>
    34 </div>
     14from sys import argv, exit, stderr
     15from optparse import OptionParser
    3516
    36 <div id="banner">
     17import logging
    3718
    38 <div id="header"><a id="logo" href="http://dev.deluge-torrent.org/"><img src="/chrome/common/trac_banner.png" alt="" /></a><hr /></div>
     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;
    3927
    40 <form id="search" action="/search" method="get">
    41  <div>
    42   <label for="proj-search">Search:</label>
    43   <input type="text" id="proj-search" name="q" size="10" accesskey="f" value="" />
    44   <input type="submit" value="Search" />
    45   <input type="hidden" name="wiki" value="on" />
    46   <input type="hidden" name="changeset" value="on" />
    47   <input type="hidden" name="ticket" value="on" />
    48  </div>
    49 </form>
     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")
    5038
     39# grab command-line options
     40(options, args) = parser.parse_args()
    5141
     42if not options.debug:
     43    logging.disable(logging.ERROR)
    5244
    53 <div id="metanav" class="nav"><ul><li class="first">logged in as mvoncken</li><li><a href="/logout">Logout</a></li><li><a href="/settings">Settings</a></li><li><a accesskey="6" href="/wiki/TracGuide">Help/Guide</a></li><li class="last"><a href="/about">About Trac</a></li></ul></div>
    54 </div>
     45settings = {}
    5546
    56 <div id="mainnav" class="nav"><ul><li class="first"><a accesskey="1" href="/wiki">Wiki</a></li><li><a accesskey="2" href="/timeline">Timeline</a></li><li><a accesskey="3" href="/roadmap">Roadmap</a></li><li><a href="/browser">Browse Source</a></li><li><a href="/report">View Tickets</a></li><li><a accesskey="7" href="/newticket">New Ticket</a></li><li class="last"><a accesskey="4" href="/search">Search</a></li></ul></div>
    57 <div id="main">
     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)
    5854
     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)
    5961
     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)
    6068
     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)
    6175
    62 <div id="ctxtnav" class="nav"></div>
     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)
    6382
    64 <div id="content" class="attachment">
     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)
    6588
    66 
    67  <h1><a href="/ticket/382">Ticket #382</a>: deluge_config.py</h1>
    68  <table id="info" summary="Description"><tbody><tr>
    69    <th scope="col">
    70     File deluge_config.py, 3.8 kB
    71     (added by garett@zy.ca,  2 days ago)
    72    </th></tr><tr>
    73    <td class="message"><p>
    74 Script to alter configuration settings on the deluge backend
    75 </p>
    76 </td>
    77   </tr>
    78  </tbody></table>
    79  <div id="preview">
    80    <table class="code"><thead><tr><th class="lineno">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="L1"><a href="#L1">1</a></th>
    81 <td>#!/usr/bin/python</td>
    82 </tr><tr><th id="L2"><a href="#L2">2</a></th>
    83 <td>#</td>
    84 </tr><tr><th id="L3"><a href="#L3">3</a></th>
    85 <td># This software is in the public domain, furnished &#34;as is&#34;, without technical</td>
    86 </tr><tr><th id="L4"><a href="#L4">4</a></th>
    87 <td># support, and with no warranty, express or implied, as to its usefulness for</td>
    88 </tr><tr><th id="L5"><a href="#L5">5</a></th>
    89 <td># any purpose.</td>
    90 </tr><tr><th id="L6"><a href="#L6">6</a></th>
    91 <td>#</td>
    92 </tr><tr><th id="L7"><a href="#L7">7</a></th>
    93 <td># deluge_config.py</td>
    94 </tr><tr><th id="L8"><a href="#L8">8</a></th>
    95 <td># This code (at least in theory) allows one to alter configuration settings</td>
    96 </tr><tr><th id="L9"><a href="#L9">9</a></th>
    97 <td># on a deluge backend.&nbsp; &nbsp;At the moment, though, it only alters the parameters</td>
    98 </tr><tr><th id="L10"><a href="#L10">10</a></th>
    99 <td># that I've found useful to change.</td>
    100 </tr><tr><th id="L11"><a href="#L11">11</a></th>
    101 <td>#</td>
    102 </tr><tr><th id="L12"><a href="#L12">12</a></th>
    103 <td># Authour: Garett Harnish</td>
    104 </tr><tr><th id="L13"><a href="#L13">13</a></th>
    105 <td></td>
    106 </tr><tr><th id="L14"><a href="#L14">14</a></th>
    107 <td>from sys import argv, exit, stderr</td>
    108 </tr><tr><th id="L15"><a href="#L15">15</a></th>
    109 <td>from optparse import OptionParser</td>
    110 </tr><tr><th id="L16"><a href="#L16">16</a></th>
    111 <td></td>
    112 </tr><tr><th id="L17"><a href="#L17">17</a></th>
    113 <td>import logging</td>
    114 </tr><tr><th id="L18"><a href="#L18">18</a></th>
    115 <td></td>
    116 </tr><tr><th id="L19"><a href="#L19">19</a></th>
    117 <td>def isFloatDigit (string):</td>
    118 </tr><tr><th id="L20"><a href="#L20">20</a></th>
    119 <td>&nbsp; &nbsp; if string.isdigit():</td>
    120 </tr><tr><th id="L21"><a href="#L21">21</a></th>
    121 <td>&nbsp; &nbsp; &nbsp; &nbsp; return True</td>
    122 </tr><tr><th id="L22"><a href="#L22">22</a></th>
    123 <td>&nbsp; &nbsp; else:</td>
    124 </tr><tr><th id="L23"><a href="#L23">23</a></th>
    125 <td>&nbsp; &nbsp; &nbsp; &nbsp; try:</td>
    126 </tr><tr><th id="L24"><a href="#L24">24</a></th>
    127 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tmp = float(string)</td>
    128 </tr><tr><th id="L25"><a href="#L25">25</a></th>
    129 <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return True</td>
    130 </tr><tr><th id="L26"><a href="#L26">26</a></th>
    131 <td>&nbsp; &nbsp; &nbsp; &nbsp; except: return False;</td>
    132 </tr><tr><th id="L27"><a href="#L27">27</a></th>
    133 <td></td>
    134 </tr><tr><th id="L28"><a href="#L28">28</a></th>
    135 <td># set up command-line options</td>
    136 </tr><tr><th id="L29"><a href="#L29">29</a></th>
    137 <td>parser = OptionParser()</td>
    138 </tr><tr><th id="L30"><a href="#L30">30</a></th>
    139 <td>parser.add_option(&#34;--port&#34;, help=&#34;port for deluge backend host (default: 58846)&#34;, default=&#34;58846&#34;, dest=&#34;port&#34;)</td>
    140 </tr><tr><th id="L31"><a href="#L31">31</a></th>
    141 <td>parser.add_option(&#34;--host&#34;, help=&#34;hostname of deluge backend to connect to (default: localhost)&#34;, default=&#34;localhost&#34;, dest=&#34;host&#34;)</td>
    142 </tr><tr><th id="L32"><a href="#L32">32</a></th>
    143 <td>parser.add_option(&#34;--max_active_limit&#34;, help=&#34;sets the absolute maximum number of active torrents on the deluge backend&#34;, dest=&#34;max_active_limit&#34;)</td>
    144 </tr><tr><th id="L33"><a href="#L33">33</a></th>
    145 <td>parser.add_option(&#34;--max_active_downloading&#34;, help=&#34;sets the maximum number of active downloading torrents on the deluge backend&#34;, dest=&#34;max_active_downloading&#34;)</td>
    146 </tr><tr><th id="L34"><a href="#L34">34</a></th>
    147 <td>parser.add_option(&#34;--max_active_seeding&#34;, help=&#34;sets the maximum number of active seeding torrents on the deluge backend&#34;, dest=&#34;max_active_seeding&#34;)</td>
    148 </tr><tr><th id="L35"><a href="#L35">35</a></th>
    149 <td>parser.add_option(&#34;--max_download_speed&#34;, help=&#34;sets the maximum global download speed on the deluge backend&#34;, dest=&#34;max_download_speed&#34;)</td>
    150 </tr><tr><th id="L36"><a href="#L36">36</a></th>
    151 <td>parser.add_option(&#34;--max_upload_speed&#34;, help=&#34;sets the maximum global upload speed on the deluge backend&#34;, dest=&#34;max_upload_speed&#34;)</td>
    152 </tr><tr><th id="L37"><a href="#L37">37</a></th>
    153 <td>parser.add_option(&#34;--debug&#34;, help=&#34;outputs debug information to the console&#34;, default=False, action=&#34;store_true&#34;, dest=&#34;debug&#34;)</td>
    154 </tr><tr><th id="L38"><a href="#L38">38</a></th>
    155 <td></td>
    156 </tr><tr><th id="L39"><a href="#L39">39</a></th>
    157 <td># grab command-line options</td>
    158 </tr><tr><th id="L40"><a href="#L40">40</a></th>
    159 <td>(options, args) = parser.parse_args()</td>
    160 </tr><tr><th id="L41"><a href="#L41">41</a></th>
    161 <td></td>
    162 </tr><tr><th id="L42"><a href="#L42">42</a></th>
    163 <td>if not options.debug:</td>
    164 </tr><tr><th id="L43"><a href="#L43">43</a></th>
    165 <td>&nbsp; &nbsp; logging.disable(logging.ERROR)</td>
    166 </tr><tr><th id="L44"><a href="#L44">44</a></th>
    167 <td></td>
    168 </tr><tr><th id="L45"><a href="#L45">45</a></th>
    169 <td>settings = {}</td>
    170 </tr><tr><th id="L46"><a href="#L46">46</a></th>
    171 <td></td>
    172 </tr><tr><th id="L47"><a href="#L47">47</a></th>
    173 <td># set values if set and valid</td>
    174 </tr><tr><th id="L48"><a href="#L48">48</a></th>
    175 <td>if options.max_active_limit:</td>
    176 </tr><tr><th id="L49"><a href="#L49">49</a></th>
    177 <td>&nbsp; &nbsp; if options.max_active_limit.isdigit() and int(options.max_active_limit) &gt;= 0:</td>
    178 </tr><tr><th id="L50"><a href="#L50">50</a></th>
    179 <td>&nbsp; &nbsp; &nbsp; &nbsp; settings['max_active_limit'] = int(options.max_active_limit)</td>
    180 </tr><tr><th id="L51"><a href="#L51">51</a></th>
    181 <td>&nbsp; &nbsp; else:</td>
    182 </tr><tr><th id="L52"><a href="#L52">52</a></th>
    183 <td>&nbsp; &nbsp; &nbsp; &nbsp; stderr.write (&#34;ERROR: Invalid max_active_limit parameter!\n&#34;)</td>
    184 </tr><tr><th id="L53"><a href="#L53">53</a></th>
    185 <td>&nbsp; &nbsp; &nbsp; &nbsp; exit (-1)</td>
    186 </tr><tr><th id="L54"><a href="#L54">54</a></th>
    187 <td></td>
    188 </tr><tr><th id="L55"><a href="#L55">55</a></th>
    189 <td>if options.max_active_downloading:</td>
    190 </tr><tr><th id="L56"><a href="#L56">56</a></th>
    191 <td>&nbsp; &nbsp; if options.max_active_downloading.isdigit() and int(options.max_active_downloading) &gt;= 0:</td>
    192 </tr><tr><th id="L57"><a href="#L57">57</a></th>
    193 <td>&nbsp; &nbsp; &nbsp; &nbsp; settings['max_active_downloading'] = int(options.max_active_downloading)</td>
    194 </tr><tr><th id="L58"><a href="#L58">58</a></th>
    195 <td>&nbsp; &nbsp; else:</td>
    196 </tr><tr><th id="L59"><a href="#L59">59</a></th>
    197 <td>&nbsp; &nbsp; &nbsp; &nbsp; stderr.write (&#34;ERROR: Invalid max_active_downloading parameter!\n&#34;)</td>
    198 </tr><tr><th id="L60"><a href="#L60">60</a></th>
    199 <td>&nbsp; &nbsp; &nbsp; &nbsp; exit (-1)</td>
    200 </tr><tr><th id="L61"><a href="#L61">61</a></th>
    201 <td></td>
    202 </tr><tr><th id="L62"><a href="#L62">62</a></th>
    203 <td>if options.max_active_seeding:</td>
    204 </tr><tr><th id="L63"><a href="#L63">63</a></th>
    205 <td>&nbsp; &nbsp; if options.max_active_seeding.isdigit() and int(options.max_active_seeding) &gt;= 0:</td>
    206 </tr><tr><th id="L64"><a href="#L64">64</a></th>
    207 <td>&nbsp; &nbsp; &nbsp; &nbsp; settings['max_active_seeding'] = int(options.max_active_seeding)</td>
    208 </tr><tr><th id="L65"><a href="#L65">65</a></th>
    209 <td>&nbsp; &nbsp; else:</td>
    210 </tr><tr><th id="L66"><a href="#L66">66</a></th>
    211 <td>&nbsp; &nbsp; &nbsp; &nbsp; stderr.write (&#34;ERROR: Invalid max_active_seeding parameter!\n&#34;)</td>
    212 </tr><tr><th id="L67"><a href="#L67">67</a></th>
    213 <td>&nbsp; &nbsp; &nbsp; &nbsp; exit (-1)</td>
    214 </tr><tr><th id="L68"><a href="#L68">68</a></th>
    215 <td></td>
    216 </tr><tr><th id="L69"><a href="#L69">69</a></th>
    217 <td>if options.max_download_speed:</td>
    218 </tr><tr><th id="L70"><a href="#L70">70</a></th>
    219 <td>&nbsp; &nbsp; if isFloatDigit(options.max_download_speed) and (float(options.max_download_speed) &gt;= 0.0 or float(options.max_download_speed) == -1.0):</td>
    220 </tr><tr><th id="L71"><a href="#L71">71</a></th>
    221 <td>&nbsp; &nbsp; &nbsp; &nbsp; settings['max_download_speed'] = float(options.max_download_speed)</td>
    222 </tr><tr><th id="L72"><a href="#L72">72</a></th>
    223 <td>&nbsp; &nbsp; else:</td>
    224 </tr><tr><th id="L73"><a href="#L73">73</a></th>
    225 <td>&nbsp; &nbsp; &nbsp; &nbsp; stderr.write (&#34;ERROR: Invalid max_download_speed parameter!\n&#34;)</td>
    226 </tr><tr><th id="L74"><a href="#L74">74</a></th>
    227 <td>&nbsp; &nbsp; &nbsp; &nbsp; exit (-1)</td>
    228 </tr><tr><th id="L75"><a href="#L75">75</a></th>
    229 <td></td>
    230 </tr><tr><th id="L76"><a href="#L76">76</a></th>
    231 <td>if options.max_upload_speed:</td>
    232 </tr><tr><th id="L77"><a href="#L77">77</a></th>
    233 <td>&nbsp; &nbsp; if isFloatDigit(options.max_upload_speed) and (float(options.max_upload_speed) &gt;= 0.0 or float(options.max_upload_speed) == -1.0):</td>
    234 </tr><tr><th id="L78"><a href="#L78">78</a></th>
    235 <td>&nbsp; &nbsp; &nbsp; &nbsp; settings['max_upload_speed'] = float(options.max_upload_speed)</td>
    236 </tr><tr><th id="L79"><a href="#L79">79</a></th>
    237 <td>&nbsp; &nbsp; else:</td>
    238 </tr><tr><th id="L80"><a href="#L80">80</a></th>
    239 <td>&nbsp; &nbsp; &nbsp; &nbsp; stderr.write (&#34;ERROR: Invalid max_upload_speed parameter!\n&#34;)</td>
    240 </tr><tr><th id="L81"><a href="#L81">81</a></th>
    241 <td>&nbsp; &nbsp; &nbsp; &nbsp; exit (-1)</td>
    242 </tr><tr><th id="L82"><a href="#L82">82</a></th>
    243 <td></td>
    244 </tr><tr><th id="L83"><a href="#L83">83</a></th>
    245 <td># If there is something to do ...</td>
    246 </tr><tr><th id="L84"><a href="#L84">84</a></th>
    247 <td>if settings:</td>
    248 </tr><tr><th id="L85"><a href="#L85">85</a></th>
    249 <td>&nbsp; &nbsp; # create connection to daemon</td>
    250 </tr><tr><th id="L86"><a href="#L86">86</a></th>
    251 <td>&nbsp; &nbsp; from deluge.ui.client import sclient as client</td>
    252 </tr><tr><th id="L87"><a href="#L87">87</a></th>
    253 <td>&nbsp; &nbsp; client.set_core_uri(&#34;http://&#34; + options.host + &#34;:&#34; + options.port)</td>
    254 </tr><tr><th id="L88"><a href="#L88">88</a></th>
    255 <td></td>
    256 </tr><tr><th id="L89"><a href="#L89">89</a></th>
    257 <td>&nbsp; &nbsp; # commit configurations changes</td>
    258 </tr><tr><th id="L90"><a href="#L90">90</a></th>
    259 <td>&nbsp; &nbsp; client.set_config(settings)</td>
    260 </tr></tbody></table>
    261  </div>
    262  
    263 
    264 
    265 </div>
    266 <script type="text/javascript">searchHighlight()</script>
    267 <div id="altlinks"><h3>Download in other formats:</h3><ul><li class="first last"><a href="/attachment/ticket/382/deluge_config.py?format=raw">Original Format</a></li></ul></div>
    268 
    269 </div>
    270 
    271 <div id="footer">
    272  <hr />
    273  <a id="tracpowered" href="http://trac.edgewall.org/"><img src="/trac/trac_logo_mini.png" height="30" width="107"
    274    alt="Trac Powered"/></a>
    275  <p class="left">
    276   Powered by <a href="/about"><strong>Trac 0.10.3.1</strong></a><br />
    277   By <a href="http://www.edgewall.org/">Edgewall Software</a>.
    278  </p>
    279  <p class="right">
    280   Visit the Trac open source project at<br /><a href="http://trac.edgewall.org/">http://trac.edgewall.org/</a>
    281  </p>
    282 </div>
    283 
    284 
    285 
    286  </body>
    287 </html>
    288 
     89    # commit configurations changes
     90    client.set_config(settings)
Note: See TracChangeset for help on using the changeset viewer.