get version for cdrdao too.

Add debug commands: rip debug version cdrdao/cdparanoia
This commit is contained in:
Thomas Vander Stichele
2013-07-13 11:31:27 +02:00
parent cc2ee6ba07
commit 7813103a4d
7 changed files with 106 additions and 25 deletions

View File

@@ -24,8 +24,9 @@
import os
import os.path
import math
import subprocess
from morituri.extern import asyncsub
from morituri.extern.log import log
FRAMES_PER_SECOND = 75
@@ -288,3 +289,44 @@ def getRelativePath(targetPath, collectionPath):
'getRelativePath: target and collection in different dir, %r' %
rel)
return os.path.join(rel, os.path.basename(targetPath))
class VersionGetter(object):
"""
I get the version of a program by looking for it in command output
according to a regexp.
"""
def __init__(self, dependency, args, regexp, expander):
"""
@param dependency: name of the dependency providing the program
@param args: the arguments to invoke to show the version
@type args: list of str
@param regexp: the regular expression to get the version
@param expander: the expansion string for the version using the
regexp group dict
"""
self._dep = dependency
self._args = args
self._regexp = regexp
self._expander = expander
def get(self):
version = "(Unknown)"
try:
p = asyncsub.Popen(self._args,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
output = asyncsub.recv_some(p, e=0, stderr=1)
vre = self._regexp.search(output)
if vre:
version = self._expander % vre.groupdict()
except OSError, e:
import errno
if e.errno == errno.ENOENT:
raise MissingDependencyException(self._dep)
raise
return version

View File

@@ -550,25 +550,12 @@ _VERSION_RE = re.compile(
def getCdParanoiaVersion():
version = "(Unknown)"
getter = common.VersionGetter('cdparanoia',
["cdparanoia", "-V"],
_VERSION_RE,
"%(version)s %(release)s")
try:
p = asyncsub.Popen(["cdparanoia", "-V"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
version = asyncsub.recv_some(p, e=0, stderr=1)
vre = _VERSION_RE.search(version)
if vre and len(vre.groups()) == 2:
version = "%s %s" % (
vre.groupdict().get('version'),
vre.groupdict().get('release'))
except OSError, e:
import errno
if e.errno == errno.ENOENT:
raise common.MissingDependencyException('cdparanoia')
raise
return version
return getter.get()
_OK_RE = re.compile(r'Drive tests OK with Paranoia.')

View File

@@ -507,3 +507,16 @@ class ProgramFailedException(Exception):
def __init__(self, code):
self.code = code
self.args = (code, )
_VERSION_RE = re.compile(
"^Cdrdao version (?P<version>.+) -")
def getCDRDAOVersion():
getter = common.VersionGetter('cdrdao',
["cdrdao"],
_VERSION_RE,
"%(version)s")
return getter.get()

View File

@@ -117,8 +117,9 @@ class _CD(logcommand.LogCommand):
# result
self.program.result.cdrdaoVersion = version
self.program.result.cdparanoiaVersion = cdparanoia.getCdParanoiaVersion()
self.program.result.cdrdaoVersion = cdrdao.getCDRDAOVersion()
self.program.result.cdparanoiaVersion = \
cdparanoia.getCdParanoiaVersion()
info = drive.getDeviceInfo(self.parentCommand.options.device)
if info:
try:

View File

@@ -245,8 +245,32 @@ Example disc id: KnpGsLhvH.lPrNc1PBL21lb9Bg4-"""
track.title.encode('utf-8')))
class CDParanoia(logcommand.LogCommand):
def do(self, args):
from morituri.program import cdparanoia
version = cdparanoia.getCdParanoiaVersion()
self.stdout.write("cdparanoia version: %s\n" % version)
class CDRDAO(logcommand.LogCommand):
def do(self, args):
from morituri.program import cdrdao
version = cdrdao.getCDRDAOVersion()
self.stdout.write("cdrdao version: %s\n" % version)
class Version(logcommand.LogCommand):
summary = "debug version getting"
subCommandClasses = [CDParanoia, CDRDAO]
class Debug(logcommand.LogCommand):
summary = "debug internals"
subCommandClasses = [Checksum, Encode, MaxSample, Tag, MusicBrainzNGS, ResultCache]
subCommandClasses = [Checksum, Encode, MaxSample, Tag, MusicBrainzNGS,
ResultCache, Version]

View File

@@ -65,7 +65,11 @@ class ErrorTestCase(common.TestCase):
class VersionTestCase(common.TestCase):
def testGetVersion(self):
self.failUnless(cdparanoia.getCdParanoiaVersion())
v = cdparanoia.getCdParanoiaVersion()
self.failUnless(v)
# of the form III 10.2
# make sure it ends with a digit
self.failUnless(int(v[-1]))
class AnalyzeFileTask(cdparanoia.AnalyzeTask):

View File

@@ -2,10 +2,11 @@
# vi:si:et:sw=4:sts=4:ts=4
import os
import unittest
from morituri.program import cdrdao
from morituri.test import common
class FakeTask:
@@ -13,7 +14,7 @@ class FakeTask:
pass
class ParseTestCase(unittest.TestCase):
class ParseTestCase(common.TestCase):
def setUp(self):
path = os.path.join(os.path.dirname(__file__),
@@ -34,3 +35,12 @@ class ParseTestCase(unittest.TestCase):
self.assertEquals(track.getIndex(1).absolute, offset)
self.assertEquals(self._parser.version, '1.2.2')
class VersionTestCase(common.TestCase):
def testGetVersion(self):
v = cdrdao.getCDRDAOVersion()
self.failUnless(v)
# make sure it starts with a digit
self.failUnless(int(v[0]))