Beispiel #1
0
def configure(cache_dir, replace=False):
    """Configure caches."""
    # memory cache
    from subliminal.cache import region as subliminal_cache

    memory_cache.configure('dogpile.cache.memory', expiration_time=timedelta(hours=1))

    # subliminal cache
    subliminal_cache.configure('dogpile.cache.dbm', replace_existing_backend=replace,
                               expiration_time=timedelta(days=30),
                               arguments={
                                   'filename': os.path.join(cache_dir, 'subliminal.dbm'),
                                   'lock_factory': MutexLock})

    # application cache
    cache.configure('dogpile.cache.dbm', replace_existing_backend=replace,
                    expiration_time=timedelta(days=1),
                    arguments={'filename': os.path.join(cache_dir, 'application.dbm'),
                               'lock_factory': MutexLock})

    # recommended series cache
    recommended_series_cache.configure('dogpile.cache.dbm', replace_existing_backend=replace,
                                       expiration_time=timedelta(days=7),
                                       arguments={'filename': os.path.join(cache_dir, 'recommended.dbm'),
                                                  'lock_factory': MutexLock})

    # anidb (adba) series cache
    anidb_cache.configure('dogpile.cache.dbm', replace_existing_backend=replace,
                          expiration_time=timedelta(days=3),
                          arguments={'filename': os.path.join(cache_dir, 'anidb.dbm'),
                                     'lock_factory': MutexLock})
Beispiel #2
0
def run(args):
    opts = get_opts(args)

    env.load(data_dir = opts.data_dir, config_file = opts.config_file)

    if not os.path.isdir(env.paths.data_dir):
        os.makedirs(env.paths.data_dir)

    if not os.path.isdir(env.paths.logs_dir):
        os.makedirs(env.paths.logs_dir)

    init_logging(logging.DEBUG)

    logger.info("Starting up...")

    logger.info("subliminal cache at '%s'", env.paths.cache_file)
    from subliminal.cache import region
    region.configure('dogpile.cache.dbm', expiration_time=timedelta(days=30),
                     arguments={'filename': env.paths.cache_file})

    logger.info("Spawning check_for_better async loop")
    IOLoop.current().spawn_callback(check_for_better)

    try:
        run_server()
    except KeyboardInterrupt:
        logger.info("Shutting down...")
        pass
def test_fill_addic7ed_show_id_cache(monkeypatch):
    # Use subliminal cache (not our own cache since the provider cache is used from within subliminal)
    filename = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'resources', 'test.subliminal.cache.dbm'))
    region.configure(backend='dogpile.cache.dbm', arguments={'filename': filename, 'lock_factory': MutexLock})
    monkeypatch.setattr('autosubliminal.ADDIC7EDSHOWNAMEMAPPING', {'show1': 1, 'show2': 2})
    fill_addic7ed_show_id_cache()
    assert region.get(ADDIC7ED_SEARCH_SHOW_ID_CACHE_PREFIX + '|show1') == 1
    assert region.get(CUSTOM_ADDIC7ED_SEARCH_SHOW_ID_CACHE_PREFIX + '|show1') == 1
    assert region.get(ADDIC7ED_SEARCH_SHOW_ID_CACHE_PREFIX + '|show2') == 2
    assert region.get(CUSTOM_ADDIC7ED_SEARCH_SHOW_ID_CACHE_PREFIX + '|show2') == 2
    assert not region.get('unknown')
Beispiel #4
0
def configure_subtitles_cache():
    """
    Configure the subliminal cache settings.
    Should be called once when the program starts.
    """
    # Configure the subliminal cache.
    cache_dir = dirs.user_cache_dir
    if not os.path.exists(cache_dir):
        os.makedirs(cache_dir)
    cache_file_path = os.path.join(cache_dir, cache_file)
    region.configure('dogpile.cache.dbm',
                     expiration_time=datetime.timedelta(days=30),
                     arguments={
                         'filename': cache_file_path,
                         'lock_factory': MutexLock
                     })
Beispiel #5
0
def _initialize_subliminal():
    """
    Initialize subliminal.
    This must always be done AFTER the registration of our fake_entry_points.
    Therefore the imports must be done here, otherwise the 'subliminal.providers' entry point is already initialized
    before we could register it ourselves.
    -> see subliminal.api.provider_manager
    """

    # Imports
    from subliminal.cache import region
    from subliminal.cli import MutexLock

    # Configure subliminal/dogpile cache
    # Use MutexLock otherwise some providers will not work due to fcntl module import error in windows
    # Do not reconfigure after a soft restart (without exiting main app) -> otherwise RegionAlreadyConfigured exception
    if not region.is_configured:
        cache_file = os.path.abspath(os.path.expanduser('subliminal.cache.dbm'))
        region.configure(backend='dogpile.cache.dbm', arguments={'filename': cache_file, 'lock_factory': MutexLock})
Beispiel #6
0
def configure(cache_dir):
    """Configure caches."""
    # memory cache
    from subliminal.cache import region as subliminal_cache

    memory_cache.configure('dogpile.cache.memory', expiration_time=timedelta(hours=1))

    # subliminal cache
    subliminal_cache.configure('dogpile.cache.dbm',
                               expiration_time=timedelta(days=30),
                               arguments={
                                   'filename': os.path.join(cache_dir, 'subliminal.dbm'),
                                   'lock_factory': MutexLock})

    # application cache
    cache.configure('dogpile.cache.dbm',
                    expiration_time=timedelta(days=1),
                    arguments={'filename': os.path.join(cache_dir, 'application.dbm'),
                               'lock_factory': MutexLock})
Beispiel #7
0
def _initialize_subliminal():
    """
    Initialize subliminal.
    This must always be done AFTER the registration of our fake_entry_points.
    Therefore the imports must be done here, otherwise the 'subliminal.providers' entry point is already initialized
    before we could register it ourselves.
    -> see subliminal.api.provider_manager
    """

    # Imports
    from subliminal.cache import region
    from subliminal.cli import MutexLock

    # Configure subliminal/dogpile cache
    # Use MutexLock otherwise some providers will not work due to fcntl module import error in windows
    # Do not reconfigure after a soft restart (without exiting main app) -> otherwise RegionAlreadyConfigured exception
    if not region.is_configured:
        cache_file = os.path.abspath(
            os.path.expanduser('subliminal.cache.dbm'))
        region.configure(backend='dogpile.cache.dbm',
                         arguments={
                             'filename': cache_file,
                             'lock_factory': MutexLock
                         })
Beispiel #8
0
def configure_region():
    region.configure('dogpile.cache.null')
    region.configure = Mock()
Beispiel #9
0
def configure_region():
    region.configure('dogpile.cache.null')
    region.configure = Mock()