From 94b9a1bbf64802e8ddc6209bd0d571eae2d02da1 Mon Sep 17 00:00:00 2001 From: Samantha Baldwin Date: Sun, 10 Sep 2017 22:35:10 -0400 Subject: [PATCH] fix image verify: - accurip.py: raise exception if accuraterip db entry not found - program.py: verify image with only one table, remove redundant check --- whipper/command/cd.py | 8 ++++---- whipper/command/image.py | 15 ++++++++------- whipper/common/accurip.py | 7 ++++++- whipper/common/program.py | 16 +++------------- whipper/test/test_common_accurip.py | 7 ++++--- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/whipper/command/cd.py b/whipper/command/cd.py index 6a03b84..c7b7569 100644 --- a/whipper/command/cd.py +++ b/whipper/command/cd.py @@ -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) diff --git a/whipper/command/image.py b/whipper/command/image.py index 510a56b..25d4f6d 100644 --- a/whipper/command/image.py +++ b/whipper/command/image.py @@ -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): diff --git a/whipper/common/accurip.py b/whipper/common/accurip.py index 031d232..0c6c1eb 100644 --- a/whipper/common/accurip.py +++ b/whipper/common/accurip.py @@ -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) diff --git a/whipper/common/program.py b/whipper/common/program.py index 613b4a7..934f983 100644 --- a/whipper/common/program.py +++ b/whipper/common/program.py @@ -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) diff --git a/whipper/test/test_common_accurip.py b/whipper/test/test_common_accurip.py index 61baf32..316ab93 100644 --- a/whipper/test/test_common_accurip.py +++ b/whipper/test/test_common_accurip.py @@ -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)