* 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.
This commit is contained in:
Thomas Vander Stichele
2009-05-03 17:44:23 +00:00
parent 4e62448000
commit d1c3bb3def
4 changed files with 72 additions and 21 deletions

View File

@@ -1,3 +1,13 @@
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:

View File

@@ -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'

View File

@@ -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.

View File

@@ -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)