* morituri/program/cdparanoia.py:
* morituri/test/test_program_cdparanoia.py: Add a task that can analyze the drive for whether it defeats the audio cache. * morituri/result/result.py: * morituri/rip/cd.py: Make it possible to store whether a drive defeats audio cache in the result. * morituri/rip/drive.py: Add rip drive analyze command to analyze caching of a drive, and store it in the config.
This commit is contained in:
14
ChangeLog
14
ChangeLog
@@ -1,3 +1,17 @@
|
||||
2012-12-04 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/program/cdparanoia.py:
|
||||
* morituri/test/test_program_cdparanoia.py:
|
||||
Add a task that can analyze the drive for whether it defeats
|
||||
the audio cache.
|
||||
* morituri/result/result.py:
|
||||
* morituri/rip/cd.py:
|
||||
Make it possible to store whether a drive defeats audio cache
|
||||
in the result.
|
||||
* morituri/rip/drive.py:
|
||||
Add rip drive analyze command to analyze caching of a drive,
|
||||
and store it in the config.
|
||||
|
||||
2012-12-04 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/common/task.py:
|
||||
|
||||
@@ -30,6 +30,7 @@ import subprocess
|
||||
import tempfile
|
||||
|
||||
from morituri.common import log, common
|
||||
from morituri.common import task as ctask
|
||||
|
||||
from morituri.extern import asyncsub
|
||||
from morituri.extern.task import task
|
||||
@@ -562,3 +563,45 @@ def getCdParanoiaVersion():
|
||||
raise
|
||||
|
||||
return version
|
||||
|
||||
|
||||
_OK_RE = re.compile(r'Drive tests OK with Paranoia.')
|
||||
|
||||
|
||||
class AnalyzeTask(ctask.PopenTask):
|
||||
|
||||
logCategory = 'AnalyzeTask'
|
||||
description = 'Analyzing drive caching behaviour'
|
||||
|
||||
defeatsCache = None
|
||||
|
||||
cwd = None
|
||||
|
||||
_output = []
|
||||
|
||||
def __init__(self, device=None):
|
||||
# cdparanoia -A *always* writes cdparanoia.log
|
||||
self.cwd = tempfile.mkdtemp(suffix='.morituri.cache')
|
||||
self.command = ['cdparanoia', '-A']
|
||||
if device:
|
||||
self.command += ['-d', device]
|
||||
|
||||
def commandMissing(self):
|
||||
raise common.MissingDependencyException('cdparanoia')
|
||||
|
||||
def readbyteserr(self, bytes):
|
||||
self._output.append(bytes)
|
||||
|
||||
def done(self):
|
||||
if self.cwd:
|
||||
shutil.rmtree(self.cwd)
|
||||
output = "".join(self._output)
|
||||
m = _OK_RE.search(output)
|
||||
if m:
|
||||
self.defeatsCache = True
|
||||
else:
|
||||
self.defeatsCache = False
|
||||
|
||||
def failed(self):
|
||||
if self.cwd:
|
||||
shutil.rmtree(self.cwd)
|
||||
|
||||
@@ -103,6 +103,7 @@ class RipResult:
|
||||
|
||||
cdrdaoVersion = None
|
||||
cdparanoiaVersion = None
|
||||
cdparanoiaDefeatsCache = None
|
||||
|
||||
gstreamerVersion = None
|
||||
gstPythonVersion = None
|
||||
|
||||
@@ -214,6 +214,13 @@ Log files will log the path to tracks relative to this directory.
|
||||
|
||||
prog.result.cdrdaoVersion = version
|
||||
prog.result.cdparanoiaVersion = cdparanoia.getCdParanoiaVersion()
|
||||
info = drive.getDeviceInfo(self.parentCommand.options.device)
|
||||
if info:
|
||||
try:
|
||||
prog.result.cdparanoiaDefeatsCache = self.getRootCommand(
|
||||
).config.getDefeatsCache(*info)
|
||||
except KeyError:
|
||||
pass
|
||||
prog.result.offset = int(self.options.offset)
|
||||
prog.result.artist = prog.metadata and prog.metadata.artist \
|
||||
or 'Unknown Artist'
|
||||
|
||||
@@ -20,7 +20,61 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with morituri. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
|
||||
from morituri.extern.task import task
|
||||
|
||||
from morituri.common import logcommand, drive
|
||||
from morituri.program import cdparanoia
|
||||
|
||||
|
||||
class Analyze(logcommand.LogCommand):
|
||||
|
||||
summary = "analyze caching behaviour of drive"
|
||||
|
||||
def addOptions(self):
|
||||
self.parser.add_option('-d', '--device',
|
||||
action="store", dest="device",
|
||||
help="CD-DA device")
|
||||
|
||||
def handleOptions(self, options):
|
||||
if not options.device:
|
||||
drives = drive.getAllDevicePaths()
|
||||
if not drives:
|
||||
self.error('No CD-DA drives found!')
|
||||
return 3
|
||||
|
||||
# pick the first
|
||||
self.options.device = drives[0]
|
||||
|
||||
# this can be a symlink to another device
|
||||
self.options.device = os.path.realpath(self.options.device)
|
||||
|
||||
def do(self, args):
|
||||
runner = task.SyncRunner()
|
||||
t = cdparanoia.AnalyzeTask(self.options.device)
|
||||
runner.run(t)
|
||||
|
||||
if t.defeatsCache is None:
|
||||
self.stdout.write(
|
||||
'Cannot analyze the drive. Is there a CD in it?\n')
|
||||
return
|
||||
if not t.defeatsCache:
|
||||
self.stdout.write(
|
||||
'cdparanoia cannot defeat the audio cache on this drive.\n')
|
||||
else:
|
||||
self.stdout.write(
|
||||
'cdparanoia can defeat the audio cache on this drive.\n')
|
||||
|
||||
info = drive.getDeviceInfo(self.options.device)
|
||||
if not info:
|
||||
return
|
||||
|
||||
self.stdout.write(
|
||||
'Adding drive cache behaviour to configuration file.\n')
|
||||
|
||||
self.getRootCommand().config.setDefeatsCache(info[0], info[1], info[2],
|
||||
t.defeatsCache)
|
||||
|
||||
|
||||
class List(logcommand.LogCommand):
|
||||
@@ -66,4 +120,4 @@ class Drive(logcommand.LogCommand):
|
||||
|
||||
summary = "handle drives"
|
||||
|
||||
subCommandClasses = [List, ]
|
||||
subCommandClasses = [Analyze, List, ]
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from morituri.extern.task import task
|
||||
|
||||
from morituri.program import cdparanoia
|
||||
|
||||
from morituri.test import common
|
||||
|
||||
class ParseTestCase(unittest.TestCase):
|
||||
|
||||
class ParseTestCase(common.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# report from Afghan Whigs - Sweet Son Of A Bitch
|
||||
@@ -25,7 +28,7 @@ class ParseTestCase(unittest.TestCase):
|
||||
self.assertEquals(q, '99.7 %')
|
||||
|
||||
|
||||
class ErrorTestCase(unittest.TestCase):
|
||||
class ErrorTestCase(common.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# report from a rip with offset -1164 causing scsi errors
|
||||
@@ -43,7 +46,29 @@ class ErrorTestCase(unittest.TestCase):
|
||||
self.assertEquals(q, '79.6 %')
|
||||
|
||||
|
||||
class VersionTestCase(unittest.TestCase):
|
||||
class VersionTestCase(common.TestCase):
|
||||
|
||||
def testGetVersion(self):
|
||||
self.failUnless(cdparanoia.getCdparanoiaVersion())
|
||||
self.failUnless(cdparanoia.getCdParanoiaVersion())
|
||||
|
||||
|
||||
class AnalyzeFileTask(cdparanoia.AnalyzeTask):
|
||||
|
||||
def __init__(self, path):
|
||||
self.command = ['cat', path]
|
||||
|
||||
def readbytesout(self, bytes):
|
||||
self.readbyteserr(bytes)
|
||||
|
||||
|
||||
class CacheTestCase(common.TestCase):
|
||||
|
||||
def testDefeatsCache(self):
|
||||
self.runner = task.SyncRunner(verbose=False)
|
||||
|
||||
path = os.path.join(os.path.dirname(__file__),
|
||||
'cdparanoia', 'PX-L890SA.cdparanoia-A.stderr')
|
||||
t = AnalyzeFileTask(path)
|
||||
self.runner.run(t)
|
||||
self.failUnless(t.defeatsCache)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user