Skip to content

Commit

Permalink
Release 0.1.5.1 (#1148)
Browse files Browse the repository at this point in the history
* Refactor searches (#797)

* Refactor search -> search/core

* Refactor searchBacklog -> search/backlog

* Refactor dailysearcher -> search/daily

* Refactor manual_search -> search/manual

* Refactor properFinder -> search/proper

* Refactor search_queue -> search/queue

* Refactor

* Fixing flake8 issues

* Remove unused import

* Update DB version to v44 to keep compatibility (#1141)

* Update DB version to v44 to keep compatibility

* Update main_db.py

* Update main_db.py

* Update main_db.py

* Fix massUpdate (#1143)

* Update comments in DB upgrade (#1147)
  • Loading branch information
fernandog authored and medariox committed Sep 18, 2016
1 parent 04137b6 commit 61fc790
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 72 deletions.
2 changes: 1 addition & 1 deletion gui/slick/js/mass-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ $(document).ready(function() {
toMetadata: metadataArr.join('|')
});

window.location.href = 'massUpdate?' + params;
window.location.href = 'manage/massUpdate?' + params;
}
});
}
Expand Down
13 changes: 7 additions & 6 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ flake8-ignore =
sickbeard/classes.py D100 D101 D102 D105 N802 N803
sickbeard/common.py D101 D102 D105 D200 D202 D204 D205 D400 D401 E501 N802 N812
sickbeard/config.py D100 D101 D103 D200 D202 D205 D210 D400 D401 E501 N802 N803 N806
sickbeard/dailysearcher.py D100 D102 D200 D400 D401
sickbeard/databases/cache_db.py D100 D101 D102 E501
sickbeard/databases/failed_db.py D100 D101 D102 D400 E501
sickbeard/databases/__init__.py D104
Expand All @@ -29,7 +28,6 @@ flake8-ignore =
sickbeard/indexers/indexer_exceptions.py D400 E501
sickbeard/indexers/__init__.py D104 F401
sickbeard/__init__.py D103 D104 E501 F401 F841 N802 N803 N806
sickbeard/manual_search.py D100 D200 D202 D205 D210 D400 D401 E501 F401 N802
sickbeard/metadata/generic.py D100 D102 D200 D202 D205 D400 D401 E302 E501 N802 N806
sickbeard/metadata/helpers.py D100 D103 N802 N803 N806
sickbeard/metadata/__init__.py D104 N802
Expand Down Expand Up @@ -70,7 +68,6 @@ flake8-ignore =
sickbeard/nzbSplitter.py D100 D202 D400 E501
sickbeard/postProcessor.py D100 D200 D202 D205 D400 D401 E501 F401 N802 N803 N806
sickbeard/processTV.py D100 D101 D102 D103 D202 D205 D400 D401 E127 E128 E265 E302 E501 F401 N802 N803 N806
sickbeard/properFinder.py D100 D101 D102 D200 D202 D400 E501 F401 N802 N812
sickbeard/providers/__init__.py D104 F401 N802
sickbeard/providers/nzb/anizb.py D100 D102 D400
sickbeard/providers/nzb/binsearch.py D100 D101 D102 D202 D204 D400 D401 N802
Expand Down Expand Up @@ -139,9 +136,13 @@ flake8-ignore =
sickbeard/scene_exceptions.py D100
sickbeard/scene_numbering.py D100 D200 D205 D400 D401 E501 N803 N806
sickbeard/scheduler.py D100 D101 D102 D200 D205 D400 D401 E501 N802 N803
sickbeard/searchBacklog.py D100 D101 D102 E501 N802 N803 N806
sickbeard/search.py D100 D202 D401 E501 F401 F821 N802 N803 N806 N812
sickbeard/search_queue.py D100 D101 D102 D103 D200 D204 D205 D210 D400 D401 E231 E501 N803
sickbeard/search/__init__.py D104
sickbeard/search/backlog.py D100 D101 D102 E501 N802 N803 N806
sickbeard/search/daily.py D100 D102 D200 D400 D401
sickbeard/search/core.py D100 D202 D401 E501 F401 F821 N802 N803 N806 N812
sickbeard/search/manual.py D100 D200 D202 D205 D210 D400 D401 E501 F401 N802
sickbeard/search/proper.py D100 D101 D102 D200 D202 D400 E501 F401 N802 N812
sickbeard/search/queue.py D100 D101 D102 D103 D200 D204 D205 D210 D400 D401 E231 E501 N803
sickbeard/server/api/__init__.py D104
sickbeard/server/api/v1/core.py D100 D101 D102 D200 D201 D202 D204 D205 D208 D210 D400 D401 D403 E501 N801
sickbeard/server/api/v1/__init__.py D104
Expand Down
27 changes: 16 additions & 11 deletions sickbeard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
from sickrage.providers.GenericProvider import GenericProvider
from sickrage.system.Shutdown import Shutdown
from . import (
auto_postprocessor, dailysearcher, db, helpers, logger, metadata, naming, properFinder, providers,
scheduler, searchBacklog, search_queue, showUpdater, show_queue, subtitles, traktChecker, versionChecker
auto_postprocessor, db, helpers, logger, metadata, naming, providers,
scheduler, showUpdater, show_queue, subtitles, traktChecker, versionChecker
)
from .common import SD, SKIPPED, WANTED
from .config import (
Expand All @@ -52,6 +52,11 @@
indexer_seasonnotfound, indexer_showincomplete, indexer_shownotfound, indexer_userabort
)
from .providers import NewznabProvider, TorrentRssProvider
from .search import backlog, daily, proper
from .search.backlog import BacklogSearchScheduler, BacklogSearcher
from .search.daily import DailySearcher
from .search.proper import ProperFinder
from .search.queue import ForcedSearchQueue, SearchQueue, SnatchQueue

shutil.copyfile = shutil_custom.copyfile_custom

Expand Down Expand Up @@ -1346,30 +1351,30 @@ def initialize(consoleLogging=True): # pylint: disable=too-many-locals, too-man
start_time=datetime.time(hour=SHOWUPDATE_HOUR, minute=random.randint(0, 59)))

# snatcher used for manual search, manual picked results
manualSnatchScheduler = scheduler.Scheduler(search_queue.SnatchQueue(),
manualSnatchScheduler = scheduler.Scheduler(SnatchQueue(),
cycleTime=datetime.timedelta(seconds=3),
threadName="MANUALSNATCHQUEUE")
# searchers
searchQueueScheduler = scheduler.Scheduler(search_queue.SearchQueue(),
searchQueueScheduler = scheduler.Scheduler(SearchQueue(),
cycleTime=datetime.timedelta(seconds=3),
threadName="SEARCHQUEUE")

forcedSearchQueueScheduler = scheduler.Scheduler(search_queue.ForcedSearchQueue(),
forcedSearchQueueScheduler = scheduler.Scheduler(ForcedSearchQueue(),
cycleTime=datetime.timedelta(seconds=3),
threadName="FORCEDSEARCHQUEUE")

# TODO: update_interval should take last daily/backlog times into account!
update_interval = datetime.timedelta(minutes=DAILYSEARCH_FREQUENCY)
dailySearchScheduler = scheduler.Scheduler(dailysearcher.DailySearcher(),
dailySearchScheduler = scheduler.Scheduler(DailySearcher(),
cycleTime=update_interval,
threadName="DAILYSEARCHER",
run_delay=update_interval)

update_interval = datetime.timedelta(minutes=BACKLOG_FREQUENCY)
backlogSearchScheduler = searchBacklog.BacklogSearchScheduler(searchBacklog.BacklogSearcher(),
cycleTime=update_interval,
threadName="BACKLOG",
run_delay=update_interval)
backlogSearchScheduler = BacklogSearchScheduler(BacklogSearcher(),
cycleTime=update_interval,
threadName="BACKLOG",
run_delay=update_interval)

search_intervals = {'15m': 15, '45m': 45, '90m': 90, '4h': 4 * 60, 'daily': 24 * 60}
if CHECK_PROPERS_INTERVAL in search_intervals:
Expand All @@ -1379,7 +1384,7 @@ def initialize(consoleLogging=True): # pylint: disable=too-many-locals, too-man
update_interval = datetime.timedelta(hours=1)
run_at = datetime.time(hour=1) # 1 AM

properFinderScheduler = scheduler.Scheduler(properFinder.ProperFinder(),
properFinderScheduler = scheduler.Scheduler(ProperFinder(),
cycleTime=update_interval,
threadName="FINDPROPERS",
start_time=run_at,
Expand Down
20 changes: 13 additions & 7 deletions sickbeard/databases/main_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,13 +1189,13 @@ class TestIncreaseMajorVersion(AddMinorVersion):
"""
def test(self):
"""
Test if the version is at least 43.1
Test if the version is < 44.0
"""
return self.connection.version >= (43, 1)
return self.connection.version >= (44, 0)

def execute(self):
"""
Updates the version to 43.1
Updates the version until 44.1
"""
backupDatabase(self.connection.version)

Expand All @@ -1211,15 +1211,21 @@ class AddProperTags(TestIncreaseMajorVersion):

def test(self):
"""
Test if the version is at least 43.2
Test if the version is < 44.2
"""
return self.connection.version >= (43, 2)
return self.connection.version >= (44, 2)

def execute(self):
backupDatabase(self.checkDBVersion())
"""
Updates the version until 44.2 and adds proper_tags column
"""
backupDatabase(self.connection.version)

logger.log(u'Adding column proper_tags in history')
if not self.hasColumn('history', 'proper_tags'):
logger.log(u'Adding column proper_tags to history')
self.addColumn('history', 'proper_tags', 'TEXT', u'')

MainSanityCheck(self.connection).update_old_propers()
self.inc_minor_version()

logger.log(u'Updated to: %d.%d' % self.connection.version)
5 changes: 3 additions & 2 deletions sickbeard/failedProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import sickbeard
from sickrage.helper.exceptions import FailedPostProcessingFailedException

from . import logger, search_queue, show_name_helpers
from . import logger, show_name_helpers
from .name_parser.parser import InvalidNameException, InvalidShowException, NameParser
from .search.queue import FailedQueueItem


class FailedProcessor(object):
Expand Down Expand Up @@ -71,7 +72,7 @@ def process(self):

if segment:
self._log(u"Adding this release to failed queue: {0}".format(releaseName), logger.DEBUG)
cur_failed_queue_item = search_queue.FailedQueueItem(parsed.show, segment)
cur_failed_queue_item = FailedQueueItem(parsed.show, segment)
sickbeard.forcedSearchQueueScheduler.action.add_item(cur_failed_queue_item)

return True
Expand Down
Empty file added sickbeard/search/__init__.py
Empty file.
5 changes: 3 additions & 2 deletions sickbeard/searchBacklog.py → sickbeard/search/backlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

import sickbeard
from six import iteritems
from . import common, db, logger, scheduler, search_queue, ui
from .queue import BacklogQueueItem
from .. import common, db, logger, scheduler, ui


class BacklogSearchScheduler(scheduler.Scheduler):
Expand Down Expand Up @@ -102,7 +103,7 @@ def searchBacklog(self, which_shows=None):
for season, segment in iteritems(segments):
self.currentSearchInfo = {'title': curShow.name + " Season " + str(season)}

backlog_queue_item = search_queue.BacklogQueueItem(curShow, segment)
backlog_queue_item = BacklogQueueItem(curShow, segment)
sickbeard.searchQueueScheduler.action.add_item(backlog_queue_item) # @UndefinedVariable

if not segments:
Expand Down
4 changes: 2 additions & 2 deletions sickbeard/search.py → sickbeard/search/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
from sickrage.helper.encoding import ek
from sickrage.helper.exceptions import AuthException, ex
from sickrage.providers.GenericProvider import GenericProvider
from . import clients, common, db, failed_history, helpers, history, logger, notifiers, nzbSplitter, nzbget, sab, show_name_helpers, ui
from .common import MULTI_EP_RESULT, Quality, SEASON_RESULT, SNATCHED, SNATCHED_BEST, SNATCHED_PROPER
from .. import clients, common, db, failed_history, helpers, history, logger, notifiers, nzbSplitter, nzbget, sab, show_name_helpers, ui
from ..common import MULTI_EP_RESULT, Quality, SEASON_RESULT, SNATCHED, SNATCHED_BEST, SNATCHED_PROPER


def _downloadResult(result):
Expand Down
8 changes: 4 additions & 4 deletions sickbeard/dailysearcher.py → sickbeard/search/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
from sickrage.helper.common import try_int
from sickrage.helper.exceptions import MultipleShowObjectsException
from sickrage.show.Show import Show
from . import common, logger
from .db import DBConnection
from .network_timezones import network_dict, parse_date_time, sb_timezone, update_network_dict
from .search_queue import DailySearchQueueItem
from .queue import DailySearchQueueItem
from .. import common, logger
from ..db import DBConnection
from ..network_timezones import network_dict, parse_date_time, sb_timezone, update_network_dict


class DailySearcher(object): # pylint:disable=too-few-public-methods
Expand Down
15 changes: 8 additions & 7 deletions sickbeard/manual_search.py → sickbeard/search/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import sickbeard
from sickrage.helper.common import enabled_providers
from sickrage.show.Show import Show
from . import db, logger, search_queue
from .common import Overview, Quality, cpu_presets, statusStrings
from .queue import ForcedSearchQueueItem
from .. import db, logger
from ..common import Overview, Quality, cpu_presets, statusStrings

SEARCH_STATUS_FINISHED = "finished"
SEARCH_STATUS_QUEUED = "queued"
Expand Down Expand Up @@ -118,11 +119,11 @@ def update_finished_search_queue_item(snatch_queue_item):
"""
# Finished Searches

for search_thread in sickbeard.search_queue.FORCED_SEARCH_HISTORY:
for search_thread in sickbeard.search.queue.FORCED_SEARCH_HISTORY:
if snatch_queue_item.show and not search_thread.show.indexerid == snatch_queue_item.show.indexerid:
continue

if isinstance(search_thread, sickbeard.search_queue.ForcedSearchQueueItem):
if isinstance(search_thread, ForcedSearchQueueItem):
if not isinstance(search_thread.segment, list):
search_thread.segment = [search_thread.segment]

Expand Down Expand Up @@ -160,11 +161,11 @@ def collectEpisodesFromSearchThread(show):

# Finished Searches
searchstatus = SEARCH_STATUS_FINISHED
for search_thread in sickbeard.search_queue.FORCED_SEARCH_HISTORY:
for search_thread in sickbeard.search.queue.FORCED_SEARCH_HISTORY:
if show and not search_thread.show.indexerid == int(show):
continue

if isinstance(search_thread, sickbeard.search_queue.ForcedSearchQueueItem):
if isinstance(search_thread, ForcedSearchQueueItem):
if not [x for x in episodes if x['episodeindexid'] in [search.indexerid for search in search_thread.segment]]:
episodes += getEpisodes(search_thread, searchstatus)
else:
Expand Down Expand Up @@ -258,7 +259,7 @@ def get_provider_cache_results(indexer, show_all_results=None, perform_search=No
and episode: {1}x{2}'.format(show_obj.name, season, episode)

# make a queue item for it and put it on the queue
ep_queue_item = search_queue.ForcedSearchQueueItem(ep_obj.show, [ep_obj], bool(int(down_cur_quality)), True, manual_search_type) # pylint: disable=maybe-no-member
ep_queue_item = ForcedSearchQueueItem(ep_obj.show, [ep_obj], bool(int(down_cur_quality)), True, manual_search_type) # pylint: disable=maybe-no-member

sickbeard.forcedSearchQueueScheduler.action.add_item(ep_queue_item)

Expand Down
8 changes: 4 additions & 4 deletions sickbeard/properFinder.py → sickbeard/search/proper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
from sickrage.helper.common import enabled_providers
from sickrage.helper.exceptions import AuthException, ex
from sickrage.show.History import History
from . import db, helpers, logger
from .common import Quality, cpu_presets
from .name_parser.parser import InvalidNameException, InvalidShowException, NameParser
from .search import pickBestResult, snatchEpisode
from .. import db, helpers, logger
from ..common import Quality, cpu_presets
from ..name_parser.parser import InvalidNameException, InvalidShowException, NameParser
from ..search.core import pickBestResult, snatchEpisode


class ProperFinder(object): # pylint: disable=too-few-public-methods
Expand Down
27 changes: 16 additions & 11 deletions sickbeard/search_queue.py → sickbeard/search/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
import traceback

import sickbeard
from . import common, failed_history, generic_queue, history, logger, providers, search, ui
from .. import common, failed_history, generic_queue, history, logger, providers, ui
from ..search.core import (
searchForNeededEpisodes,
searchProviders,
snatchEpisode,
)

search_queue_lock = threading.Lock()

Expand Down Expand Up @@ -241,7 +246,7 @@ def run(self):

try:
logger.log(u"Beginning daily search for new episodes")
found_results = search.searchForNeededEpisodes()
found_results = searchForNeededEpisodes()

if not found_results:
logger.log(u"No needed episodes found")
Expand All @@ -253,7 +258,7 @@ def run(self):
result.seeders, result.leechers, result.provider.name))
else:
logger.log(u"Downloading {0} from {1}".format(result.name, result.provider.name))
self.success = search.snatchEpisode(result)
self.success = snatchEpisode(result)

# give the CPU a break
time.sleep(common.cpu_presets[sickbeard.CPU_PRESET])
Expand Down Expand Up @@ -308,8 +313,8 @@ def run(self):
format(('forced', 'manual')[bool(self.manual_search)],
('', 'season pack ')[bool(self.manual_search_type == 'season')], self.segment[0].pretty_name()))

search_result = search.searchProviders(self.show, self.segment, True, self.downCurQuality,
self.manual_search, self.manual_search_type)
search_result = searchProviders(self.show, self.segment, True, self.downCurQuality,
self.manual_search, self.manual_search_type)

if not self.manual_search and search_result:
# just use the first result for now
Expand All @@ -319,7 +324,7 @@ def run(self):
search_result[0].seeders, search_result[0].leechers, search_result[0].provider.name))
else:
logger.log(u"Downloading {0} from {1}".format(search_result[0].name, search_result[0].provider.name))
self.success = search.snatchEpisode(search_result[0])
self.success = snatchEpisode(search_result[0])

# give the CPU a break
time.sleep(common.cpu_presets[sickbeard.CPU_PRESET])
Expand Down Expand Up @@ -405,7 +410,7 @@ def run(self):
search_result.seeders, search_result.leechers, search_result.provider.name))
else:
logger.log(u"Downloading {0} from {1}".format(search_result.name, search_result.provider.name))
self.success = search.snatchEpisode(search_result)
self.success = snatchEpisode(search_result)
else:
logger.log(u"Unable to snatch release: {0}".format(search_result.name))

Expand Down Expand Up @@ -446,7 +451,7 @@ def run(self):
if not self.show.paused:
try:
logger.log(u"Beginning backlog search for: [" + self.show.name + "]")
search_result = search.searchProviders(self.show, self.segment, False, False)
search_result = searchProviders(self.show, self.segment, False, False)

if search_result:
for result in search_result:
Expand All @@ -457,7 +462,7 @@ def run(self):
result.seeders, result.leechers, result.provider.name))
else:
logger.log(u"Downloading {0} from {1}".format(result.name, result.provider.name))
self.success = search.snatchEpisode(result)
self.success = snatchEpisode(result)

# give the CPU a break
time.sleep(common.cpu_presets[sickbeard.CPU_PRESET])
Expand Down Expand Up @@ -511,7 +516,7 @@ def run(self):

# If it is wanted, self.downCurQuality doesnt matter
# if it isnt wanted, we need to make sure to not overwrite the existing ep that we reverted to!
search_result = search.searchProviders(self.show, self.segment, True, False, False)
search_result = searchProviders(self.show, self.segment, True, False, False)

if search_result:
for result in search_result:
Expand All @@ -521,7 +526,7 @@ def run(self):
result.seeders, result.leechers, result.provider.name))
else:
logger.log(u"Downloading {0} from {1}".format(result.name, result.provider.name))
self.success = search.snatchEpisode(result)
self.success = snatchEpisode(result)

# give the CPU a break
time.sleep(common.cpu_presets[sickbeard.CPU_PRESET])
Expand Down
Loading

0 comments on commit 61fc790

Please sign in to comment.