From 1e9afffde6ef5deb3cca48cd4c895f3fc08bbc1e Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 3 Feb 2013 21:07:28 +0100 Subject: [PATCH] extract code into program.getFastToc --- morituri/common/program.py | 39 ++++++++++++++++++++++++++++++++++++++ morituri/rip/cd.py | 31 +++--------------------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/morituri/common/program.py b/morituri/common/program.py index fc985bd..11da844 100644 --- a/morituri/common/program.py +++ b/morituri/common/program.py @@ -37,6 +37,9 @@ def filterForPath(text): return "-".join(text.split("/")) +# FIXME: should Program have a runner ? + + class Program(log.Loggable): """ I maintain program state and functionality. @@ -100,6 +103,42 @@ class Program(log.Loggable): print 'Device %s is mounted, unmounting' % device os.system('umount %s' % device) + def getFastToc(self, runner, toc_pickle, device): + """ + Retrieve the normal TOC table from a toc pickle or the drive. + + @rtype: L{table.Table} + """ + def function(r, t): + r.run(t) + + ptoc = cache.Persister(toc_pickle or None) + if not ptoc.object: + tries = 0 + while True: + tries += 1 + t = cdrdao.ReadTOCTask(device=device) + try: + function(runner, t) + break + except: + if tries > 3: + raise + self.debug('failed to read TOC after %d tries, retrying' % tries) + + version = t.tasks[1].parser.version + from pkg_resources import parse_version as V + # we've built a cdrdao 1.2.3rc2 modified package with the patch + if V(version) < V('1.2.3rc2p1'): + self.stdout.write('Warning: cdrdao older than 1.2.3 has a ' + 'pre-gap length bug.\n' + 'See http://sourceforge.net/tracker/?func=detail' + '&aid=604751&group_id=2171&atid=102171\n') + ptoc.persist(t.table) + toc = ptoc.object + assert toc.hasTOC() + return toc + def getTable(self, runner, cddbdiscid, device): """ Retrieve the Table either from the cache or the drive. diff --git a/morituri/rip/cd.py b/morituri/rip/cd.py index 78611f8..e7a2148 100644 --- a/morituri/rip/cd.py +++ b/morituri/rip/cd.py @@ -56,9 +56,6 @@ class _CD(logcommand.LogCommand): stdout=self.stdout) self.runner = task.SyncRunner() - def function(r, t): - r.run(t) - # if the device is mounted (data session), unmount it self.device = self.parentCommand.options.device self.stdout.write('Checking device %s\n' % self.device) @@ -69,31 +66,9 @@ class _CD(logcommand.LogCommand): version = None # first, read the normal TOC, which is fast - ptoc = cache.Persister(self.options.toc_pickle or None) - if not ptoc.object: - tries = 0 - while True: - tries += 1 - t = cdrdao.ReadTOCTask(device=self.device) - try: - function(self.runner, t) - break - except: - if tries > 3: - raise - self.debug('failed to read TOC after %d tries, retrying' % tries) - - version = t.tasks[1].parser.version - from pkg_resources import parse_version as V - # we've built a cdrdao 1.2.3rc2 modified package with the patch - if V(version) < V('1.2.3rc2p1'): - self.stdout.write('Warning: cdrdao older than 1.2.3 has a ' - 'pre-gap length bug.\n' - 'See http://sourceforge.net/tracker/?func=detail' - '&aid=604751&group_id=2171&atid=102171\n') - ptoc.persist(t.table) - self.ittoc = ptoc.object - assert self.ittoc.hasTOC() + self.ittoc = self.program.getFastToc(self.runner, + self.options.toc_pickle, + self.device) # already show us some info based on this self.program.getRipResult(self.ittoc.getCDDBDiscId())