Preserve ToC file generated by cdrdao

Whipper uses cdrdao during its ripping process. With this commit it will now store cdrdao's generated tocfile in the ripping path.
Preserving the tocfile allows users to easily burn ripped discs having a non-compliant cue sheet.

Fixes #214.
This commit is contained in:
JoeLametta
2018-10-26 08:00:00 +00:00
parent 2b286be91c
commit c2af4459ef
3 changed files with 27 additions and 10 deletions

View File

@@ -135,11 +135,21 @@ class _CD(BaseCommand):
"--cdr not passed")
return -1
# Change working directory before cdrdao's task
if self.options.working_directory is not None:
os.chdir(os.path.expanduser(self.options.working_directory))
out_bpath = self.options.output_directory.decode('utf-8')
# Needed to preserve cdrdao's tocfile
out_fpath = self.program.getPath(out_bpath,
self.options.disc_template,
self.mbdiscid,
self.program.metadata)
# now, read the complete index table, which is slower
self.itable = self.program.getTable(self.runner,
self.ittoc.getCDDBDiscId(),
self.ittoc.getMusicBrainzDiscId(),
self.device, self.options.offset)
self.device, self.options.offset,
out_fpath)
assert self.itable.getCDDBDiscId() == self.ittoc.getCDDBDiscId(), \
"full table's id %s differs from toc id %s" % (
@@ -329,9 +339,6 @@ Log files will log the path to tracks relative to this directory.
dirname.encode('utf-8'))
logger.critical(msg)
raise RuntimeError(msg)
else:
sys.stdout.write("output directory %s already exists\n" %
dirname.encode('utf-8'))
else:
print("creating output directory %s" % dirname.encode('utf-8'))
os.makedirs(dirname)

View File

@@ -104,7 +104,8 @@ class Program:
assert toc.hasTOC()
return toc
def getTable(self, runner, cddbdiscid, mbdiscid, device, offset):
def getTable(self, runner, cddbdiscid, mbdiscid, device, offset,
out_path):
"""
Retrieve the Table either from the cache or the drive.
@@ -126,7 +127,7 @@ class Program:
logger.debug('getTable: cddbdiscid %s, mbdiscid %s not '
'in cache for offset %s, reading table' % (
cddbdiscid, mbdiscid, offset))
t = cdrdao.ReadTableTask(device)
t = cdrdao.ReadTableTask(device, out_path)
itable = t.table
tdict[offset] = itable
ptable.persist(tdict)

View File

@@ -1,9 +1,10 @@
import os
import re
import shutil
import tempfile
from subprocess import Popen, PIPE
from whipper.common.common import EjectError
from whipper.common.common import EjectError, truncate_filename
from whipper.image.toc import TocFile
import logging
@@ -12,7 +13,7 @@ logger = logging.getLogger(__name__)
CDRDAO = 'cdrdao'
def read_toc(device, fast_toc=False):
def read_toc(device, fast_toc=False, toc_path=None):
"""
Return cdrdao-generated table of contents for 'device'.
"""
@@ -43,6 +44,14 @@ def read_toc(device, fast_toc=False):
toc = TocFile(tocfile)
toc.parse()
if toc_path is not None:
t_comp = os.path.abspath(toc_path).split(os.sep)
t_dirn = os.sep.join(t_comp[:-1])
# If the output path doesn't exist, make it recursively
if not os.path.isdir(t_dirn):
os.makedirs(t_dirn)
t_dst = truncate_filename(os.path.join(t_dirn, t_comp[-1] + '.toc'))
shutil.copy(tocfile, os.path.join(t_dirn, t_dst))
os.unlink(tocfile)
return toc
@@ -86,11 +95,11 @@ def ReadTOCTask(device):
return read_toc(device, fast_toc=True)
def ReadTableTask(device):
def ReadTableTask(device, toc_path=None):
"""
stopgap morituri-insanity compatibility layer
"""
return read_toc(device)
return read_toc(device, toc_path=toc_path)
def getCDRDAOVersion():