def setUp(self): """Set up tests.""" super(SceneExceptionTestCase, self).setUp() scene_exceptions.retrieve_exceptions() # Make sure cache has been created scene_exceptions.refresh_exceptions_cache()
def setUp(self): """Set up tests.""" super(SceneExceptionTestCase, self).setUp() scene_exceptions.retrieve_exceptions() # Make sure cache has been created scene_exceptions.refresh_exceptions_cache()
def test_scene_ex_reset_name_cache(self): # clear the exceptions test_cache_db_con = db.DBConnection('cache.db') test_cache_db_con.action("DELETE FROM scene_exceptions") # put something in the cache name_cache.addNameToCache('Cached Name', 0) # updating should not clear the cache this time since our exceptions didn't change scene_exceptions.retrieve_exceptions() self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), 0)
def test_scene_ex_reset_name_cache(self): # clear the exceptions test_cache_db_con = db.DBConnection('cache.db') test_cache_db_con.action("DELETE FROM scene_exceptions") # put something in the cache name_cache.addNameToCache('Cached Name', 0) # updating should not clear the cache this time since our exceptions didn't change scene_exceptions.retrieve_exceptions() self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), (0, 0))
def build_name_cache(series_obj=None): """Build internal name cache. :param series_obj: Specify series to build name cache for, if None, just do all series :param force: Force the build name cache. Do not depend on the scene_exception_refresh table. """ def _cache_name(cache_series_obj): """Build the name cache for a single show.""" clear_cache(cache_series_obj.indexer, cache_series_obj.series_id) series_identifier = (cache_series_obj.indexer, cache_series_obj.series_id) scene_exceptions = exceptions_cache[series_identifier].copy() names = { full_sanitize_scene_name(name): series_identifier for season_exceptions in itervalues(scene_exceptions) for name in season_exceptions } # Add original name to name cache series_name = full_sanitize_scene_name(cache_series_obj.name) names[series_name] = series_identifier # Add scene exceptions to name cache name_cache.update(names) log.debug(u'Internal name cache for {series} set to: {names}', { 'series': series_name, 'names': u', '.join(list(names)) }) with nameCacheLock: retrieve_exceptions() # Create cache from db for the scene_exceptions. refresh_exceptions_cache() if not series_obj: log.info(u'Building internal name cache for all shows') for show in app.showList: _cache_name(show) else: log.info(u'Building internal name cache for {series}', {'series': series_obj.name}) _cache_name(series_obj)
def build_name_cache(show=None): """Build internal name cache. :param show: Specify show to build name cache for, if None, just do all shows :param force: Force the build name cache. Do not depend on the scene_exception_refresh table. """ def _cache_name(show): """Build the name cache for a single show.""" indexer_id = show.indexerid clear_cache(indexer_id) scene_exceptions = exceptions_cache[indexer_id].copy() names = { full_sanitize_scene_name(name): int(indexer_id) for season_exceptions in scene_exceptions.values() for name in season_exceptions } # Add original name to name cache show_name = full_sanitize_scene_name(show.name) names[show_name] = indexer_id # Add scene exceptions to name cache name_cache.update(names) log.debug(u'Internal name cache for {show} set to: {names}', { 'show': show.name, 'names': ', '.join(names.keys()) }) with nameCacheLock: retrieve_exceptions() # Create cache from db for the scene_exceptions. refresh_exceptions_cache() if not show: log.info(u'Building internal name cache for all shows') for show in app.showList: _cache_name(show) else: log.info(u'Building internal name cache for {show}', {'show': show.name}) _cache_name(show)
def build_name_cache(series_obj=None): """Build internal name cache. :param series_obj: Specify series to build name cache for, if None, just do all series :param force: Force the build name cache. Do not depend on the scene_exception_refresh table. """ def _cache_name(cache_series_obj): """Build the name cache for a single show.""" clear_cache(cache_series_obj.indexer, cache_series_obj.series_id) series_identifier = (cache_series_obj.indexer, cache_series_obj.series_id) scene_exceptions = exceptions_cache[series_identifier].copy() names = { full_sanitize_scene_name(name): series_identifier for season_exceptions in itervalues(scene_exceptions) for name in season_exceptions } # Add original name to name cache series_name = full_sanitize_scene_name(cache_series_obj.name) names[series_name] = series_identifier # Add scene exceptions to name cache name_cache.update(names) log.debug(u'Internal name cache for {series} set to: {names}', { 'series': series_name, 'names': u', '.join(list(names)) }) with name_cache_lock: retrieve_exceptions() # Create cache from db for the scene_exceptions. refresh_exceptions_cache() if not series_obj: log.info(u'Building internal name cache for all shows') for show in app.showList: _cache_name(show) else: log.info(u'Building internal name cache for {series}', {'series': series_obj.name}) _cache_name(series_obj)
def post(self, identifier): """Refresh all scene exception types.""" types = { 'local': 'custom_exceptions', 'xem': 'xem', 'anidb': 'anidb', 'all': None, } if identifier not in types: return self._not_found('Alias source not found') data = json_decode(self.request.body) if not data or not all([data.get('type')]) and len(data) != 1: return self._bad_request('Invalid request body') if data['type'] == 'REFRESH': retrieve_exceptions(force=True, exception_type=types[identifier]) data['creation'] = datetime.utcnow().isoformat()[:-3] + 'Z' return self._created(data=data) return self._bad_request('Operation not supported')
def http_post(self, identifier): """Refresh all scene exception types.""" types = { 'local': 'custom_exceptions', 'xem': 'xem', 'anidb': 'anidb', 'all': None, } if identifier not in types: return self._not_found('Alias source not found') data = json_decode(self.request.body) if not data or not all([data.get('type')]) and len(data) != 1: return self._bad_request('Invalid request body') if data['type'] == 'REFRESH': retrieve_exceptions(force=True, exception_type=types[identifier]) data['creation'] = datetime.utcnow().isoformat()[:-3] + 'Z' return self._created(data=data) return self._bad_request('Operation not supported')