extract code into program.getFastToc
This commit is contained in:
@@ -37,6 +37,9 @@ def filterForPath(text):
|
|||||||
return "-".join(text.split("/"))
|
return "-".join(text.split("/"))
|
||||||
|
|
||||||
|
|
||||||
|
# FIXME: should Program have a runner ?
|
||||||
|
|
||||||
|
|
||||||
class Program(log.Loggable):
|
class Program(log.Loggable):
|
||||||
"""
|
"""
|
||||||
I maintain program state and functionality.
|
I maintain program state and functionality.
|
||||||
@@ -100,6 +103,42 @@ class Program(log.Loggable):
|
|||||||
print 'Device %s is mounted, unmounting' % device
|
print 'Device %s is mounted, unmounting' % device
|
||||||
os.system('umount %s' % 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):
|
def getTable(self, runner, cddbdiscid, device):
|
||||||
"""
|
"""
|
||||||
Retrieve the Table either from the cache or the drive.
|
Retrieve the Table either from the cache or the drive.
|
||||||
|
|||||||
@@ -56,9 +56,6 @@ class _CD(logcommand.LogCommand):
|
|||||||
stdout=self.stdout)
|
stdout=self.stdout)
|
||||||
self.runner = task.SyncRunner()
|
self.runner = task.SyncRunner()
|
||||||
|
|
||||||
def function(r, t):
|
|
||||||
r.run(t)
|
|
||||||
|
|
||||||
# if the device is mounted (data session), unmount it
|
# if the device is mounted (data session), unmount it
|
||||||
self.device = self.parentCommand.options.device
|
self.device = self.parentCommand.options.device
|
||||||
self.stdout.write('Checking device %s\n' % self.device)
|
self.stdout.write('Checking device %s\n' % self.device)
|
||||||
@@ -69,31 +66,9 @@ class _CD(logcommand.LogCommand):
|
|||||||
version = None
|
version = None
|
||||||
|
|
||||||
# first, read the normal TOC, which is fast
|
# first, read the normal TOC, which is fast
|
||||||
ptoc = cache.Persister(self.options.toc_pickle or None)
|
self.ittoc = self.program.getFastToc(self.runner,
|
||||||
if not ptoc.object:
|
self.options.toc_pickle,
|
||||||
tries = 0
|
self.device)
|
||||||
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()
|
|
||||||
|
|
||||||
# already show us some info based on this
|
# already show us some info based on this
|
||||||
self.program.getRipResult(self.ittoc.getCDDBDiscId())
|
self.program.getRipResult(self.ittoc.getCDDBDiscId())
|
||||||
|
|||||||
Reference in New Issue
Block a user