[SCM] morituri/master: * morituri/program/cdparanoia.py: Add a task to read and verify a track. * examples/readtrack.py: Use it to clean up code. * morituri/common/task.py: describe a MultiTask better.
js at users.alioth.debian.org
js at users.alioth.debian.org
Sun Oct 19 20:08:53 UTC 2014
The following commit has been merged in the master branch:
commit d1c3bb3defba22514dba25ccf46a734460b3311f
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date: Sun May 3 17:44:23 2009 +0000
* morituri/program/cdparanoia.py:
Add a task to read and verify a track.
* examples/readtrack.py:
Use it to clean up code.
* morituri/common/task.py:
describe a MultiTask better.
diff --git a/ChangeLog b/ChangeLog
index 76f7528..2629101 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2009-05-03 Thomas Vander Stichele <thomas at apestaart dot org>
+ * morituri/program/cdparanoia.py:
+ Add a task to read and verify a track.
+ * examples/readtrack.py:
+ Use it to clean up code.
+ * morituri/common/task.py:
+ describe a MultiTask better.
+
+
+2009-05-03 Thomas Vander Stichele <thomas at apestaart dot org>
+
* morituri/common/common.py:
Create a Persister class to wrap a possible pickle path.
* examples/trm.py:
diff --git a/examples/readtrack.py b/examples/readtrack.py
index 4b41c8e..d3e73b5 100644
--- a/examples/readtrack.py
+++ b/examples/readtrack.py
@@ -19,31 +19,21 @@ def main():
runner = task.SyncRunner()
checksums = []
- for i in range(2):
- fd, path = tempfile.mkstemp(suffix='.morituri')
- os.close(fd)
+ fd, path = tempfile.mkstemp(suffix='.morituri')
+ os.close(fd)
- fakeTable = table.Table([
- table.Track( 1, 0, 15536),
- ])
+ fakeTable = table.Table([
+ table.Track( 1, 0, 15536),
+ ])
- t = cdparanoia.ReadTrackTask(path, fakeTable, 1000, 3000, offset=0)
+ t = cdparanoia.ReadVerifyTrackTask(path, fakeTable, 1000, 3000, offset=0)
- if i == 1:
- t.description = 'Verifying track...'
- runner.run(t)
-
- t = checksum.CRC32Task(path)
- runner.run(t)
-
- if i == 0:
- os.unlink(path)
-
- checksums.append(t.checksum)
+ runner.run(t)
print 'runner done'
- if checksums[0] == checksums[1]:
+
+ if t.checksum is not None:
print 'Checksums match'
else:
print 'Checksums do not match'
diff --git a/morituri/common/task.py b/morituri/common/task.py
index dcdb483..3e46b78 100644
--- a/morituri/common/task.py
+++ b/morituri/common/task.py
@@ -145,7 +145,7 @@ class BaseMultiTask(Task):
self.debug('BaseMultiTask.next(): starting task %r', task)
self._task += 1
self.setDescription("%s (%d of %d) ..." % (
- self._generic, self._task, len(self.tasks)))
+ task.description, self._task, len(self.tasks)))
task.addListener(self)
task.start(self.runner)
@@ -185,6 +185,11 @@ class MultiTask(BaseMultiTask):
def progressed(self, task, value):
self.setProgress(value)
+ def described(self, description):
+ print 'description'
+ self.setDescription("%s (%d of %d) ..." % (
+ description, self._task, len(self.tasks)))
+
class MultiCombinedTask(BaseMultiTask):
"""
I perform multiple tasks.
diff --git a/morituri/program/cdparanoia.py b/morituri/program/cdparanoia.py
index b1fdab5..2350e0d 100644
--- a/morituri/program/cdparanoia.py
+++ b/morituri/program/cdparanoia.py
@@ -61,7 +61,7 @@ class ReadTrackTask(task.Task):
I am a task that reads a track using cdparanoia.
"""
- description = "Reading Track..."
+ description = "Reading Track"
def __init__(self, path, table, start, stop, offset=0):
@@ -193,3 +193,49 @@ class ReadTrackTask(task.Task):
self.stop()
return
+
+class ReadVerifyTrackTask(task.MultiTask):
+ """
+ I am a task that reads and verifies a track using cdparanoia.
+
+ @ivar checksum: the checksum of the track.
+ """
+
+ def __init__(self, path, table, start, stop, offset=0):
+ """
+ @param path: where to store the ripped track
+ @type path: str
+ @param table: table of contents of CD
+ @type table: L{table.Table}
+ @param start: first frame to rip
+ @type start: int
+ @param stop: last frame to rip (inclusive)
+ @type stop: int
+ @param offset: read offset, in samples
+ @type offset: int
+ """
+ self.tasks = []
+ self.tasks.append(
+ ReadTrackTask(path, table, start, stop, offset))
+ self.tasks.append(
+ checksum.CRC32Task(path))
+ t = ReadTrackTask(path, table, start, stop, offset)
+ t.description = 'Verifying track...'
+ self.tasks.append(
+ ReadTrackTask(path, table, start, stop, offset))
+ self.tasks.append(
+ checksum.CRC32Task(path))
+
+ self.checksum = None
+
+ def stop(self):
+ c1 = self.tasks[1].checksum
+ c2 = self.tasks[3].checksum
+ if c1 == c2:
+ self.info('Checksums match, %08x' % c1)
+ self.checksum = checksum
+ else:
+ print 'ERROR: read and verify failed'
+ self.checksum = None
+
+ task.MultiTask.stop(self)
--
morituri packaging
More information about the pkg-multimedia-commits
mailing list