Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store ToC file generated by cdrdao #277

Closed
wants to merge 1 commit into from
Closed

Store ToC file generated by cdrdao #277

wants to merge 1 commit into from

Conversation

JoeLametta
Copy link
Collaborator

@JoeLametta JoeLametta commented Jun 8, 2018

Fixes #214.

This FR isn't implemented as an option because I think always having the original toc file could be useful for debugging purposes, burning a copy of the source CD and it's a tiny file anyway...

@RecursiveForest
Copy link
Contributor

What does 'FR' mean?

@@ -614,3 +617,12 @@ def writeLog(self, discName, logger):
self.logPath = logPath

return logPath

def writeToc(self, discName):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stumbled for a moment on the name of this-- what's actually happening is we're moving a previous created tocfile to the output directory, so maybe we should make the method name (and docstring if necessary) reflect this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this too: decided to use this name/style to mimic the existing code style. It's true in this case it's a bit deceptive: I'll amend this (+ add a docstring). What would be a good name for the method?

Copy link
Collaborator Author

@JoeLametta JoeLametta Jun 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this?

def move_tocfile(self, discName):
    """Move cdrdao's tocfile to the discname path (.toc ending)"""


def writeToc(self, discName):
tocPath = '%s.toc' % discName
logger.debug('write .toc file to %s', tocPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the present active: "writing .toc file to %s"

Copy link
Collaborator Author

@JoeLametta JoeLametta Jun 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there's a similar logger.debug statement in whipper/command/cd.py maybe I should drop one of them? (written it like this to mimic the existing code style).

@@ -85,7 +85,7 @@ def do(self):
utils.unmount_device(device)

# first get the Table Of Contents of the CD
t = cdrdao.ReadTOCTask(device)
t = cdrdao.ReadTOCTask(device)[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep the "return a tuple" behaviour for ReadTOCTask (which is a little awkward but it's not a big deal), we should write this as t, _ = cdrdao.ReadTOCTask(device), which is a little less opaque than [0] in my opinion. Maybe a comment explaining the tocfile is unused (e.g., ...Task(device) # tocfile unused)

Copy link
Collaborator Author

@JoeLametta JoeLametta Jun 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll improve this as suggested.

P.S. What would be a better way to avoid the awkward return of a tuple?

@JoeLametta
Copy link
Collaborator Author

JoeLametta commented Jun 9, 2018

What does 'FR' mean?

Thanks for the pull request review.
I meant Feature Request.

@@ -614,3 +617,13 @@ def writeLog(self, discName, logger):
self.logPath = logPath

return logPath

def move_tocfile(self, discName):
"""Move cdrdao's tocfile to the discname path (.toc ending)"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a little more clear. Maybe "to the output directory ('DISCNAME.toc')", "... ('[discname].toc')", etc.

@@ -43,8 +43,7 @@ def read_toc(device, fast_toc=False):

toc = TocFile(tocfile)
toc.parse()
os.unlink(tocfile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that when the tocfile is unused (like for whipper offset), we have a /tmp-file that isn't cleaned up?

@@ -614,3 +618,11 @@ def writeLog(self, discName, logger):
self.logPath = logPath

return logPath

def move_tocfile(self, discName):
"""Move cdrdao's tocfile to the output dir. ('[discName].toc')"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nitpick, but now I think "Move cdrdao's tocfile to output-dir/discName.toc" would read the best.


def move_tocfile(self, discName):
"""Move cdrdao's tocfile to the output dir. ('[discName].toc')"""
tocPath = '%s.toc' % discName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variable names are confusing. Maybe something like result_toc_path to differentiate the new path from the temporary path.

Honestly I think we might be doing this backwards. Maybe it's best to move the toc from /tmp to the result directory in the read_toc() function itself if persist_tocfile is True and just return toc in read_toc() like before. I think it would keep things simpler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.
Let's say I've done this:

diff --git a/whipper/program/cdrdao.py b/whipper/program/cdrdao.py
index e0da15c..778fb7a 100644
--- a/whipper/program/cdrdao.py
+++ b/whipper/program/cdrdao.py
@@ -1,5 +1,6 @@
 import os
 import re
+import shutil
 import tempfile
 from subprocess import Popen, PIPE
 
@@ -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,7 +44,10 @@ def read_toc(device, fast_toc=False):
 
     toc = TocFile(tocfile)
     toc.parse()
-    os.unlink(tocfile)
+    if toc_path is not None:
+        shutil.move(tocfile, toc_path)
+    else:
+        os.unlink(tocfile)
     return toc
 
 
@@ -83,14 +87,14 @@ def ReadTOCTask(device):
     """
     stopgap morituri-insanity compatibility layer
     """
-    return read_toc(device, fast_toc=True)
+    return read_toc(device, fast_toc=True, toc_path=None)
 
 
 def ReadTableTask(device):
     """
     stopgap morituri-insanity compatibility layer
     """
-    return read_toc(device)
+    return read_toc(device, toc_path=None)
 
 
 def getCDRDAOVersion():

Who gives me the proper toc_path? (unfortunately it seems that one isn't available both in getFastToc() and in getTable() methods).

P.S. I'm quite tired right now so I may be missing something obvious.

Copy link
Contributor

@RecursiveForest RecursiveForest Jun 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From cd.py, pass the path to the function that ultimately calls read_toc(): something like self.program.getTable(..., output_dir) and self.program.getFastToc(..., output_dir). (This could be kwarg with default =None if we don't want to always persist the toc.) Then pass output_dir to read_toc().

We will need to make sure that the output directory has been created by the time we persist the toc though, right now that happens after both calls to getFastToc() and getTable(). As far as I can tell, we're committed to ripping after getFastToc() but before getTable(), so we should have getTable() be the call that persists the toc.

@MerlijnWajer MerlijnWajer self-requested a review June 11, 2018 07:25
@JoeLametta JoeLametta force-pushed the cdrdao-toc branch 2 times, most recently from 31aa1cd to b87a970 Compare October 27, 2018 13:48
@JoeLametta
Copy link
Collaborator Author

New solution implemented and tested: seems to be working as expected.

RFC: @MerlijnWajer, @RecursiveForest.

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.
@JoeLametta JoeLametta changed the base branch from master to develop November 2, 2018 08:48
@JoeLametta
Copy link
Collaborator Author

Adopted git flow: I'm closing this pull request, new one will be available in #321.

@JoeLametta JoeLametta closed this Nov 2, 2018
@JoeLametta JoeLametta deleted the cdrdao-toc branch November 2, 2018 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants