Browse Source

Merge branch 'hotfix/0.22.9'

tags/release_0.22.9^0 release_0.22.9
JackDandy 5 years ago
parent
commit
c0b3ccd163
  1. 8
      CHANGES.md
  2. 7
      gui/slick/interfaces/default/config_general.tmpl
  3. 24
      lib/libtrakt/trakt.py
  4. 12
      sickbeard/__init__.py

8
CHANGES.md

@ -1,4 +1,10 @@
### 0.22.8 (2020-10-19 13:45:00 UTC)
### 0.22.9 (2020-10-21 11:55:00 UTC)
* Change remove DB file logging level from config/General and reduce DB levels to Debug to reduce log file noise
* Add Trakt rate-limiting http response code 429 handling to prevent request failure
### 0.22.8 (2020-10-19 13:45:00 UTC)
* Fix rare timing case on first-time startup with a network timezone update failure and an endless loop
* Change ensure `autoProcessTV/sabToSickGear.py` is set executable

7
gui/slick/interfaces/default/config_general.tmpl

@ -772,12 +772,15 @@
#for $level in $levels
#set $level_title = $level.title().upper()
#set $level_count -= 1
#if 'DB' == $level_title
#continue
#end if
#set $level_text = '%s%s' % ($level.title(), (('', ' only')[0 == $level_count], ' and the next%s level%s' % ((' ' + str($level_count), '')[1 == $level_count], maybe_plural($level_count)))[0 < $level_count])
<option value="$level_title"#echo ('', $selected)[$level_title == $sg_str('FILE_LOGGING_PRESET', 'DB')]#>$level_text</option>
#end for
</select>
<span>(default: Db)</span>
<p>enable Db or Debug to pin down an issue, the others are normal use</p>
<span>(default: Debug)</span>
<p>enable Debug to pin down an issue, the others are for light use</p>
</span>
</label>
</div>

24
lib/libtrakt/trakt.py

@ -6,9 +6,14 @@ import time
import datetime
import logging
from exceptions_helper import ex
from sg_helpers import try_int
from .exceptions import *
# noinspection PyUnreachableCode
if False:
from typing import Any, AnyStr, Dict
log = logging.getLogger('libtrakt')
log.addHandler(logging.NullHandler())
@ -193,7 +198,7 @@ class TraktAPI(object):
return False
if 'access_token' in resp and 'refresh_token' in resp and 'expires_in' in resp:
token_valid_date = now + datetime.timedelta(seconds=sickbeard.helpers.try_int(resp['expires_in']))
token_valid_date = now + datetime.timedelta(seconds=try_int(resp['expires_in']))
if refresh or (not refresh and None is not account and account in sickbeard.TRAKT_ACCOUNTS):
return self.replace_account(account, resp['access_token'], resp['refresh_token'],
token_valid_date, refresh)
@ -203,6 +208,7 @@ class TraktAPI(object):
def trakt_request(self, path, data=None, headers=None, url=None, count=0, sleep_retry=60,
send_oauth=None, method=None, **kwargs):
# type: (AnyStr, Dict, Dict, AnyStr, int, int, AnyStr, AnyStr, Any) -> Dict
if method not in ['GET', 'POST', 'PUT', 'DELETE', None]:
return {}
@ -310,6 +316,22 @@ class TraktAPI(object):
elif 404 == code:
log.warning(u'Trakt error (404) the resource does not exist: %s%s' % (url, path))
raise TraktMethodNotExisting('Trakt error (404) the resource does not exist: %s%s' % (url, path))
elif 429 == code:
if count >= self.max_retrys:
log.warning(u'Trakt replied with Rate-Limiting, maximum retries exceeded.')
raise TraktServerError(error_code=code)
r_headers = getattr(e.response, 'headers', None)
if None is not r_headers:
wait_seconds = min(try_int(r_headers.get('Retry-After', 60), 60), 150)
else:
wait_seconds = 60
log.warning('Trakt replied with Rate-Limiting, waiting %s seconds.' % wait_seconds)
wait_seconds = (wait_seconds, 60)[0 > wait_seconds]
wait_seconds -= sleep_retry
if 0 < wait_seconds:
time.sleep(wait_seconds)
return self.trakt_request(path, data, headers, url, count=count, sleep_retry=sleep_retry,
send_oauth=send_oauth, method=method)
else:
log.error(u'Could not connect to Trakt. Code error: {0}'.format(code))
raise TraktException('Could not connect to Trakt. Code error: %s' % code)

12
sickbeard/__init__.py

@ -140,7 +140,7 @@ started = False
ACTUAL_LOG_DIR = None
LOG_DIR = None
FILE_LOGGING_PRESET = 'DB'
FILE_LOGGING_PRESET = 'DEBUG'
SOCKET_TIMEOUT = None
@ -821,7 +821,11 @@ def init_stage_1(console_logging):
if not helpers.make_dir(LOG_DIR):
logger.log(u'!!! No log folder, logging to screen only!', logger.ERROR)
FILE_LOGGING_PRESET = check_setting_str(CFG, 'General', 'file_logging_preset', 'DB')
FILE_LOGGING_PRESET = check_setting_str(CFG, 'General', 'file_logging_preset', 'DEBUG')
if bool(check_setting_int(CFG, 'General', 'file_logging_db', 0)):
FILE_LOGGING_PRESET = 'DB'
elif 'DB' == FILE_LOGGING_PRESET:
FILE_LOGGING_PRESET = 'DEBUG'
SOCKET_TIMEOUT = check_setting_int(CFG, 'General', 'socket_timeout', 30)
socket.setdefaulttimeout(SOCKET_TIMEOUT)
@ -1757,7 +1761,9 @@ def save_config():
new_config['General']['cur_commit_branch'] = CUR_COMMIT_BRANCH
new_config['General']['encryption_version'] = int(ENCRYPTION_VERSION)
new_config['General']['log_dir'] = ACTUAL_LOG_DIR if ACTUAL_LOG_DIR else 'Logs'
new_config['General']['file_logging_preset'] = FILE_LOGGING_PRESET if FILE_LOGGING_PRESET else 'DB'
new_config['General']['file_logging_preset'] = FILE_LOGGING_PRESET \
if FILE_LOGGING_PRESET and 'DB' != FILE_LOGGING_PRESET else 'DEBUG'
new_config['General']['file_logging_db'] = 0
new_config['General']['socket_timeout'] = SOCKET_TIMEOUT
new_config['General']['web_host'] = WEB_HOST
new_config['General']['web_port'] = WEB_PORT

Loading…
Cancel
Save