Skip to content

Commit

Permalink
Drop whipper caching (#336)
Browse files Browse the repository at this point in the history
Whipper's caching implementation causes a few issues (#196, #230, [#321 (comment)](#321 (comment))) and complicates the code: it's better to drop this feature.

The rip resume feature doesn't work anymore: if possible it will be restored in the future.

* Remove caching item from TODO
* Delete unneeded files related to caching
* Update 'common/directory.py' & 'test/test_common_directory.py' (caching removal)
* Update 'common/accurip.py' & 'test/test_common_accurip.py' (caching removal)
* Update 'common/program.py' (caching removal)
* Update 'command/cd.py' (caching removal)

This fixes #335, fixes #196 and fixes #230.

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
  • Loading branch information
JoeLametta authored Sep 17, 2020
1 parent 4b5b6e5 commit 3acc3ff
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 368 deletions.
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ MEDIUM

- retry cdrdao a few times when it had to load the tray

- getting cache results should depend on same drive/offset

- do some character mangling so trail of dead is not in a hidden dir

HARD
Expand Down
5 changes: 0 additions & 5 deletions whipper/command/cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def do(self):
self.ittoc = self.program.getFastToc(self.runner, self.device)

# already show us some info based on this
self.program.getRipResult(self.ittoc.getCDDBDiscId())
print("CDDB disc id: %s" % self.ittoc.getCDDBDiscId())
self.mbdiscid = self.ittoc.getMusicBrainzDiscId()
print("MusicBrainz disc id %s" % self.mbdiscid)
Expand Down Expand Up @@ -499,8 +498,6 @@ def _ripIfNotRipped(number):
self.itable.setFile(number, 1, trackResult.filename,
self.itable.getTrackLength(number), number)

self.program.saveRipResult()

# check for hidden track one audio
htoa = self.program.getHTOA()
if htoa:
Expand Down Expand Up @@ -541,8 +538,6 @@ def _ripIfNotRipped(number):

accurip.print_report(self.program.result)

self.program.saveRipResult()

self.program.writeLog(discName, self.logger)


Expand Down
29 changes: 2 additions & 27 deletions whipper/common/accurip.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@

import struct
import whipper
from os import makedirs
from os.path import dirname, exists, join
from urllib.error import URLError, HTTPError
from urllib.request import urlopen, Request

from whipper.common import directory
from whipper.program.arc import accuraterip_checksum

import logging
logger = logging.getLogger(__name__)


ACCURATERIP_URL = "http://www.accuraterip.com/accuraterip/"
_CACHE_DIR = join(directory.cache_path(), 'accurip')


class EntryNotFound(Exception):
Expand Down Expand Up @@ -142,34 +138,13 @@ def _download_entry(path):
logger.error('error retrieving AccurateRip entry: %s', e)


def _save_entry(raw_entry, path):
logger.debug('saving AccurateRip entry to %s', path)
try:
makedirs(dirname(path), exist_ok=True)
except OSError as e:
logger.error('could not save entry to %s: %s', path, e)
return
with open(path, 'wb') as f:
f.write(raw_entry)


def get_db_entry(path):
"""
Retrieve cached AccurateRip disc entry as array of _AccurateRipResponses.
Downloads entry from accuraterip.com on cache fault.
Download entry from accuraterip.com.
``path`` is in the format of the output of ``table.accuraterip_path()``.
"""
cached_path = join(_CACHE_DIR, path)
if exists(cached_path):
logger.debug('found accuraterip entry at %s', cached_path)
with open(cached_path, 'rb') as f:
raw_entry = f.read()
else:
raw_entry = _download_entry(path)
if raw_entry:
_save_entry(raw_entry, cached_path)
raw_entry = _download_entry(path)
if not raw_entry:
logger.warning('entry not found in AccurateRip database')
raise EntryNotFound
Expand Down
218 changes: 0 additions & 218 deletions whipper/common/cache.py

This file was deleted.

9 changes: 0 additions & 9 deletions whipper/common/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ def config_path():
return join(path, 'whipper.conf')


def cache_path(name=None):
path = join(getenv('XDG_CACHE_HOME') or join(expanduser('~'), '.cache'),
'whipper')
if name:
path = join(path, name)
makedirs(path, exist_ok=True)
return path


def data_path(name=None):
path = join(getenv('XDG_DATA_HOME') or
join(expanduser('~'), '.local/share'),
Expand Down
Loading

0 comments on commit 3acc3ff

Please sign in to comment.