deflake, remove morituri hack, more error handling

This commit is contained in:
Samantha Baldwin
2017-09-04 21:55:05 -04:00
parent 007dc0729e
commit 83729ef7f3
10 changed files with 27 additions and 30 deletions

View File

@@ -22,14 +22,12 @@ import argparse
import cdio
import os
import glob
import urllib2
import socket
import sys
import logging
import gobject
from whipper.command.basecommand import BaseCommand
from whipper.common import (
accurip, common, config, drive, program, task
accurip, config, drive, program, task
)
from whipper.program import cdrdao, cdparanoia, utils
from whipper.result import result
@@ -145,16 +143,6 @@ class _CD(BaseCommand):
"--cdr not passed")
return -1
# FIXME ?????
# Hackish fix for broken commit
offset = 0
info = drive.getDeviceInfo(self.device)
if info:
try:
offset = self.config.getReadOffset(*info)
except KeyError:
pass
# now, read the complete index table, which is slower
self.itable = self.program.getTable(self.runner,
self.ittoc.getCDDBDiscId(),
@@ -345,8 +333,11 @@ Log files will log the path to tracks relative to this directory.
if os.path.exists(dirname):
logs = glob.glob(os.path.join(dirname, '*.log'))
if logs:
bye("output directory %s is a finished rip" %
dirname.encode('utf-8'))
msg = ("output directory %s is a finished rip" %
dirname.encode('utf-8'))
logger.critical(msg)
raise RuntimeError(msg)
exit
else:
sys.stdout.write("output directory %s already exists\n" %
dirname.encode('utf-8'))

View File

@@ -36,8 +36,13 @@ def main():
cmd.options.eject in ('failure', 'always')):
eject_device(e.device)
return 255
except RuntimeError, e:
print(e)
return 1
except KeyboardInterrupt:
return 2
except ImportError, e:
raise ImportError(e)
raise
except task.TaskException, e:
if isinstance(e.exception, ImportError):
raise ImportError(e.exception)

View File

@@ -28,7 +28,6 @@ from whipper.command.basecommand import BaseCommand
from whipper.common import accurip, common, config, drive
from whipper.common import task as ctask
from whipper.program import arc, cdrdao, cdparanoia, utils
from whipper.common import checksum
from whipper.extern.task import task
gobject.threads_init()

View File

@@ -34,6 +34,7 @@ logger = logging.getLogger(__name__)
_CACHE_DIR = join(directory.cache_path(), 'accurip')
class _AccurateRipResponse(object):
"""
An AccurateRip response contains a collection of metadata identifying a
@@ -144,6 +145,7 @@ def _download_entry(path):
return None
return resp.content
def _save_entry(raw_entry, path):
logger.debug('saving AccurateRip entry to %s', path)
# XXX: os.makedirs(exist_ok=True) in py3
@@ -155,6 +157,7 @@ def _save_entry(raw_entry, path):
return
open(path, 'wb').write(raw_entry)
def get_db_entry(path):
"""
Retrieve cached AccurateRip disc entry as array of _AccurateRipResponses.
@@ -184,6 +187,7 @@ def _assign_checksums_and_confidences(tracks, checksums, responses):
key=lambda t: t[0]
)
def _match_responses(tracks, responses):
"""
Match and save track accuraterip response checksums against
@@ -203,13 +207,14 @@ def _match_responses(tracks, responses):
'track %d matched response %s in AccurateRip'
' database: %s crc %s confidence %s' %
(i, r.cddbDiscId, v, track.AR[v]['DBCRC'],
track.AR[v]['DBConfidence'])
track.AR[v]['DBConfidence'])
)
return any((
all([t.AR['v1']['DBCRC'] for t in tracks]),
all([t.AR['v2']['DBCRC'] for t in tracks])
))
def verify_result(result, responses, checksums):
"""
Verify track AccurateRip checksums against database responses.

View File

@@ -24,8 +24,6 @@ import wave
from whipper.extern.task import task as etask
from whipper.program.arc import accuraterip_checksum
import logging
logger = logging.getLogger(__name__)

View File

@@ -613,10 +613,9 @@ class Program:
common.FRAMES_PER_SECOND)
for i, track in enumerate(self.result.tracks):
path = track.filename
writeFile(track.filename,
(self.result.table.getTrackLength(i + 1) /
common.FRAMES_PER_SECOND))
(self.result.table.getTrackLength(i + 1) /
common.FRAMES_PER_SECOND))
def writeCue(self, discName):
assert self.result.table.canCue()

View File

@@ -26,7 +26,6 @@ import os
from whipper.common import encode
from whipper.common import common
from whipper.common import checksum
from whipper.image import cue, table
from whipper.extern.task import task
from whipper.program.soxi import AudioLengthTask

View File

@@ -6,10 +6,12 @@ logger = logging.getLogger(__name__)
ARB = 'accuraterip-checksum'
FLAC = 'flac'
def _execute(cmd, **redirects):
logger.debug('executing %r', cmd)
return Popen(cmd, **redirects)
def accuraterip_checksum(f, track_number, total_tracks, wave=False, v2=False):
v = '--accuraterip-v1'
if v2:

View File

@@ -29,6 +29,7 @@ class TestAccurateRipResponse(TestCase):
def setUp(self):
self.cache_dir = mkdtemp(suffix='whipper_accurip_cache_test')
accurip._CACHE_DIR = self.cache_dir
def cleanup(cachedir):
chmod(cachedir, 0755)
rmtree(cachedir)
@@ -83,9 +84,9 @@ class TestAccurateRipResponse(TestCase):
# XXX: test arc.py
class TestCalculateChecksums(TestCase):
def test_returns_none_for_bad_files(self):
paths = ['/does/not/exist']
self.assertEquals(
calculate_checksums(['/does/not/exist']),
{'v1': [None], 'v2': [None]}
@@ -93,6 +94,7 @@ class TestCalculateChecksums(TestCase):
# TODO: test success when file exists
class TestVerifyResult(TestCase):
@classmethod
def setUpClass(cls):
@@ -221,6 +223,7 @@ class TestVerifyResult(TestCase):
'DBMaxConfidenceCRC': '9cc1f32e',
})
class TestAccurateRipReport(TestCase):
def setUp(self):
sys.stdout = StringIO()

View File

@@ -2,13 +2,9 @@
# vi:si:et:sw=4:sts=4:ts=4
import os
import pickle
import unittest
from whipper.result import result
from whipper.common import program, accurip, mbngs, config
from whipper.common import program, mbngs, config
from whipper.command.cd import DEFAULT_DISC_TEMPLATE