[SCM] morituri/master: get version for cdrdao too.
js at users.alioth.debian.org
js at users.alioth.debian.org
Sun Oct 19 20:10:05 UTC 2014
The following commit has been merged in the master branch:
commit 7813103a4dacf35f10cb3f62a8f6908c1e3689eb
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date: Sat Jul 13 11:31:27 2013 +0200
get version for cdrdao too.
Add debug commands: rip debug version cdrdao/cdparanoia
diff --git a/morituri/common/common.py b/morituri/common/common.py
index 0d91ed2..6608b7d 100644
--- a/morituri/common/common.py
+++ b/morituri/common/common.py
@@ -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
diff --git a/morituri/program/cdparanoia.py b/morituri/program/cdparanoia.py
index e8f6c59..46176d5 100644
--- a/morituri/program/cdparanoia.py
+++ b/morituri/program/cdparanoia.py
@@ -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.')
diff --git a/morituri/program/cdrdao.py b/morituri/program/cdrdao.py
index 669f0d0..c6fba64 100644
--- a/morituri/program/cdrdao.py
+++ b/morituri/program/cdrdao.py
@@ -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()
diff --git a/morituri/rip/cd.py b/morituri/rip/cd.py
index 3ccaf8b..73124d8 100644
--- a/morituri/rip/cd.py
+++ b/morituri/rip/cd.py
@@ -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:
diff --git a/morituri/rip/debug.py b/morituri/rip/debug.py
index 9751aeb..e182109 100644
--- a/morituri/rip/debug.py
+++ b/morituri/rip/debug.py
@@ -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]
diff --git a/morituri/test/test_program_cdparanoia.py b/morituri/test/test_program_cdparanoia.py
index 397073d..4d7b510 100644
--- a/morituri/test/test_program_cdparanoia.py
+++ b/morituri/test/test_program_cdparanoia.py
@@ -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):
diff --git a/morituri/test/test_program_cdrdao.py b/morituri/test/test_program_cdrdao.py
index 0a777dd..37b4986 100644
--- a/morituri/test/test_program_cdrdao.py
+++ b/morituri/test/test_program_cdrdao.py
@@ -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]))
--
morituri packaging
More information about the pkg-multimedia-commits
mailing list