Skip to content

Commit

Permalink
Merge pull request #321 from whipper-team/feature/cdrdao-toc-preserva…
Browse files Browse the repository at this point in the history
…tion

Preserve ToC file generated by cdrdao
  • Loading branch information
JoeLametta authored Nov 19, 2018
2 parents 2b286be + c2af445 commit 4a91898
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
15 changes: 11 additions & 4 deletions whipper/command/cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,21 @@ def do(self):
"--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" % (
Expand Down Expand Up @@ -329,9 +339,6 @@ def doCommand(self):
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)
Expand Down
5 changes: 3 additions & 2 deletions whipper/common/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def getFastToc(self, runner, device):
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.
Expand All @@ -126,7 +127,7 @@ def getTable(self, runner, cddbdiscid, mbdiscid, device, offset):
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)
Expand Down
17 changes: 13 additions & 4 deletions whipper/program/cdrdao.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,7 +13,7 @@
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'.
"""
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 4a91898

Please sign in to comment.