SHARE
TWEET

Server Priority

a guest Jun 3rd, 2014 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. commit bb11fed59b12111d6fd18127cd123f29ec9d65f4
  2. Author: Fmstrat <github@nosolutions.com>
  3. Date:   Thu Dec 19 18:02:52 2013 -0500
  4.  
  5.     Updated for server priority selection
  6.  
  7. diff --git a/sabnzbd/nzbstuff.py b/sabnzbd/nzbstuff.py
  8. index 65540db..a018e5b 100644
  9. --- a/sabnzbd/nzbstuff.py
  10. +++ b/sabnzbd/nzbstuff.py
  11. @@ -88,7 +88,7 @@ class Article(TryList):
  12.          self.tries = 0 # Try count
  13.          self.nzf = nzf
  14.  
  15. -    def get_article(self, server):
  16. +    def get_article(self, server, servers):
  17.          """ Return article when appropriate for specified server """
  18.          if server.fillserver and (not self.allow_fill_server) and sabnzbd.active_primaries():
  19.             logging.debug('Article %s | Server: %s | Skipping as its a fill', self.article, server.host)
  20.  
  21. commit 013056f2049983cdb952cfad3beb142c84f3d634
  22. Author: Fmstrat <github@nosolutions.com>
  23. Date:   Tue Dec 17 11:48:50 2013 -0500
  24.  
  25.     Updated for server priority selection
  26.  
  27. diff --git a/interfaces/Classic/templates/config_server.tmpl b/interfaces/Classic/templates/config_server.tmpl
  28. index 9ecfa50..2f3d417 100644
  29. --- a/interfaces/Classic/templates/config_server.tmpl
  30. +++ b/interfaces/Classic/templates/config_server.tmpl
  31. @@ -17,6 +17,7 @@
  32.        $T('srv-password'):<br><input type="password" size="25" name="password"><br>
  33.        $T('srv-timeout'):<br><input type="text" size="25" name="timeout" value="120"><br>
  34.        $T('srv-connections'):<br><input type="text" size="25" name="connections"><br>
  35. +      $T('srv-priority'):<br><input type="text" size="25" name="priority"><br>
  36.        $T('srv-retention') ($T('days')):<br><input type="text" size="25" name="retention"><br>
  37.        <!--#if int($have_ssl) == 0#-->
  38.          $T('srv-ssl') $T('opt-notInstalled')
  39. @@ -42,6 +43,7 @@
  40.        $T('srv-password'):<br><input type="password" size="25" name="password" value="$servers[$server]['password']"><br>
  41.        $T('srv-timeout'):<br><input type="text" size="25" name="timeout" value="$servers[$server]['timeout']"><br>
  42.        $T('srv-connections'):<br><input type="text" size="25" name="connections" value="$servers[$server]['connections']"><br>
  43. +      $T('srv-priorty'):<br><input type="text" size="25" name="priorty" value="$servers[$server]['priorty']"><br>
  44.        $T('srv-retention'):<br><input type="text" size="25" name="retention" value="$servers[$server]['retention']"><br>
  45.        <!--#if int($have_ssl) == 0#-->
  46.          $T('srv-ssl') $T('opt-notInstalled')
  47. diff --git a/interfaces/Config/templates/config_server.tmpl b/interfaces/Config/templates/config_server.tmpl
  48. index 171da0e..6b867c4 100644
  49. --- a/interfaces/Config/templates/config_server.tmpl
  50. +++ b/interfaces/Config/templates/config_server.tmpl
  51. @@ -41,6 +41,10 @@
  52.                      <label class="config" for="connections">$T('srv-connections')</label>
  53.                      <input type="number" name="connections" id="connections" size="8" min="0" max="100" />
  54.                  </div>
  55. +                <div class="field-pair">
  56. +                    <label class="config" for="priority">$T('srv-priority')</label>
  57. +                    <input type="number" name="priority" id="priority" size="8" min="0" max="100" />
  58. +                </div>
  59.                  <div class="field-pair alt">
  60.                      <label class="config" for="retention">$T('srv-retention')</label>
  61.                      <input type="number" name="retention" id="retention" size="8" min="0" /> <i>$T('days')</i>
  62. @@ -122,6 +126,10 @@
  63.                      <label class="config" for="connections$cur">$T('srv-connections')</label>
  64.                      <input type="number" name="connections" id="connections$cur" value="$servers[$server]['connections']" size="8" min="0" max="100" />
  65.                  </div>
  66. +                <div class="field-pair">
  67. +                    <label class="config" for="priority$cur">$T('srv-priority')</label>
  68. +                    <input type="number" name="priority" id="priority$cur" value="$servers[$server]['priority']" size="8" min="0" max="100" />
  69. +                </div>
  70.                  <div class="field-pair alt">
  71.                      <label class="config" for="retention$cur">$T('srv-retention')</label>
  72.                      <input type="number" name="retention" id="retention$cur" value="$servers[$server]['retention']" size="8" min="0" /> <i>$T('days')</i>
  73. diff --git a/interfaces/Plush/templates/config_server.tmpl b/interfaces/Plush/templates/config_server.tmpl
  74. index 305e7a5..7578159 100644
  75. --- a/interfaces/Plush/templates/config_server.tmpl
  76. +++ b/interfaces/Plush/templates/config_server.tmpl
  77. @@ -55,6 +55,12 @@
  78.            <input type="text" size="10" name="connections"/>
  79.          </label>
  80.        </div>
  81. +      <div class="field-pair">
  82. +        <label class="nocheck clearfix" for="priority">
  83. +          <span class="component-title"># $T('srv-priority')</span>
  84. +          <input type="text" size="10" name="priority"/>
  85. +        </label>
  86. +      </div>
  87.        <div class="field-pair alt">
  88.          <label class="nocheck clearfix" for="retention">
  89.            <span class="component-title">$T('srv-retention')</span>
  90. @@ -165,6 +171,12 @@
  91.        <input type="text" size="10" name="connections" value="$servers[$server]['connections']" />
  92.      </label>
  93.    </div>
  94. +  <div class="field-pair">
  95. +    <label class="nocheck clearfix" for="priority">
  96. +      <span class="component-title">$T('srv-priority')</span>
  97. +      <input type="text" size="10" name="priority" value="$servers[$server]['priority']" />
  98. +    </label>
  99. +  </div>
  100.    <div class="field-pair alt">
  101.      <label class="nocheck clearfix" for="retention">
  102.        <span class="component-title">$T('srv-retention')</span>
  103. diff --git a/interfaces/smpl/templates/config_server.tmpl b/interfaces/smpl/templates/config_server.tmpl
  104. index af26cf6..f584576 100644
  105. --- a/interfaces/smpl/templates/config_server.tmpl
  106. +++ b/interfaces/smpl/templates/config_server.tmpl
  107. @@ -22,6 +22,8 @@
  108.          <br class="clear" />
  109.        <label class="label">$T('srv-connections'):</label><input type="text" size="25" name="connections" value="$servers[$server]['connections']">
  110.          <br class="clear" />
  111. +      <label class="label">$T('srv-priority'):</label><input type="text" size="25" name="priority" value="$servers[$server]['priority']">
  112. +        <br class="clear" />
  113.        <label class="label">$T('srv-retention') ($T('days')):</label><input type="text" size="25" name="retention" value="$servers[$server]['retention']">
  114.          <br class="clear" />
  115.  
  116. @@ -87,6 +89,9 @@
  117.    <label class="label">$T('srv-connections'):</label><input type="text" size="25" name="connections">
  118.  <br class="clear" />
  119.  
  120. +  <label class="label">$T('srv-priority'):</label><input type="text" size="25" name="priority">
  121. +<br class="clear" />
  122. +
  123.    <label class="label">$T('srv-retention') ($T('days')):</label><input type="text" size="25" name="retention">
  124.  <br class="clear" />
  125.  
  126. @@ -113,4 +118,4 @@
  127.  </fieldset>
  128.    </form><br class="clear"/>
  129.  
  130. -</div>
  131. \ No newline at end of file
  132. +</div>
  133. diff --git a/interfaces/wizard/one.html b/interfaces/wizard/one.html
  134. index 1aaf719..bb32f19 100644
  135. --- a/interfaces/wizard/one.html
  136. +++ b/interfaces/wizard/one.html
  137. @@ -31,6 +31,10 @@ $T('wizard-explain-server')
  138.    <div id="connections-tip" class="tips">$T('wizard-server-con-explain') $T('wizard-server-con-eg')</div>
  139.    <div id="connections-error" class="error-text hidden">$T('wizard-server-number')</div>
  140.    <br class="clear" />
  141. +  <label class="label">$T('srv-priority')<span class="required-star">*</span></label><input id="priority" class="text-input-thin" type="text" size="2" name="priority" value="$priority">
  142. +  <div id="priority-tip" class="tips">$T('wizard-server-pri-explain') $T('wizard-server-pri-eg')</div>
  143. +  <div id="priority-error" class="error-text hidden">$T('wizard-server-number')</div>
  144. +  <br class="clear" />
  145.    <label for="srv-ssl"><!--#if $have_ssl then $T('srv-ssl') else '<span class="disabled-text">'+$T('srv-ssl')+'</span> (pyopenssl (python-ssl) '+$T('opt-notInstalled')+')'#-->
  146.    <input class="validate-text" class="radio" type="checkbox" name="ssl" value="1" <!--#if $have_ssl then '' else 'disabled'#--><!--#if $ssl == 1 then 'checked' else ''#-->></label>
  147.    <div class="tips">$T('wizard-server-ssl-explain')</div>
  148. @@ -58,4 +62,4 @@ $T('wizard-explain-server')
  149.  </table>
  150.  </div>
  151.  </form>
  152. -<!--#include $webdir + "/inc_bottom.tmpl"#-->
  153. \ No newline at end of file
  154. +<!--#include $webdir + "/inc_bottom.tmpl"#-->
  155. diff --git a/interfaces/wizard/static/javascript/checkserver.js b/interfaces/wizard/static/javascript/checkserver.js
  156. index 51583e2..049156a 100644
  157. --- a/interfaces/wizard/static/javascript/checkserver.js
  158. +++ b/interfaces/wizard/static/javascript/checkserver.js
  159. @@ -77,6 +77,22 @@ $(document).ready(function() {
  160.      }
  161.    });
  162.  
  163. +  $("#priority").bind('keyup blur',function(){
  164. +    if (this.value && isFinite(this.value)){
  165. +      $(this).removeClass("incorrect");
  166. +      $(this).addClass("correct");
  167. +      $("#priority-tip").removeClass("hidden");
  168. +      $("#priority-error").addClass("hidden");
  169. +      checkRequired();
  170. +    } else {
  171. +      $(this).removeClass("correct");
  172. +      $(this).addClass("incorrect");
  173. +      $("#priority-tip").addClass("hidden");
  174. +      $("#priority-error").removeClass("hidden");
  175. +      checkRequired();
  176. +    }
  177. +  });
  178. +
  179.    $("#port").bind('keyup blur',function(){
  180.      if (!this.value || isFinite(this.value)){
  181.        $(this).removeClass("incorrect");
  182. @@ -106,4 +122,4 @@ $(document).ready(function() {
  183.        checkRequired();
  184.      }
  185.    });
  186. -});
  187. \ No newline at end of file
  188. +});
  189. diff --git a/sabnzbd/config.py b/sabnzbd/config.py
  190. index 71cdeb6..13ab51c 100644
  191. --- a/sabnzbd/config.py
  192. +++ b/sabnzbd/config.py
  193. @@ -360,6 +360,7 @@ class ConfigServer(object):
  194.          self.enable = OptionBool(name, 'enable', True, add=False)
  195.          self.optional = OptionBool(name, 'optional', False, add=False)
  196.          self.retention = OptionNumber(name, 'retention', add=False)
  197. +        self.priority = OptionNumber(name, 'priority', 0, 0, 100, add=False)
  198.  
  199.          self.set_dict(values)
  200.          add_to_database('servers', self.__name, self)
  201. @@ -367,7 +368,7 @@ class ConfigServer(object):
  202.      def set_dict(self, values):
  203.          """ Set one or more fields, passed as dictionary """
  204.          for kw in ('host', 'port', 'timeout', 'username', 'password', 'connections',
  205. -                   'fillserver', 'ssl', 'enable', 'optional', 'retention'):
  206. +                   'fillserver', 'ssl', 'enable', 'optional', 'retention', 'priority'):
  207.              try:
  208.                  value = values[kw]
  209.              except KeyError:
  210. @@ -393,6 +394,7 @@ class ConfigServer(object):
  211.          dict['enable'] = self.enable()
  212.          dict['optional'] = self.optional()
  213.          dict['retention'] = self.retention()
  214. +        dict['priority'] = self.priority()
  215.          return dict
  216.  
  217.      def delete(self):
  218. diff --git a/sabnzbd/downloader.py b/sabnzbd/downloader.py
  219. index 00d7b9c..621f961 100644
  220. --- a/sabnzbd/downloader.py
  221. +++ b/sabnzbd/downloader.py
  222. @@ -54,7 +54,7 @@ TIMER_LOCK = RLock()
  223.  
  224.  #------------------------------------------------------------------------------
  225.  class Server(object):
  226. -    def __init__(self, id, host, port, timeout, threads, fillserver, ssl, username = None,
  227. +    def __init__(self, id, host, port, timeout, threads, priority, fillserver, ssl, username = None,
  228.                   password = None, optional=False, retention=0):
  229.          self.id = id
  230.          self.newid = None
  231. @@ -63,6 +63,7 @@ class Server(object):
  232.          self.port = port
  233.          self.timeout = timeout
  234.          self.threads = threads
  235. +        self.priority = priority
  236.          self.fillserver = fillserver
  237.          self.ssl = ssl
  238.          self.optional = optional
  239. @@ -176,6 +177,7 @@ class Downloader(Thread):
  240.              port = srv.port()
  241.              timeout = srv.timeout()
  242.              threads = srv.connections()
  243. +            priority = srv.priority()
  244.              fillserver = srv.fillserver()
  245.              primary = enabled and (not fillserver) and (threads > 0)
  246.              ssl = srv.ssl() and sabnzbd.newswrapper.HAVE_SSL
  247. @@ -196,8 +198,8 @@ class Downloader(Thread):
  248.                      break
  249.  
  250.          if create and enabled and host and port and threads:
  251. -            self.servers.append(Server(newserver, host, port, timeout, threads, fillserver, ssl,
  252. -                                            username, password, optional, retention))
  253. +            self.servers.append(Server(newserver, host, port, timeout, threads, priority, fillserver,
  254. +                                            ssl, username, password, optional, retention))
  255.  
  256.          return primary
  257.  
  258. @@ -356,7 +358,7 @@ class Downloader(Thread):
  259.                          request_server_info(server)
  260.                          break
  261.  
  262. -                    article = NzbQueue.do.get_article(server)
  263. +                    article = NzbQueue.do.get_article(server, self.servers)
  264.  
  265.                      if not article:
  266.                          break
  267. diff --git a/sabnzbd/nzbqueue.py b/sabnzbd/nzbqueue.py
  268. index 2f6e194..afd8b1c 100644
  269. --- a/sabnzbd/nzbqueue.py
  270. +++ b/sabnzbd/nzbqueue.py
  271. @@ -684,12 +684,12 @@ class NzbQueue(TryList):
  272.          return False
  273.  
  274.      @synchronized(NZBQUEUE_LOCK)
  275. -    def get_article(self, server):
  276. +    def get_article(self, server, servers):
  277.          if self.__top_only:
  278.              if self.__nzo_list:
  279.                  for nzo in self.__nzo_list:
  280.                      if nzo.status not in (Status.PAUSED, Status.GRABBING):
  281. -                        article = nzo.get_article(server)
  282. +                        article = nzo.get_article(server, servers)
  283.                          if article:
  284.                              return article
  285.  
  286. @@ -697,7 +697,7 @@ class NzbQueue(TryList):
  287.              for nzo in self.__nzo_list:
  288.                  # Don't try to get an article if server is in try_list of nzo
  289.                  if not nzo.server_in_try_list(server) and nzo.status not in (Status.PAUSED, Status.GRABBING):
  290. -                    article = nzo.get_article(server)
  291. +                    article = nzo.get_article(server, servers)
  292.                      if article:
  293.                          return article
  294.  
  295. diff --git a/sabnzbd/nzbstuff.py b/sabnzbd/nzbstuff.py
  296. index edb0b63..65540db 100644
  297. --- a/sabnzbd/nzbstuff.py
  298. +++ b/sabnzbd/nzbstuff.py
  299. @@ -42,6 +42,7 @@ from sabnzbd.misc import to_units, cat_to_opts, cat_convert, sanitize_foldername
  300.                           get_unique_path, get_admin_path, remove_all, format_source_url, \
  301.                           sanitize_filename, globber, sanitize_foldername, int_conv, \
  302.                           set_permissions
  303. +import sabnzbd.config as config
  304.  import sabnzbd.cfg as cfg
  305.  from sabnzbd.trylist import TryList
  306.  from sabnzbd.encoding import unicoder, platform_encode, latin1, name_fixer
  307. @@ -77,6 +78,7 @@ class Article(TryList):
  308.          TryList.__init__(self)
  309.  
  310.          self.fetcher = None
  311. +        self.fetcher_priority = 0
  312.          self.allow_fill_server = False
  313.  
  314.          self.article = article
  315. @@ -89,13 +91,50 @@ class Article(TryList):
  316.      def get_article(self, server):
  317.          """ Return article when appropriate for specified server """
  318.          if server.fillserver and (not self.allow_fill_server) and sabnzbd.active_primaries():
  319. +           logging.debug('Article %s | Server: %s | Skipping as its a fill', self.article, server.host)
  320.              return None
  321.  
  322.          if not self.fetcher and not self.server_in_try_list(server):
  323. -            self.fetcher = server
  324. -            self.tries += 1
  325. -            if sabnzbd.LOG_ALL: logging.debug('Article-try = %s', self.tries)
  326. -            return self
  327. +           logging.debug('Article %s | Server: %s | in second if', self.article, server.host)
  328. +            # Is the current selected server of the same priority as this article?
  329. +           logging.debug('Article %s | Server: %s | Article priority: %s', self.article, server.host, self.fetcher_priority)
  330. +           logging.debug('Article %s | Server: %s | Server priority: %s', self.article, server.host, server.priority)
  331. +           if (server.priority == self.fetcher_priority):
  332. +                   logging.debug('Article %s | Server: %s | same priority, use it', self.article, server.host)
  333. +                   self.fetcher = server
  334. +                   self.tries += 1
  335. +                   if sabnzbd.LOG_ALL: logging.debug('Article %s | Server: %s | Article-try: %s', self.article, server.host, self.tries)
  336. +                   logging.debug('Article %s | Server: %s | Article-try: %s', self.article, server.host, self.tries)
  337. +                   return self
  338. +           else:
  339. +                   logging.debug('Article %s | Server: %s | not the same priorty', self.article, server.host)
  340. +                    # No, so is it a lower priority?
  341. +                    if (server.priority > self.fetcher_priority):
  342. +                        logging.debug('Article %s | Server: %s | lower priority', self.article, server.host)
  343. +                         # Is there an available server that is a higher priority?
  344. +                         found_priority = 1000
  345. +                         #for server_check in config.get_servers():
  346. +                         for server_check in servers:
  347. +                             logging.debug('Article %s | Server: %s | checking', self.article, server.host)
  348. +                              #if (server_check.priority() < found_priority and server_check.priority() < server.priority and not self.server_in_try_list(server_check)):
  349. +                              if (server_check.priority < found_priority):
  350. +                                   if (server_check.priority < server.priority):
  351. +                                       if (not self.server_in_try_list(server_check)):
  352. +                                           logging.debug('Article %s | Server: %s | setting found priority to %s', self.article, server.host, server_check.priority)
  353. +                                            found_priority = server_check.priority
  354. +                         if found_priority == 1000:
  355. +                              # If no higher priority servers, use this server
  356. +                              self.fetcher_priority = server.priority
  357. +                             self.fetcher = server
  358. +                             self.tries += 1
  359. +                             if sabnzbd.LOG_ALL: logging.debug('Article %s | Server: %s | Article-try: %s', self.article, server.host, self.tries)
  360. +                             logging.debug('Article %s | Server: %s | Article-try: %s', self.article, server.host, self.tries)
  361. +                             return self
  362. +                         else:
  363. +                              # There is a higher priorty server, so set article priority
  364. +                             logging.debug('Article %s | Server: %s | setting self priority', self.article, server.host)
  365. +                              self.fetcher_priority = found_priority
  366. +       logging.debug('Article %s | Server: %s | Returning None', self.article, server.host)
  367.          return None
  368.  
  369.      def get_art_id(self):
  370. @@ -121,6 +160,7 @@ class Article(TryList):
  371.                  self.__dict__[tup[1]] = None
  372.          TryList.__init__(self)
  373.          self.fetcher = None
  374. +        self.fetcher_priority = 0
  375.          self.allow_fill_server = False
  376.          self.tries = 0
  377.  
  378. @@ -250,16 +290,16 @@ class NzbFile(TryList):
  379.          self.vol = vol
  380.          self.blocks = int(blocks)
  381.  
  382. -    def get_article(self, server):
  383. +    def get_article(self, server, servers):
  384.          """ Get next article to be downloaded """
  385.          if self.initial_article:
  386. -            article = self.initial_article.get_article(server)
  387. +            article = self.initial_article.get_article(server, servers)
  388.              if article:
  389.                  return article
  390.  
  391.          else:
  392.              for article in self.articles:
  393. -                article = article.get_article(server)
  394. +                article = article.get_article(server, servers)
  395.                  if article:
  396.                      return article
  397.  
  398. @@ -1157,7 +1197,7 @@ class NzbObject(TryList):
  399.          except:
  400.              self.nzo_info[log] = [txt]
  401.  
  402. -    def get_article(self, server):
  403. +    def get_article(self, server, servers):
  404.          article = None
  405.          nzf_remove_list = []
  406.  
  407. @@ -1181,7 +1221,7 @@ class NzbObject(TryList):
  408.                          else:
  409.                              continue
  410.  
  411. -                    article = nzf.get_article(server)
  412. +                    article = nzf.get_article(server, servers)
  413.                      if article:
  414.                          break
  415.  
  416. diff --git a/sabnzbd/skintext.py b/sabnzbd/skintext.py
  417. index 329d567..05ff5ca 100644
  418. --- a/sabnzbd/skintext.py
  419. +++ b/sabnzbd/skintext.py
  420. @@ -494,6 +494,7 @@ SKIN_TEXT = {
  421.      'srv-connections' : TT('Connections'), #: Server: amount of connections
  422.      'srv-retention' : TT('Retention time'), #: Server's retention time in days
  423.      'srv-ssl' : TT('SSL'), #: Server SSL tickbox
  424. +    'srv-priority' : TT('Priority'), #: Server priority
  425.      'srv-fillserver' : TT('Backup server'), #: Backup server tickbox
  426.      'srv-optional' : TT('Optional'), #: Server optional tickbox
  427.      'srv-enable' : TT('Enable'), #: Enable server tickbox
  428. @@ -865,6 +866,8 @@ SKIN_TEXT = {
  429.      'wizard-server-help2' :  TT('Don\'t have a usenet provider? We recommend trying %s.'),
  430.      'wizard-server-con-explain' :  TT('The number of connections allowed by your provider'),
  431.      'wizard-server-con-eg' : TT('E.g. 8 or 20'), #: Wizard: examples of amount of connections
  432. +    'wizard-server-pri-explain' : TT('The priority of your server, 0 being first, 100 being last.'),
  433. +    'wizard-server-pri-eg' : TT('E.g. 0, 2 or 3'), #: Wizard: examples of priority
  434.      'wizard-server-ssl-explain' :  TT('Select only if your provider allows SSL connections.'),
  435.      'wizard-server-text' :  TT('Click to test the entered details.'),
  436.      'wizard-server-required' :  TT('This field is required.'),
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top