extract code into program.getFastToc

This commit is contained in:
Thomas Vander Stichele
2013-02-03 21:07:28 +01:00
parent d907ccfaf6
commit 1e9afffde6
2 changed files with 42 additions and 28 deletions

View File

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