From c2af4459ef2b67ed2b5bc35c4fc50713eece7378 Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Fri, 26 Oct 2018 08:00:00 +0000 Subject: [PATCH] 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. --- whipper/command/cd.py | 15 +++++++++++---- whipper/common/program.py | 5 +++-- whipper/program/cdrdao.py | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/whipper/command/cd.py b/whipper/command/cd.py index 1ba0658..8fa6e63 100644 --- a/whipper/command/cd.py +++ b/whipper/command/cd.py @@ -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) diff --git a/whipper/common/program.py b/whipper/common/program.py index 7469b09..ee93009 100644 --- a/whipper/common/program.py +++ b/whipper/common/program.py @@ -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) diff --git a/whipper/program/cdrdao.py b/whipper/program/cdrdao.py index e0da15c..01f5a20 100644 --- a/whipper/program/cdrdao.py +++ b/whipper/program/cdrdao.py @@ -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():