fix image verify:

- accurip.py: raise exception if accuraterip db entry not found
- program.py: verify image with only one table, remove redundant check
This commit is contained in:
Samantha Baldwin
2017-09-10 22:35:10 -04:00
parent b98cc32fd0
commit 94b9a1bbf6
5 changed files with 25 additions and 28 deletions

View File

@@ -486,10 +486,10 @@ Log files will log the path to tracks relative to this directory.
logger.debug('writing m3u file for %r', discName)
self.program.write_m3u(discName)
if self.program.verifyImage(self.runner, self.ittoc, self.itable):
print('rip verified as accurate')
else:
print('rip NOT verified as accurate')
try:
self.program.verifyImage(self.runner, self.ittoc)
except accurip.EntryNotFound:
print('AccurateRip entry not found')
accurip.print_report(self.program.result)

View File

@@ -117,16 +117,12 @@ Verifies the image from the given .cue files against the AccurateRip database.
def do(self):
prog = program.Program(config.Config())
runner = task.SyncRunner()
cache = accurip.AccuCache()
for arg in self.options.cuefile:
arg = arg.decode('utf-8')
cueImage = image.Image(arg)
cueImage.setup(runner)
url = cueImage.table.getAccurateRipURL()
responses = cache.retrieve(url)
# FIXME: this feels like we're poking at internals.
prog.cuePath = arg
prog.result = result.RipResult()
@@ -135,9 +131,14 @@ Verifies the image from the given .cue files against the AccurateRip database.
tr.number = track.number
prog.result.tracks.append(tr)
prog.verifyImage(runner, responses)
print "\n".join(prog.getAccurateRipResults()) + "\n"
verified = False
try:
verified = prog.verifyImage(runner, cueImage.table)
except accurip.EntryNotFound:
print('AccurateRip entry not found')
accurip.print_report(prog.result)
if not verified:
sys.exit(1)
class Image(BaseCommand):

View File

@@ -36,6 +36,10 @@ ACCURATERIP_URL = "http://www.accuraterip.com/accuraterip/"
_CACHE_DIR = join(directory.cache_path(), 'accurip')
class EntryNotFound(Exception):
pass
class _AccurateRipResponse(object):
"""
An AccurateRip response contains a collection of metadata identifying a
@@ -175,7 +179,8 @@ def get_db_entry(path):
if raw_entry:
_save_entry(raw_entry, cached_path)
if not raw_entry:
return None
logger.warning('entry not found in AccurateRip database')
raise EntryNotFound
return _split_responses(raw_entry)

View File

@@ -558,9 +558,9 @@ class Program:
t = image.ImageRetagTask(cueImage, taglists)
runner.run(t)
def verifyImage(self, runner, ittoc, itable):
def verifyImage(self, runner, table):
"""
verify ittoc against accuraterip and cue_path track lengths
verify table against accuraterip and cue_path track lengths
Verify our image against the given AccurateRip responses.
Needs an initialized self.result.
@@ -576,19 +576,9 @@ class Program:
logger.error(verifytask.exceptionMessage)
return False
responses = accurip.get_db_entry(ittoc.accuraterip_path())
if not responses:
logger.warning('album not found in AccurateRip database')
return False
responses = accurip.get_db_entry(table.accuraterip_path())
logger.info('%d AccurateRip response(s) found' % len(responses))
for r in responses:
if r.cddbDiscId != itable.getCDDBDiscId():
logger.error(
'AccurateRip response discid differs: %s' % r.cddbDiscId
)
return False
checksums = accurip.calculate_checksums([
os.path.join(os.path.dirname(self.cuePath), t.indexes[1].path)
for t in filter(lambda t: t.number != 0, cueImage.cue.table.tracks)

View File

@@ -12,7 +12,7 @@ from unittest import TestCase
from whipper.common import accurip
from whipper.common.accurip import (
calculate_checksums, get_db_entry, print_report, verify_result,
_split_responses
_split_responses, EntryNotFound
)
from whipper.result.result import RipResult, TrackResult
@@ -45,8 +45,9 @@ class TestAccurateRipResponse(TestCase):
# ask cache for other entry and assert cached entry equals normal entry
self.assertEquals(self.entry, get_db_entry(self.other_path))
def test_returns_none_for_no_entry(self):
self.assertIsNone(get_db_entry('definitely_a_404'))
def test_raises_entrynotfound_for_no_entry(self):
with self.assertRaises(EntryNotFound):
get_db_entry('definitely_a_404')
def test_can_return_entry_without_saving(self):
chmod(self.cache_dir, 0)